diff --git a/platform/marvell/sonic-platform-db98cx8540-16cd/db98cx8540/sonic_platform/chassis.py b/platform/marvell/sonic-platform-db98cx8540-16cd/db98cx8540/sonic_platform/chassis.py index 8f7ae9d51..b56f2c817 100644 --- a/platform/marvell/sonic-platform-db98cx8540-16cd/db98cx8540/sonic_platform/chassis.py +++ b/platform/marvell/sonic-platform-db98cx8540-16cd/db98cx8540/sonic_platform/chassis.py @@ -11,10 +11,12 @@ from sonic_platform.sfp import Sfp from sonic_platform.eeprom import Eeprom from sonic_py_common import logger + from sonic_platform.component import Component except ImportError as e: raise ImportError(str(e) + "- required module not found") +MAX_COMPONENT=2 MAX_SELECT_DELAY = 3600 SFP_PORT_START = 1 SFP_PORT_END = 132 @@ -163,6 +165,9 @@ def __init__(self): # Instantiate ONIE system eeprom object self._eeprom = Eeprom() + for i in range(MAX_COMPONENT): + component = Component(i) + self._component_list.append(component) def __get_path_to_sai_profile_file(self): """ diff --git a/platform/marvell/sonic-platform-db98cx8540-16cd/db98cx8540/sonic_platform/component.py b/platform/marvell/sonic-platform-db98cx8540-16cd/db98cx8540/sonic_platform/component.py new file mode 100644 index 000000000..ae0a76411 --- /dev/null +++ b/platform/marvell/sonic-platform-db98cx8540-16cd/db98cx8540/sonic_platform/component.py @@ -0,0 +1,91 @@ +######################################################################## +# +# Module contains an implementation of SONiC Platform Base API and +# provides the Components' (e.g., BIOS, CPLD, FPGA, etc.) available in +# the platform +# +######################################################################## + +try: + import sys + import subprocess + from sonic_platform_base.component_base import ComponentBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + +if sys.version_info[0] < 3: + import commands as cmd +else: + import subprocess as cmd + + +class Component(ComponentBase): + """platform-specific Component class""" + + CHASSIS_COMPONENTS = [ + ["BIOS", "BIOS - Basic Input/Output System"], + ["ONIE-VERSION", "ONIE - Open Network Install Environment"], + ] + + def __init__(self, component_index): + self.index = component_index + self.name = self.CHASSIS_COMPONENTS[self.index][0] + self.description = self.CHASSIS_COMPONENTS[self.index][1] + + def _get_command_result(self, cmdline): + try: + proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + stdout = proc.communicate()[0] + proc.wait() + result = stdout.rstrip('\n') + except OSError: + result = None + + return result + + def get_name(self): + """ + Retrieves the name of the component + + Returns: + A string containing the name of the component + """ + return self.name + + def get_description(self): + """ + Retrieves the description of the component + + Returns: + A string containing the description of the component + """ + return self.description + + def get_firmware_version(self): + """ + Retrieves the firmware version of the component + + Returns: + A string containing the firmware version of the component + """ + if self.index == 0: + cmdstatus, bios_version = cmd.getstatusoutput('dmidecode -s bios-version') + return bios_version + + if self.index == 1: + cmdstatus, onie_version = cmd.getstatusoutput('grep ^onie_version /host/machine.conf | cut -f2 -d"="') + return onie_version + + def install_firmware(self, image_path): + """ + Installs firmware to the component + + Args: + image_path: A string, path to firmware image + + Returns: + A boolean, True if install was successful, False if not + """ + return False + diff --git a/platform/marvell/sonic-platform-db98cx8580-32cd/db98cx8580/sonic_platform/chassis.py b/platform/marvell/sonic-platform-db98cx8580-32cd/db98cx8580/sonic_platform/chassis.py index 97d5ab994..f90f8cdb4 100644 --- a/platform/marvell/sonic-platform-db98cx8580-32cd/db98cx8580/sonic_platform/chassis.py +++ b/platform/marvell/sonic-platform-db98cx8580-32cd/db98cx8580/sonic_platform/chassis.py @@ -10,11 +10,13 @@ from sonic_platform_base.chassis_base import ChassisBase from sonic_platform.sfp import Sfp from sonic_platform.eeprom import Eeprom + from sonic_platform.component import Component from sonic_py_common import logger except ImportError as e: raise ImportError(str(e) + "- required module not found") +MAX_COMPONENT=2 MAX_SELECT_DELAY = 3600 COPPER_PORT_START = 0 COPPER_PORT_END = 0 @@ -180,6 +182,10 @@ def __init__(self): # Instantiate ONIE system eeprom object self._eeprom = Eeprom() + for i in range(MAX_COMPONENT): + component = Component(i) + self._component_list.append(component) + def __get_path_to_sai_profile_file(self): """ diff --git a/platform/marvell/sonic-platform-db98cx8580-32cd/db98cx8580/sonic_platform/component.py b/platform/marvell/sonic-platform-db98cx8580-32cd/db98cx8580/sonic_platform/component.py new file mode 100644 index 000000000..ae0a76411 --- /dev/null +++ b/platform/marvell/sonic-platform-db98cx8580-32cd/db98cx8580/sonic_platform/component.py @@ -0,0 +1,91 @@ +######################################################################## +# +# Module contains an implementation of SONiC Platform Base API and +# provides the Components' (e.g., BIOS, CPLD, FPGA, etc.) available in +# the platform +# +######################################################################## + +try: + import sys + import subprocess + from sonic_platform_base.component_base import ComponentBase +except ImportError as e: + raise ImportError(str(e) + "- required module not found") + +if sys.version_info[0] < 3: + import commands as cmd +else: + import subprocess as cmd + + +class Component(ComponentBase): + """platform-specific Component class""" + + CHASSIS_COMPONENTS = [ + ["BIOS", "BIOS - Basic Input/Output System"], + ["ONIE-VERSION", "ONIE - Open Network Install Environment"], + ] + + def __init__(self, component_index): + self.index = component_index + self.name = self.CHASSIS_COMPONENTS[self.index][0] + self.description = self.CHASSIS_COMPONENTS[self.index][1] + + def _get_command_result(self, cmdline): + try: + proc = subprocess.Popen(cmdline.split(), stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + stdout = proc.communicate()[0] + proc.wait() + result = stdout.rstrip('\n') + except OSError: + result = None + + return result + + def get_name(self): + """ + Retrieves the name of the component + + Returns: + A string containing the name of the component + """ + return self.name + + def get_description(self): + """ + Retrieves the description of the component + + Returns: + A string containing the description of the component + """ + return self.description + + def get_firmware_version(self): + """ + Retrieves the firmware version of the component + + Returns: + A string containing the firmware version of the component + """ + if self.index == 0: + cmdstatus, bios_version = cmd.getstatusoutput('dmidecode -s bios-version') + return bios_version + + if self.index == 1: + cmdstatus, onie_version = cmd.getstatusoutput('grep ^onie_version /host/machine.conf | cut -f2 -d"="') + return onie_version + + def install_firmware(self, image_path): + """ + Installs firmware to the component + + Args: + image_path: A string, path to firmware image + + Returns: + A boolean, True if install was successful, False if not + """ + return False +