[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 <jostar_yang@accton.com.tw>
This commit is contained in:
parent
24cc827b73
commit
5e435e05a4
@ -7,6 +7,7 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@ -38,7 +39,7 @@ class Chassis(PddfChassis):
|
|||||||
|
|
||||||
bitmap = 0
|
bitmap = 0
|
||||||
for i in range(58):
|
for i in range(58):
|
||||||
modpres = self.get_sfp(i).get_presence()
|
modpres = self.get_sfp(i+1).get_presence()
|
||||||
if modpres:
|
if modpres:
|
||||||
bitmap = bitmap | (1 << i)
|
bitmap = bitmap | (1 << i)
|
||||||
|
|
||||||
@ -59,3 +60,26 @@ class Chassis(PddfChassis):
|
|||||||
return True, change_dict
|
return True, change_dict
|
||||||
else:
|
else:
|
||||||
return True, change_dict
|
return True, change_dict
|
||||||
|
|
||||||
|
def get_sfp(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves sfp represented by (1-based) index <index>
|
||||||
|
|
||||||
|
Args:
|
||||||
|
index: An integer, the index (1-based) of the sfp to retrieve.
|
||||||
|
The index should be the sequence of a physical port in a chassis,
|
||||||
|
starting from 1.
|
||||||
|
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
An object derived from SfpBase representing the specified sfp
|
||||||
|
"""
|
||||||
|
sfp = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# The index will start from 1
|
||||||
|
sfp = self._sfp_list[index-1]
|
||||||
|
except IndexError:
|
||||||
|
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
|
||||||
|
index, len(self._sfp_list)))
|
||||||
|
return sfp
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@ -38,7 +39,7 @@ class Chassis(PddfChassis):
|
|||||||
|
|
||||||
bitmap = 0
|
bitmap = 0
|
||||||
for i in range(34):
|
for i in range(34):
|
||||||
modpres = self.get_sfp(i).get_presence()
|
modpres = self.get_sfp(i+1).get_presence()
|
||||||
if modpres:
|
if modpres:
|
||||||
bitmap = bitmap | (1 << i)
|
bitmap = bitmap | (1 << i)
|
||||||
|
|
||||||
@ -59,3 +60,27 @@ class Chassis(PddfChassis):
|
|||||||
return True, change_dict
|
return True, change_dict
|
||||||
else:
|
else:
|
||||||
return True, change_dict
|
return True, change_dict
|
||||||
|
|
||||||
|
|
||||||
|
def get_sfp(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves sfp represented by (1-based) index <index>
|
||||||
|
|
||||||
|
Args:
|
||||||
|
index: An integer, the index (1-based) of the sfp to retrieve.
|
||||||
|
The index should be the sequence of a physical port in a chassis,
|
||||||
|
starting from 1.
|
||||||
|
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
An object derived from SfpBase representing the specified sfp
|
||||||
|
"""
|
||||||
|
sfp = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# The index will start from 1
|
||||||
|
sfp = self._sfp_list[index-1]
|
||||||
|
except IndexError:
|
||||||
|
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
|
||||||
|
index, len(self._sfp_list)))
|
||||||
|
return sfp
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@ -38,7 +39,7 @@ class Chassis(PddfChassis):
|
|||||||
|
|
||||||
bitmap = 0
|
bitmap = 0
|
||||||
for i in range(64):
|
for i in range(64):
|
||||||
modpres = self.get_sfp(i).get_presence()
|
modpres = self.get_sfp(i+1).get_presence()
|
||||||
if modpres:
|
if modpres:
|
||||||
bitmap = bitmap | (1 << i)
|
bitmap = bitmap | (1 << i)
|
||||||
|
|
||||||
@ -59,3 +60,27 @@ class Chassis(PddfChassis):
|
|||||||
return True, change_dict
|
return True, change_dict
|
||||||
else:
|
else:
|
||||||
return True, change_dict
|
return True, change_dict
|
||||||
|
|
||||||
|
|
||||||
|
def get_sfp(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves sfp represented by (1-based) index <index>
|
||||||
|
|
||||||
|
Args:
|
||||||
|
index: An integer, the index (1-based) of the sfp to retrieve.
|
||||||
|
The index should be the sequence of a physical port in a chassis,
|
||||||
|
starting from 1.
|
||||||
|
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
An object derived from SfpBase representing the specified sfp
|
||||||
|
"""
|
||||||
|
sfp = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# The index will start from 1
|
||||||
|
sfp = self._sfp_list[index-1]
|
||||||
|
except IndexError:
|
||||||
|
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
|
||||||
|
index, len(self._sfp_list)))
|
||||||
|
return sfp
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@ -38,7 +39,7 @@ class Chassis(PddfChassis):
|
|||||||
|
|
||||||
bitmap = 0
|
bitmap = 0
|
||||||
for i in range(34):
|
for i in range(34):
|
||||||
modpres = self.get_sfp(i).get_presence()
|
modpres = self.get_sfp(i+1).get_presence()
|
||||||
if modpres:
|
if modpres:
|
||||||
bitmap = bitmap | (1 << i)
|
bitmap = bitmap | (1 << i)
|
||||||
|
|
||||||
@ -59,3 +60,27 @@ class Chassis(PddfChassis):
|
|||||||
return True, change_dict
|
return True, change_dict
|
||||||
else:
|
else:
|
||||||
return True, change_dict
|
return True, change_dict
|
||||||
|
|
||||||
|
|
||||||
|
def get_sfp(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves sfp represented by (1-based) index <index>
|
||||||
|
|
||||||
|
Args:
|
||||||
|
index: An integer, the index (1-based) of the sfp to retrieve.
|
||||||
|
The index should be the sequence of a physical port in a chassis,
|
||||||
|
starting from 1.
|
||||||
|
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
An object derived from SfpBase representing the specified sfp
|
||||||
|
"""
|
||||||
|
sfp = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# The index will start from 1
|
||||||
|
sfp = self._sfp_list[index-1]
|
||||||
|
except IndexError:
|
||||||
|
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
|
||||||
|
index, len(self._sfp_list)))
|
||||||
|
return sfp
|
||||||
|
Reference in New Issue
Block a user