Skip to content

Commit

Permalink
[port_util] define base indexes for ethernet and portchannel as enum (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
mykolaf authored and lguohan committed Sep 17, 2018
1 parent 6272b5f commit 667b821
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/swsssdk/port_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"""
import swsssdk
import re
from enum import Enum


SONIC_ETHERNET_RE_PATTERN = "^Ethernet(\d+)$"
SONIC_PORTCHANNEL_RE_PATTERN = "^PortChannel(\d+)$"


class BaseIdx(int, Enum):
ethernet_base_idx = 1
portchannel_base_idx = 1000

def get_index(if_name):
"""
OIDs are 1-based, interfaces are 0-based, return the 1-based index
Expand All @@ -23,8 +30,8 @@ def get_index_from_str(if_name):
PortChannel N = N + 1000
"""
patterns = {
SONIC_ETHERNET_RE_PATTERN: 1,
SONIC_PORTCHANNEL_RE_PATTERN: 1000
SONIC_ETHERNET_RE_PATTERN: BaseIdx.ethernet_base_idx,
SONIC_PORTCHANNEL_RE_PATTERN: BaseIdx.portchannel_base_idx
}

for pattern, baseidx in patterns.items():
Expand Down

0 comments on commit 667b821

Please sign in to comment.