Skip to content

Commit 2b42ac6

Browse files
author
Jostar Yang
committed
Add component.py
1 parent 1ef791d commit 2b42ac6

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

platform/broadcom/sonic-platform-modules-accton/as5835-54x/sonic_platform/chassis.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,23 @@
1313
except ImportError as e:
1414
raise ImportError(str(e) + "- required module not found")
1515

16+
NUM_COMPONENT = 4
17+
1618
class Chassis(PddfChassis):
1719
"""
1820
PDDF Platform-specific Chassis class
1921
"""
2022

2123
def __init__(self, pddf_data=None, pddf_plugin_data=None):
2224
PddfChassis.__init__(self, pddf_data, pddf_plugin_data)
25+
self.__initialize_components()
26+
27+
def __initialize_components(self):
28+
from sonic_platform.component import Component
29+
for index in range(NUM_COMPONENT):
30+
component = Component(index)
31+
self._component_list.append(component)
32+
2333

2434
# Provide the functions/variables below for which implementation is to be overwritten
2535
sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#############################################################################
2+
#
3+
# Component contains an implementation of SONiC Platform Base API and
4+
# provides the components firmware management function
5+
#
6+
#############################################################################
7+
8+
try:
9+
import subprocess
10+
import logging
11+
from sonic_platform_base.component_base import ComponentBase
12+
except ImportError as e:
13+
raise ImportError(str(e) + "- required module not found")
14+
15+
CPLD_ADDR_MAPPING = {
16+
"CPLD1": ['3', '0x60'],
17+
"CPLD2": ['3', '0x61'],
18+
"CPLD3": ['3', '0x62']
19+
}
20+
SYSFS_PATH = "/sys/bus/i2c/devices/"
21+
BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version"
22+
COMPONENT_LIST= [
23+
("CPLD1", "CPLD 1"),
24+
("CPLD2", "CPLD 2"),
25+
("CPLD3", "CPLD 3"),
26+
("BIOS", "Basic Input/Output System")
27+
28+
]
29+
30+
class Component(ComponentBase):
31+
"""Platform-specific Component class"""
32+
33+
DEVICE_TYPE = "component"
34+
35+
def __init__(self, component_index=0):
36+
self.index = component_index
37+
self.name = self.get_name()
38+
39+
def __run_command(self, command):
40+
# Run bash command and print output to stdout
41+
try:
42+
process = subprocess.Popen(
43+
shlex.split(command), stdout=subprocess.PIPE)
44+
while True:
45+
output = process.stdout.readline()
46+
if output == '' and process.poll() is not None:
47+
break
48+
rc = process.poll()
49+
if rc != 0:
50+
return False
51+
except Exception:
52+
return False
53+
return True
54+
55+
def __get_bios_version(self):
56+
# Retrieves the BIOS firmware version
57+
try:
58+
with open(BIOS_VERSION_PATH, 'r') as fd:
59+
bios_version = fd.read()
60+
return bios_version.strip()
61+
except Exception as e:
62+
return None
63+
64+
def __get_cpld_version(self):
65+
# Retrieves the CPLD firmware version
66+
cpld_version = dict()
67+
for cpld_name in CPLD_ADDR_MAPPING:
68+
cmd = "i2cget -f -y {0} {1} 0x1".format(CPLD_ADDR_MAPPING[cpld_name][0], CPLD_ADDR_MAPPING[cpld_name][1])
69+
status, value = subprocess.getstatusoutput(cmd)
70+
if not status:
71+
cpld_version_raw = value.rstrip()
72+
cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16))
73+
74+
return cpld_version
75+
76+
def get_name(self):
77+
"""
78+
Retrieves the name of the component
79+
Returns:
80+
A string containing the name of the component
81+
"""
82+
return COMPONENT_LIST[self.index][0]
83+
84+
def get_description(self):
85+
"""
86+
Retrieves the description of the component
87+
Returns:
88+
A string containing the description of the component
89+
"""
90+
return COMPONENT_LIST[self.index][1]
91+
92+
def get_firmware_version(self):
93+
"""
94+
Retrieves the firmware version of module
95+
Returns:
96+
string: The firmware versions of the module
97+
"""
98+
fw_version = None
99+
100+
if self.name == "BIOS":
101+
fw_version = self.__get_bios_version()
102+
elif "CPLD" in self.name:
103+
cpld_version = self.__get_cpld_version()
104+
fw_version = cpld_version.get(self.name)
105+
106+
return fw_version
107+
108+
def install_firmware(self, image_path):
109+
"""
110+
Install firmware to module
111+
Args:
112+
image_path: A string, path to firmware image
113+
Returns:
114+
A boolean, True if install successfully, False if not
115+
"""
116+
raise NotImplementedError

platform/broadcom/sonic-platform-modules-accton/as5835-54x/sonic_platform/psu.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ def get_capacity(self):
3434
An integer, the capacity of PSU
3535
"""
3636
return (self.PLATFORM_PSU_CAPACITY)
37+
38+
def get_type(self):
39+
"""
40+
Gets the type of the PSU
41+
Returns:
42+
A string, the type of PSU (AC/DC)
43+
"""
44+
return "AC"

0 commit comments

Comments
 (0)