15
15
from sonic_platform .psu import Psu
16
16
from sonic_platform .fan import Fan
17
17
from sonic_platform .fan import FAN_PATH
18
+ from sonic_platform .sfp import SFP
18
19
from sonic_platform .watchdog import get_watchdog
19
20
from os import listdir
20
21
from os .path import isfile , join
21
22
import re
23
+ import subprocess
22
24
except ImportError as e :
23
25
raise ImportError (str (e ) + "- required module not found" )
24
26
25
27
MLNX_NUM_PSU = 2
26
28
29
+ GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"
30
+
31
+ # magic code defnition for port number, qsfp port position of each hwsku
32
+ # port_position_tuple = (PORT_START, QSFP_PORT_START, PORT_END, PORT_IN_BLOCK, EEPROM_OFFSET)
33
+ hwsku_dict = {'ACS-MSN2700' : 0 , "LS-SN2700" :0 , 'ACS-MSN2740' : 0 , 'ACS-MSN2100' : 1 , 'ACS-MSN2410' : 2 , 'ACS-MSN2010' : 3 , 'ACS-MSN3700' : 0 , 'ACS-MSN3700C' : 0 , 'Mellanox-SN2700' : 0 , 'Mellanox-SN2700-D48C8' : 0 }
34
+ port_position_tuple_list = [(0 , 0 , 31 , 32 , 1 ), (0 , 0 , 15 , 16 , 1 ), (0 , 48 , 55 , 56 , 1 ),(0 , 18 , 21 , 22 , 1 )]
35
+
27
36
class Chassis (ChassisBase ):
28
37
"""Platform-specific Chassis class"""
29
38
@@ -50,6 +59,20 @@ def __init__(self):
50
59
fan = Fan (index , index )
51
60
self ._fan_list .append (fan )
52
61
62
+ # Initialize SFP list
63
+ port_position_tuple = self ._get_port_position_tuple_by_sku_name ()
64
+ self .PORT_START = port_position_tuple [0 ]
65
+ self .QSFP_PORT_START = port_position_tuple [1 ]
66
+ self .PORT_END = port_position_tuple [2 ]
67
+ self .PORTS_IN_BLOCK = port_position_tuple [3 ]
68
+
69
+ for index in range (self .PORT_START , self .PORT_END + 1 ):
70
+ if index in range (QSFP_PORT_START , self .PORTS_IN_BLOCK + 1 ):
71
+ sfp_module = SFP (index , 'QSFP' )
72
+ else :
73
+ sfp_module = SFP (index , 'SFP' )
74
+ self ._psu_list .append (sfp_module )
75
+
53
76
def _extract_num_of_fans_and_fan_drawers (self ):
54
77
num_of_fan = 0
55
78
num_of_drawer = 0
@@ -64,7 +87,13 @@ def _extract_num_of_fans_and_fan_drawers(self):
64
87
if match_obj != None and int (match_obj .group (1 )) > num_of_drawer :
65
88
num_of_drawer = int (match_obj .group (1 ))
66
89
67
- return num_of_fan , num_of_drawer
90
+ return num_of_fan , num_of_drawer
91
+
92
+ def _get_port_position_tuple_by_sku_name (self ):
93
+ p = subprocess .Popen (GET_HWSKU_CMD , shell = True , stdout = subprocess .PIPE )
94
+ out , err = p .communicate ()
95
+ position_tuple = port_position_tuple_list [hwsku_dict [out .rstrip ('\n ' )]]
96
+ return position_tuple
68
97
69
98
70
99
0 commit comments