Skip to content

Commit 403747a

Browse files
[sonic-platform-common] Add new platform API for SONiC Physical MIB Extension feature (#134)
Why I did this? In order to implement physical entity mib object entPhysicalParentRelPos, entPhysicalContainedIn and entPhysicalIsFRU, new platform API is required to collect information from each vendor. What I did? 1. Add DeviceBase.is_replaceable and DeviceBase.get_position_in_parent 2. Add PsuBase.get_num_thermals, PsuBase.get_all_thermals, PsuBase.get_thermal 3. Add SfpBase.get_num_thermals, SfpBase.get_all_thermals, SfpBase.get_thermal
1 parent 19b8545 commit 403747a

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

sonic_platform_base/device_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,20 @@ def get_status(self):
5656
A boolean value, True if device is operating properly, False if not
5757
"""
5858
raise NotImplementedError
59+
60+
def get_position_in_parent(self):
61+
"""
62+
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
63+
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
64+
Returns:
65+
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
66+
"""
67+
raise NotImplementedError
68+
69+
def is_replaceable(self):
70+
"""
71+
Indicate whether this device is replaceable.
72+
Returns:
73+
bool: True if it is replaceable.
74+
"""
75+
raise NotImplementedError

sonic_platform_base/psu_base.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,20 @@ class PsuBase(device_base.DeviceBase):
2525
# available on the PSU
2626
_fan_list = None
2727

28+
# List of ThermalBase-derived objects representing all thermals
29+
# available on the PSU. Put a class level _thermal_list here to
30+
# avoid an exception when call get_num_thermals, get_all_thermals
31+
# and get_thermal if vendor does not call PsuBase.__init__ in concrete
32+
# PSU class
33+
_thermal_list = []
34+
2835
def __init__(self):
2936
self._fan_list = []
3037

38+
# List of ThermalBase-derived objects representing all thermals
39+
# available on the PSU
40+
self._thermal_list = []
41+
3142
def get_num_fans(self):
3243
"""
3344
Retrieves the number of fan modules available on this PSU
@@ -69,6 +80,46 @@ def get_fan(self, index):
6980

7081
return fan
7182

83+
def get_num_thermals(self):
84+
"""
85+
Retrieves the number of thermals available on this PSU
86+
87+
Returns:
88+
An integer, the number of thermals available on this PSU
89+
"""
90+
return len(self._thermal_list)
91+
92+
def get_all_thermals(self):
93+
"""
94+
Retrieves all thermals available on this PSU
95+
96+
Returns:
97+
A list of objects derived from ThermalBase representing all thermals
98+
available on this PSU
99+
"""
100+
return self._thermal_list
101+
102+
def get_thermal(self, index):
103+
"""
104+
Retrieves thermal unit represented by (0-based) index <index>
105+
106+
Args:
107+
index: An integer, the index (0-based) of the thermal to
108+
retrieve
109+
110+
Returns:
111+
An object dervied from ThermalBase representing the specified thermal
112+
"""
113+
thermal = None
114+
115+
try:
116+
thermal = self._thermal_list[index]
117+
except IndexError:
118+
sys.stderr.write("THERMAL index {} out of range (0-{})\n".format(
119+
index, len(self._thermal_list)-1))
120+
121+
return thermal
122+
72123
def get_voltage(self):
73124
"""
74125
Retrieves current PSU voltage output

sonic_platform_base/sfp_base.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,58 @@ class SfpBase(device_base.DeviceBase):
1616
# Device type definition. Note, this is a constant.
1717
DEVICE_TYPE = "sfp"
1818

19+
# List of ThermalBase-derived objects representing all thermals
20+
# available on the SFP. Put a class level _thermal_list here to
21+
# avoid an exception when call get_num_thermals, get_all_thermals
22+
# and get_thermal if vendor does not call SfpBase.__init__ in concrete
23+
# SFP class
24+
_thermal_list = []
25+
26+
def __init__(self):
27+
# List of ThermalBase-derived objects representing all thermals
28+
# available on the SFP
29+
self._thermal_list = []
30+
31+
def get_num_thermals(self):
32+
"""
33+
Retrieves the number of thermals available on this SFP
34+
35+
Returns:
36+
An integer, the number of thermals available on this SFP
37+
"""
38+
return len(self._thermal_list)
39+
40+
def get_all_thermals(self):
41+
"""
42+
Retrieves all thermals available on this SFP
43+
44+
Returns:
45+
A list of objects derived from ThermalBase representing all thermals
46+
available on this SFP
47+
"""
48+
return self._thermal_list
49+
50+
def get_thermal(self, index):
51+
"""
52+
Retrieves thermal unit represented by (0-based) index <index>
53+
54+
Args:
55+
index: An integer, the index (0-based) of the thermal to
56+
retrieve
57+
58+
Returns:
59+
An object derived from ThermalBase representing the specified thermal
60+
"""
61+
thermal = None
62+
63+
try:
64+
thermal = self._thermal_list[index]
65+
except IndexError:
66+
sys.stderr.write("THERMAL index {} out of range (0-{})\n".format(
67+
index, len(self._thermal_list)-1))
68+
69+
return thermal
70+
1971
def get_transceiver_info(self):
2072
"""
2173
Retrieves transceiver info of this SFP

0 commit comments

Comments
 (0)