-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jostar Yang <[email protected]>
- Loading branch information
Jostar Yang
committed
May 18, 2021
1 parent
3db6572
commit c5e4141
Showing
13 changed files
with
2,344 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
device/accton/x86_64-accton_as7816_64x-r0/sonic_platform/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__all__ = ['chassis', 'eeprom', 'platform', 'psu', 'sfp', 'thermal', 'fan'] | ||
from . import platform |
213 changes: 213 additions & 0 deletions
213
device/accton/x86_64-accton_as7816_64x-r0/sonic_platform/chassis.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
############################################################################# | ||
# Edgecore | ||
# | ||
# Module contains an implementation of SONiC Platform Base API and | ||
# provides the Chassis information which are available in the platform | ||
# | ||
############################################################################# | ||
|
||
import os | ||
import sys | ||
import logging | ||
|
||
try: | ||
from sonic_platform_base.chassis_base import ChassisBase | ||
from .helper import APIHelper | ||
from .event import SfpEvent | ||
except ImportError as e: | ||
raise ImportError(str(e) + "- required module not found") | ||
|
||
NUM_FAN_TRAY = 4 | ||
NUM_FAN = 2 | ||
NUM_PSU = 2 | ||
NUM_THERMAL = 6 | ||
NUM_PORT = 64 | ||
NUM_COMPONENT = 4 | ||
HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/" | ||
PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/" | ||
REBOOT_CAUSE_FILE = "reboot-cause.txt" | ||
PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt" | ||
HOST_CHK_CMD = "docker > /dev/null 2>&1" | ||
|
||
|
||
class Chassis(ChassisBase): | ||
"""Platform-specific Chassis class""" | ||
|
||
def __init__(self): | ||
ChassisBase.__init__(self) | ||
self._api_helper = APIHelper() | ||
self._api_helper = APIHelper() | ||
self.is_host = self._api_helper.is_host() | ||
|
||
self.config_data = {} | ||
|
||
self.__initialize_fan() | ||
self.__initialize_psu() | ||
self.__initialize_thermals() | ||
self.__initialize_components() | ||
self.__initialize_sfp() | ||
self.__initialize_eeprom() | ||
|
||
def __initialize_sfp(self): | ||
from sonic_platform.sfp import Sfp | ||
for index in range(0, NUM_PORT): | ||
sfp = Sfp(index) | ||
self._sfp_list.append(sfp) | ||
self.sfp_module_initialized = True | ||
|
||
def __initialize_fan(self): | ||
from sonic_platform.fan import Fan | ||
for fant_index in range(0, NUM_FAN_TRAY): | ||
for fan_index in range(0, NUM_FAN): | ||
fan = Fan(fant_index, fan_index) | ||
self._fan_list.append(fan) | ||
|
||
def __initialize_psu(self): | ||
from sonic_platform.psu import Psu | ||
for index in range(0, NUM_PSU): | ||
psu = Psu(index) | ||
self._psu_list.append(psu) | ||
|
||
def __initialize_thermals(self): | ||
from sonic_platform.thermal import Thermal | ||
for index in range(0, NUM_THERMAL): | ||
thermal = Thermal(index) | ||
self._thermal_list.append(thermal) | ||
|
||
def __initialize_eeprom(self): | ||
from sonic_platform.eeprom import Tlv | ||
self._eeprom = Tlv() | ||
|
||
def __initialize_components(self): | ||
from sonic_platform.component import Component | ||
for index in range(0, NUM_COMPONENT): | ||
component = Component(index) | ||
self._component_list.append(component) | ||
|
||
def __initialize_watchdog(self): | ||
from sonic_platform.watchdog import Watchdog | ||
self._watchdog = Watchdog() | ||
|
||
|
||
def __is_host(self): | ||
return os.system(HOST_CHK_CMD) == 0 | ||
|
||
def __read_txt_file(self, file_path): | ||
try: | ||
with open(file_path, 'r') as fd: | ||
data = fd.read() | ||
return data.strip() | ||
except IOError: | ||
pass | ||
return None | ||
|
||
def get_name(self): | ||
""" | ||
Retrieves the name of the device | ||
Returns: | ||
string: The name of the device | ||
""" | ||
|
||
return self._api_helper.hwsku | ||
|
||
def get_presence(self): | ||
""" | ||
Retrieves the presence of the Chassis | ||
Returns: | ||
bool: True if Chassis is present, False if not | ||
""" | ||
return True | ||
|
||
def get_status(self): | ||
""" | ||
Retrieves the operational status of the device | ||
Returns: | ||
A boolean value, True if device is operating properly, False if not | ||
""" | ||
return True | ||
|
||
def get_base_mac(self): | ||
""" | ||
Retrieves the base MAC address for the chassis | ||
Returns: | ||
A string containing the MAC address in the format | ||
'XX:XX:XX:XX:XX:XX' | ||
""" | ||
return self._eeprom.get_mac() | ||
|
||
def get_model(self): | ||
""" | ||
Retrieves the model number (or part number) of the device | ||
Returns: | ||
string: Model/part number of device | ||
""" | ||
return self._eeprom.get_pn() | ||
|
||
def get_serial_number(self): | ||
""" | ||
Retrieves the hardware serial number for the chassis | ||
Returns: | ||
A string containing the hardware serial number for this chassis. | ||
""" | ||
return self._eeprom.get_serial() | ||
|
||
def get_system_eeprom_info(self): | ||
""" | ||
Retrieves the full content of system EEPROM information for the chassis | ||
Returns: | ||
A dictionary where keys are the type code defined in | ||
OCP ONIE TlvInfo EEPROM format and values are their corresponding | ||
values. | ||
""" | ||
return self._eeprom.get_eeprom() | ||
|
||
def get_reboot_cause(self): | ||
""" | ||
Retrieves the cause of the previous reboot | ||
Returns: | ||
A tuple (string, string) where the first element is a string | ||
containing the cause of the previous reboot. This string must be | ||
one of the predefined strings in this class. If the first string | ||
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used | ||
to pass a description of the reboot cause. | ||
""" | ||
|
||
reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + REBOOT_CAUSE_FILE) | ||
sw_reboot_cause = self._api_helper.read_txt_file( | ||
reboot_cause_path) or "Unknown" | ||
|
||
|
||
return ('REBOOT_CAUSE_NON_HARDWARE', sw_reboot_cause) | ||
|
||
def get_change_event(self, timeout=0): | ||
# SFP event | ||
if not self.sfp_module_initialized: | ||
self.__initialize_sfp() | ||
|
||
status, sfp_event = SfpEvent(self._sfp_list).get_sfp_event(timeout) | ||
|
||
return status, sfp_event | ||
|
||
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 dervied from SfpBase representing the specified sfp | ||
""" | ||
sfp = None | ||
if not self.sfp_module_initialized: | ||
self.__initialize_sfp() | ||
|
||
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 |
127 changes: 127 additions & 0 deletions
127
device/accton/x86_64-accton_as7816_64x-r0/sonic_platform/component.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
############################################################################# | ||
# Celestica | ||
# | ||
# Component contains an implementation of SONiC Platform Base API and | ||
# provides the components firmware management function | ||
# | ||
############################################################################# | ||
|
||
import shlex | ||
import subprocess | ||
import logging | ||
|
||
try: | ||
from sonic_platform_base.component_base import ComponentBase | ||
from .helper import APIHelper | ||
except ImportError as e: | ||
raise ImportError(str(e) + "- required module not found") | ||
|
||
CPLD_ADDR_MAPPING = { | ||
"CPLD1": "19-0060", | ||
"CPLD2": "20-0062", | ||
"CPLD3": "21-0064", | ||
"CPLD4": "22-0066", | ||
} | ||
SYSFS_PATH = "/sys/bus/i2c/devices/" | ||
BIOS_VERSION_PATH = "/sys/class/dmi/id/bios_version" | ||
COMPONENT_LIST= [ | ||
("CPLD1", "CPLD 1"), | ||
("CPLD2", "CPLD 2"), | ||
("CPLD3", "CPLD 3"), | ||
("CPLD4", "CPLD 4"), | ||
("BIOS", "Basic Input/Output System") | ||
|
||
] | ||
|
||
class Component(ComponentBase): | ||
"""Platform-specific Component class""" | ||
|
||
DEVICE_TYPE = "component" | ||
|
||
def __init__(self, component_index=0): | ||
self._api_helper=APIHelper() | ||
ComponentBase.__init__(self) | ||
self.index = component_index | ||
self.name = self.get_name() | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
def __run_command(self, command): | ||
# Run bash command and print output to stdout | ||
try: | ||
process = subprocess.Popen( | ||
shlex.split(command), stdout=subprocess.PIPE) | ||
while True: | ||
output = process.stdout.readline() | ||
if output == '' and process.poll() is not None: | ||
break | ||
rc = process.poll() | ||
if rc != 0: | ||
return False | ||
except Exception: | ||
return False | ||
return True | ||
|
||
def __get_bios_version(self): | ||
# Retrieves the BIOS firmware version | ||
try: | ||
with open(BIOS_VERSION_PATH, 'r') as fd: | ||
bios_version = fd.read() | ||
return bios_version.strip() | ||
except Exception as e: | ||
return None | ||
|
||
def __get_cpld_version(self): | ||
# Retrieves the CPLD firmware version | ||
cpld_version = dict() | ||
for cpld_name in CPLD_ADDR_MAPPING: | ||
try: | ||
cpld_path = "{}{}{}".format(SYSFS_PATH, CPLD_ADDR_MAPPING[cpld_name], '/version') | ||
cpld_version_raw= self._api_helper.read_txt_file(cpld_path) | ||
cpld_version[cpld_name] = "{}".format(int(cpld_version_raw,16)) | ||
except Exception as e: | ||
print('Get exception when read cpld') | ||
cpld_version[cpld_name] = 'None' | ||
|
||
return cpld_version | ||
|
||
def get_name(self): | ||
""" | ||
Retrieves the name of the component | ||
Returns: | ||
A string containing the name of the component | ||
""" | ||
return COMPONENT_LIST[self.index][0] | ||
|
||
def get_description(self): | ||
""" | ||
Retrieves the description of the component | ||
Returns: | ||
A string containing the description of the component | ||
""" | ||
return COMPONENT_LIST[self.index][1] | ||
|
||
def get_firmware_version(self): | ||
""" | ||
Retrieves the firmware version of module | ||
Returns: | ||
string: The firmware versions of the module | ||
""" | ||
fw_version = None | ||
|
||
if self.name == "BIOS": | ||
fw_version = self.__get_bios_version() | ||
elif "CPLD" in self.name: | ||
cpld_version = self.__get_cpld_version() | ||
fw_version = cpld_version.get(self.name) | ||
|
||
return fw_version | ||
|
||
def install_firmware(self, image_path): | ||
""" | ||
Install firmware to module | ||
Args: | ||
image_path: A string, path to firmware image | ||
Returns: | ||
A boolean, True if install successfully, False if not | ||
""" | ||
raise NotImplementedError |
Oops, something went wrong.