Skip to content

Commit 5797d55

Browse files
author
Jostar Yang
committed
[AS4630-54PE]Support API2.0 to 202012br
Signed-off-by: Jostar Yang <[email protected]>
1 parent 7eb6abd commit 5797d55

File tree

17 files changed

+2953
-270
lines changed

17 files changed

+2953
-270
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"skip_ledd": true,
3-
"skip_thermalctld": true
3+
"skip_pcied": true
44
}
55

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__all__ = [ "platform", "chassis", "sfp", "eeprom", "component", "psu", "thermal", "fan", "fan_drawer" ]
2+
from . import platform
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
#############################################################################
2+
# Edgecore
3+
#
4+
# Module contains an implementation of SONiC Platform Base API and
5+
# provides the Chassis information which are available in the platform
6+
#
7+
#############################################################################
8+
9+
import os
10+
import sys
11+
12+
try:
13+
from sonic_platform_base.chassis_base import ChassisBase
14+
from .helper import APIHelper
15+
from .event import SfpEvent
16+
except ImportError as e:
17+
raise ImportError(str(e) + "- required module not found")
18+
19+
NUM_FAN_TRAY = 3
20+
NUM_FAN = 2
21+
NUM_PSU = 2
22+
NUM_THERMAL = 3
23+
PORT_START = 49
24+
PORT_END = 54
25+
NUM_COMPONENT = 2
26+
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/"
27+
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/"
28+
REBOOT_CAUSE_FILE = "reboot-cause.txt"
29+
PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt"
30+
HOST_CHK_CMD = "docker > /dev/null 2>&1"
31+
SYSLED_FNODE = "/sys/class/leds/diag/brightness"
32+
SYSLED_MODES = {
33+
"0" : "STATUS_LED_COLOR_OFF",
34+
"1" : "STATUS_LED_COLOR_GREEN",
35+
"2" : "STATUS_LED_COLOR_AMBER",
36+
"5" : "STATUS_LED_COLOR_GREEN_BLINK"
37+
}
38+
39+
40+
class Chassis(ChassisBase):
41+
"""Platform-specific Chassis class"""
42+
43+
def __init__(self):
44+
ChassisBase.__init__(self)
45+
self._api_helper = APIHelper()
46+
self._api_helper = APIHelper()
47+
self.is_host = self._api_helper.is_host()
48+
49+
self.config_data = {}
50+
51+
self.__initialize_fan()
52+
self.__initialize_psu()
53+
self.__initialize_thermals()
54+
self.__initialize_components()
55+
self.__initialize_sfp()
56+
self.__initialize_eeprom()
57+
58+
def __initialize_sfp(self):
59+
from sonic_platform.sfp import Sfp
60+
for index in range(0, PORT_END):
61+
sfp = Sfp(index)
62+
self._sfp_list.append(sfp)
63+
self.sfp_module_initialized = True
64+
65+
def __initialize_fan(self):
66+
from sonic_platform.fan_drawer import FanDrawer
67+
for fant_index in range(NUM_FAN_TRAY):
68+
fandrawer = FanDrawer(fant_index)
69+
self._fan_drawer_list.append(fandrawer)
70+
self._fan_list.extend(fandrawer._fan_list)
71+
72+
def __initialize_psu(self):
73+
from sonic_platform.psu import Psu
74+
for index in range(0, NUM_PSU):
75+
psu = Psu(index)
76+
self._psu_list.append(psu)
77+
78+
def __initialize_thermals(self):
79+
from sonic_platform.thermal import Thermal
80+
for index in range(0, NUM_THERMAL):
81+
thermal = Thermal(index)
82+
self._thermal_list.append(thermal)
83+
84+
def __initialize_eeprom(self):
85+
from sonic_platform.eeprom import Tlv
86+
self._eeprom = Tlv()
87+
88+
def __initialize_components(self):
89+
from sonic_platform.component import Component
90+
for index in range(0, NUM_COMPONENT):
91+
component = Component(index)
92+
self._component_list.append(component)
93+
94+
def __initialize_watchdog(self):
95+
from sonic_platform.watchdog import Watchdog
96+
self._watchdog = Watchdog()
97+
98+
99+
def __is_host(self):
100+
return os.system(HOST_CHK_CMD) == 0
101+
102+
def __read_txt_file(self, file_path):
103+
try:
104+
with open(file_path, 'r') as fd:
105+
data = fd.read()
106+
return data.strip()
107+
except IOError:
108+
pass
109+
return None
110+
111+
def get_name(self):
112+
"""
113+
Retrieves the name of the device
114+
Returns:
115+
string: The name of the device
116+
"""
117+
118+
return self._api_helper.hwsku
119+
120+
def get_presence(self):
121+
"""
122+
Retrieves the presence of the Chassis
123+
Returns:
124+
bool: True if Chassis is present, False if not
125+
"""
126+
return True
127+
128+
def get_status(self):
129+
"""
130+
Retrieves the operational status of the device
131+
Returns:
132+
A boolean value, True if device is operating properly, False if not
133+
"""
134+
return True
135+
136+
def get_base_mac(self):
137+
"""
138+
Retrieves the base MAC address for the chassis
139+
Returns:
140+
A string containing the MAC address in the format
141+
'XX:XX:XX:XX:XX:XX'
142+
"""
143+
return self._eeprom.get_mac()
144+
145+
def get_model(self):
146+
"""
147+
Retrieves the model number (or part number) of the device
148+
Returns:
149+
string: Model/part number of device
150+
"""
151+
return self._eeprom.get_pn()
152+
153+
def get_serial(self):
154+
"""
155+
Retrieves the hardware serial number for the chassis
156+
Returns:
157+
A string containing the hardware serial number for this chassis.
158+
"""
159+
return self._eeprom.get_serial()
160+
161+
def get_system_eeprom_info(self):
162+
"""
163+
Retrieves the full content of system EEPROM information for the chassis
164+
Returns:
165+
A dictionary where keys are the type code defined in
166+
OCP ONIE TlvInfo EEPROM format and values are their corresponding
167+
values.
168+
"""
169+
return self._eeprom.get_eeprom()
170+
171+
def get_reboot_cause(self):
172+
"""
173+
Retrieves the cause of the previous reboot
174+
175+
Returns:
176+
A tuple (string, string) where the first element is a string
177+
containing the cause of the previous reboot. This string must be
178+
one of the predefined strings in this class. If the first string
179+
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
180+
to pass a description of the reboot cause.
181+
"""
182+
183+
reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + REBOOT_CAUSE_FILE)
184+
sw_reboot_cause = self._api_helper.read_txt_file(
185+
reboot_cause_path) or "Unknown"
186+
187+
188+
return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause)
189+
190+
def get_change_event(self, timeout=0):
191+
# SFP event
192+
if not self.sfp_module_initialized:
193+
self.__initialize_sfp()
194+
195+
status, sfp_event = SfpEvent(self._sfp_list).get_sfp_event(timeout)
196+
197+
return status, sfp_event
198+
199+
def get_sfp(self, index):
200+
"""
201+
Retrieves sfp represented by (1-based) index <index>
202+
Args:
203+
index: An integer, the index (1-based) of the sfp to retrieve.
204+
The index should be the sequence of a physical port in a chassis,
205+
starting from 1.
206+
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
207+
Returns:
208+
An object dervied from SfpBase representing the specified sfp
209+
"""
210+
sfp = None
211+
if not self.sfp_module_initialized:
212+
self.__initialize_sfp()
213+
214+
try:
215+
# The index will start from 1
216+
sfp = self._sfp_list[index-1]
217+
except IndexError:
218+
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
219+
index, len(self._sfp_list)))
220+
return sfp
221+
222+
def get_position_in_parent(self):
223+
"""
224+
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
225+
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
226+
Returns:
227+
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
228+
"""
229+
return -1
230+
231+
def is_replaceable(self):
232+
"""
233+
Indicate whether this device is replaceable.
234+
Returns:
235+
bool: True if it is replaceable.
236+
"""
237+
return False
238+
239+
240+
def initizalize_system_led(self):
241+
return True
242+
243+
def get_status_led(self):
244+
val = self._api_helper.read_txt_file(SYSLED_FNODE)
245+
return SYSLED_MODES[val] if val in SYSLED_MODES else "UNKNOWN"
246+
247+
def set_status_led(self, color):
248+
mode = None
249+
for key, val in SYSLED_MODES.items():
250+
if val == color:
251+
mode = key
252+
break
253+
if mode is None:
254+
return False
255+
else:
256+
return self._api_helper.write_txt_file(SYSLED_FNODE, mode)
257+

0 commit comments

Comments
 (0)