Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PDDF] Add get_sfp() to chassis to handle port idx #7980

Merged
merged 2 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
Expand Down Expand Up @@ -38,7 +39,7 @@ def get_change_event(self, timeout=2000):

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)

Expand All @@ -59,3 +60,26 @@ def get_change_event(self, timeout=2000):
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
Expand Down Expand Up @@ -38,7 +39,7 @@ def get_change_event(self, timeout=2000):

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)

Expand All @@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000):
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
Expand Down Expand Up @@ -38,7 +39,7 @@ def get_change_event(self, timeout=2000):

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)

Expand All @@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000):
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
Expand Down Expand Up @@ -38,7 +39,7 @@ def get_change_event(self, timeout=2000):

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)

Expand All @@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000):
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