Skip to content

Commit 89ee636

Browse files
keboliuliat-grozovik
authored andcommitted
[Mellanox] SFP new platform API implementation (#2944)
* add sfp new api * fix get presence
1 parent 4d212de commit 89ee636

File tree

2 files changed

+1082
-1
lines changed

2 files changed

+1082
-1
lines changed

platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,24 @@
1515
from sonic_platform.psu import Psu
1616
from sonic_platform.fan import Fan
1717
from sonic_platform.fan import FAN_PATH
18+
from sonic_platform.sfp import SFP
1819
from sonic_platform.watchdog import get_watchdog
1920
from os import listdir
2021
from os.path import isfile, join
2122
import re
23+
import subprocess
2224
except ImportError as e:
2325
raise ImportError (str(e) + "- required module not found")
2426

2527
MLNX_NUM_PSU = 2
2628

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+
2736
class Chassis(ChassisBase):
2837
"""Platform-specific Chassis class"""
2938

@@ -50,6 +59,20 @@ def __init__(self):
5059
fan = Fan(index, index)
5160
self._fan_list.append(fan)
5261

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+
5376
def _extract_num_of_fans_and_fan_drawers(self):
5477
num_of_fan = 0
5578
num_of_drawer = 0
@@ -64,7 +87,13 @@ def _extract_num_of_fans_and_fan_drawers(self):
6487
if match_obj != None and int(match_obj.group(1)) > num_of_drawer:
6588
num_of_drawer = int(match_obj.group(1))
6689

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
6897

6998

7099

0 commit comments

Comments
 (0)