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

[sonic-platform-common] Add new platform API for SONiC Physical MIB Extension feature #134

Merged
merged 4 commits into from
Oct 21, 2020
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
17 changes: 17 additions & 0 deletions sonic_platform_base/device_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,20 @@ def get_status(self):
A boolean value, True if device is operating properly, False if not
"""
raise NotImplementedError

def get_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
Returns:
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
"""
raise NotImplementedError

def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
raise NotImplementedError
51 changes: 51 additions & 0 deletions sonic_platform_base/psu_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@ class PsuBase(device_base.DeviceBase):
# available on the PSU
_fan_list = None

# List of ThermalBase-derived objects representing all thermals
# available on the PSU. Put a class level _thermal_list here to
# avoid an exception when call get_num_thermals, get_all_thermals
# and get_thermal if vendor does not call PsuBase.__init__ in concrete
# PSU class
_thermal_list = []

def __init__(self):
self._fan_list = []

# List of ThermalBase-derived objects representing all thermals
# available on the PSU
self._thermal_list = []

def get_num_fans(self):
"""
Retrieves the number of fan modules available on this PSU
Expand Down Expand Up @@ -69,6 +80,46 @@ def get_fan(self, index):

return fan

def get_num_thermals(self):
"""
Retrieves the number of thermals available on this PSU

Returns:
An integer, the number of thermals available on this PSU
"""
return len(self._thermal_list)

def get_all_thermals(self):
"""
Retrieves all thermals available on this PSU

Returns:
A list of objects derived from ThermalBase representing all thermals
available on this PSU
"""
return self._thermal_list

def get_thermal(self, index):
"""
Retrieves thermal unit represented by (0-based) index <index>

Args:
index: An integer, the index (0-based) of the thermal to
retrieve

Returns:
An object dervied from ThermalBase representing the specified thermal
"""
thermal = None

try:
thermal = self._thermal_list[index]
except IndexError:
sys.stderr.write("THERMAL index {} out of range (0-{})\n".format(
index, len(self._thermal_list)-1))

return thermal

def get_voltage(self):
"""
Retrieves current PSU voltage output
Expand Down
52 changes: 52 additions & 0 deletions sonic_platform_base/sfp_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,58 @@ class SfpBase(device_base.DeviceBase):
# Device type definition. Note, this is a constant.
DEVICE_TYPE = "sfp"

# List of ThermalBase-derived objects representing all thermals
# available on the SFP. Put a class level _thermal_list here to
# avoid an exception when call get_num_thermals, get_all_thermals
# and get_thermal if vendor does not call SfpBase.__init__ in concrete
# SFP class
_thermal_list = []

def __init__(self):
# List of ThermalBase-derived objects representing all thermals
# available on the SFP
self._thermal_list = []

def get_num_thermals(self):
"""
Retrieves the number of thermals available on this SFP

Returns:
An integer, the number of thermals available on this SFP
"""
return len(self._thermal_list)

def get_all_thermals(self):
"""
Retrieves all thermals available on this SFP

Returns:
A list of objects derived from ThermalBase representing all thermals
available on this SFP
"""
return self._thermal_list

def get_thermal(self, index):
"""
Retrieves thermal unit represented by (0-based) index <index>

Args:
index: An integer, the index (0-based) of the thermal to
retrieve

Returns:
An object derived from ThermalBase representing the specified thermal
"""
thermal = None

try:
thermal = self._thermal_list[index]
except IndexError:
sys.stderr.write("THERMAL index {} out of range (0-{})\n".format(
index, len(self._thermal_list)-1))

return thermal

def get_transceiver_info(self):
"""
Retrieves transceiver info of this SFP
Expand Down