Skip to content

Commit 5e435e0

Browse files
jostar-yangJostar Yang
and
Jostar Yang
authored
[Accton/PDDF] Add get_sfp() to chassis to handle port idx (#7980)
* Modify index start from 1 in in get_change_event() Co-authored-by: Jostar Yang <[email protected]>
1 parent 24cc827 commit 5e435e0

File tree

4 files changed

+103
-4
lines changed

4 files changed

+103
-4
lines changed

platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#############################################################################
88

99
try:
10+
import sys
1011
import time
1112
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
1213
except ImportError as e:
@@ -38,7 +39,7 @@ def get_change_event(self, timeout=2000):
3839

3940
bitmap = 0
4041
for i in range(58):
41-
modpres = self.get_sfp(i).get_presence()
42+
modpres = self.get_sfp(i+1).get_presence()
4243
if modpres:
4344
bitmap = bitmap | (1 << i)
4445

@@ -59,3 +60,26 @@ def get_change_event(self, timeout=2000):
5960
return True, change_dict
6061
else:
6162
return True, change_dict
63+
64+
def get_sfp(self, index):
65+
"""
66+
Retrieves sfp represented by (1-based) index <index>
67+
68+
Args:
69+
index: An integer, the index (1-based) of the sfp to retrieve.
70+
The index should be the sequence of a physical port in a chassis,
71+
starting from 1.
72+
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
73+
74+
Returns:
75+
An object derived from SfpBase representing the specified sfp
76+
"""
77+
sfp = None
78+
79+
try:
80+
# The index will start from 1
81+
sfp = self._sfp_list[index-1]
82+
except IndexError:
83+
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
84+
index, len(self._sfp_list)))
85+
return sfp

platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#############################################################################
88

99
try:
10+
import sys
1011
import time
1112
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
1213
except ImportError as e:
@@ -38,7 +39,7 @@ def get_change_event(self, timeout=2000):
3839

3940
bitmap = 0
4041
for i in range(34):
41-
modpres = self.get_sfp(i).get_presence()
42+
modpres = self.get_sfp(i+1).get_presence()
4243
if modpres:
4344
bitmap = bitmap | (1 << i)
4445

@@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000):
5960
return True, change_dict
6061
else:
6162
return True, change_dict
63+
64+
65+
def get_sfp(self, index):
66+
"""
67+
Retrieves sfp represented by (1-based) index <index>
68+
69+
Args:
70+
index: An integer, the index (1-based) of the sfp to retrieve.
71+
The index should be the sequence of a physical port in a chassis,
72+
starting from 1.
73+
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
74+
75+
Returns:
76+
An object derived from SfpBase representing the specified sfp
77+
"""
78+
sfp = None
79+
80+
try:
81+
# The index will start from 1
82+
sfp = self._sfp_list[index-1]
83+
except IndexError:
84+
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
85+
index, len(self._sfp_list)))
86+
return sfp

platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#############################################################################
88

99
try:
10+
import sys
1011
import time
1112
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
1213
except ImportError as e:
@@ -38,7 +39,7 @@ def get_change_event(self, timeout=2000):
3839

3940
bitmap = 0
4041
for i in range(64):
41-
modpres = self.get_sfp(i).get_presence()
42+
modpres = self.get_sfp(i+1).get_presence()
4243
if modpres:
4344
bitmap = bitmap | (1 << i)
4445

@@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000):
5960
return True, change_dict
6061
else:
6162
return True, change_dict
63+
64+
65+
def get_sfp(self, index):
66+
"""
67+
Retrieves sfp represented by (1-based) index <index>
68+
69+
Args:
70+
index: An integer, the index (1-based) of the sfp to retrieve.
71+
The index should be the sequence of a physical port in a chassis,
72+
starting from 1.
73+
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
74+
75+
Returns:
76+
An object derived from SfpBase representing the specified sfp
77+
"""
78+
sfp = None
79+
80+
try:
81+
# The index will start from 1
82+
sfp = self._sfp_list[index-1]
83+
except IndexError:
84+
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
85+
index, len(self._sfp_list)))
86+
return sfp

platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#############################################################################
88

99
try:
10+
import sys
1011
import time
1112
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
1213
except ImportError as e:
@@ -38,7 +39,7 @@ def get_change_event(self, timeout=2000):
3839

3940
bitmap = 0
4041
for i in range(34):
41-
modpres = self.get_sfp(i).get_presence()
42+
modpres = self.get_sfp(i+1).get_presence()
4243
if modpres:
4344
bitmap = bitmap | (1 << i)
4445

@@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000):
5960
return True, change_dict
6061
else:
6162
return True, change_dict
63+
64+
65+
def get_sfp(self, index):
66+
"""
67+
Retrieves sfp represented by (1-based) index <index>
68+
69+
Args:
70+
index: An integer, the index (1-based) of the sfp to retrieve.
71+
The index should be the sequence of a physical port in a chassis,
72+
starting from 1.
73+
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
74+
75+
Returns:
76+
An object derived from SfpBase representing the specified sfp
77+
"""
78+
sfp = None
79+
80+
try:
81+
# The index will start from 1
82+
sfp = self._sfp_list[index-1]
83+
except IndexError:
84+
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
85+
index, len(self._sfp_list)))
86+
return sfp

0 commit comments

Comments
 (0)