[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:
jostar-yang 2021-07-25 09:31:45 +08:00 committed by GitHub
parent 24cc827b73
commit 5e435e05a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 103 additions and 4 deletions

View File

@ -7,6 +7,7 @@
#############################################################################
try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
@ -38,7 +39,7 @@ class Chassis(PddfChassis):
bitmap = 0
for i in range(58):
modpres = self.get_sfp(i).get_presence()
modpres = self.get_sfp(i+1).get_presence()
if modpres:
bitmap = bitmap | (1 << i)
@ -59,3 +60,26 @@ class Chassis(PddfChassis):
return True, change_dict
else:
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

View File

@ -7,6 +7,7 @@
#############################################################################
try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
@ -38,7 +39,7 @@ class Chassis(PddfChassis):
bitmap = 0
for i in range(34):
modpres = self.get_sfp(i).get_presence()
modpres = self.get_sfp(i+1).get_presence()
if modpres:
bitmap = bitmap | (1 << i)
@ -59,3 +60,27 @@ class Chassis(PddfChassis):
return True, change_dict
else:
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

View File

@ -7,6 +7,7 @@
#############################################################################
try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
@ -38,7 +39,7 @@ class Chassis(PddfChassis):
bitmap = 0
for i in range(64):
modpres = self.get_sfp(i).get_presence()
modpres = self.get_sfp(i+1).get_presence()
if modpres:
bitmap = bitmap | (1 << i)
@ -59,3 +60,27 @@ class Chassis(PddfChassis):
return True, change_dict
else:
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

View File

@ -7,6 +7,7 @@
#############################################################################
try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
@ -38,7 +39,7 @@ class Chassis(PddfChassis):
bitmap = 0
for i in range(34):
modpres = self.get_sfp(i).get_presence()
modpres = self.get_sfp(i+1).get_presence()
if modpres:
bitmap = bitmap | (1 << i)
@ -59,3 +60,27 @@ class Chassis(PddfChassis):
return True, change_dict
else:
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