diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index 9ffc7c4e5190..4e1762699e9a 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -26,6 +26,10 @@ class ChassisBase(device_base.DeviceBase): REBOOT_CAUSE_HARDWARE_OTHER = "Hardware - Other" REBOOT_CAUSE_NON_HARDWARE = "Non-Hardware" + # List of ComponentBase-derived objects representing all components + # available on the chassis + _component_list = [] + # List of ModuleBase-derived objects representing all modules # available on the chassis (for use with modular chassis) _module_list = [] @@ -46,9 +50,6 @@ class ChassisBase(device_base.DeviceBase): # available on the chassis _sfp_list = [] - # List of component names that are available on the chassis - _component_name_list = [] - # Object derived from WatchdogBase for interacting with hardware watchdog _watchdog = None @@ -101,38 +102,48 @@ def get_reboot_cause(self): """ raise NotImplementedError - def get_component_name_list(self): + ############################################## + # Component methods + ############################################## + + def get_num_components(self): """ - Retrieves a list of the names of components available on the chassis (e.g., BIOS, CPLD, FPGA, etc.) + Retrieves the number of components available on this chassis Returns: - A list containing the names of components available on the chassis + An integer, the number of components available on this chassis """ - return self._component_name_list + return len(self._component_list) - def get_firmware_version(self, component_name): + def get_all_components(self): """ - Retrieves platform-specific hardware/firmware versions for chassis - componenets such as BIOS, CPLD, FPGA, etc. - Args: - component_name: A string, the component name. + Retrieves all components available on this chassis Returns: - A string containing platform-specific component versions + A list of objects derived from ComponentBase representing all components + available on this chassis """ - raise NotImplementedError + return self._component_list - def install_component_firmware(self, component_name, image_path): + def get_component(self, index): """ - Install firmware to component + Retrieves component represented by (0-based) index + Args: - component_name: A string, the component name. - image_path: A string, path to firmware image. + index: An integer, the index (0-based) of the component to retrieve Returns: - A boolean, True if install was successful, False if not + An object dervied from ComponentBase representing the specified component """ - raise NotImplementedError + component = None + + try: + component = self._component_list[index] + except IndexError: + sys.stderr.write("Component index {} out of range (0-{})\n".format( + index, len(self._component_list)-1)) + + return component ############################################## # Module methods diff --git a/sonic_platform_base/component_base.py b/sonic_platform_base/component_base.py new file mode 100644 index 000000000000..97444460ae2f --- /dev/null +++ b/sonic_platform_base/component_base.py @@ -0,0 +1,52 @@ +# +# component_base.py +# +# Abstract base class for implementing a platform-specific class +# to interact with a chassis/module component (e.g., BIOS, CPLD, FPGA, etc.) in SONiC +# + + +class ComponentBase(object): + """ + Abstract base class for implementing a platform-specific class + to interact with a chassis/module component (e.g., BIOS, CPLD, FPGA, etc.) + """ + + def get_name(self): + """ + Retrieves the name of the component + + Returns: + A string containing the name of the component + """ + raise NotImplementedError + + def get_description(self): + """ + Retrieves the description of the component + + Returns: + A string containing the description of the component + """ + raise NotImplementedError + + def get_firmware_version(self): + """ + Retrieves the firmware version of the component + + Returns: + A string containing the firmware version of the component + """ + raise NotImplementedError + + 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 + """ + raise NotImplementedError diff --git a/sonic_platform_base/module_base.py b/sonic_platform_base/module_base.py index 583f3cc357e2..b4f8ac4514f1 100644 --- a/sonic_platform_base/module_base.py +++ b/sonic_platform_base/module_base.py @@ -17,6 +17,10 @@ class ModuleBase(device_base.DeviceBase): # Device type definition. Note, this is a constant. DEVICE_TYPE = "module" + # List of ComponentBase-derived objects representing all components + # available on the module + _component_list = [] + # List of FanBase-derived objects representing all fans # available on the module _fan_list = [] @@ -33,9 +37,6 @@ class ModuleBase(device_base.DeviceBase): # available on the module _sfp_list = [] - # List of component names that available on the chassis - _component_name_list = [] - def get_base_mac(self): """ Retrieves the base MAC address for the module @@ -69,38 +70,48 @@ def get_system_eeprom_info(self): """ raise NotImplementedError - def get_component_name_list(self): + ############################################## + # Component methods + ############################################## + + def get_num_components(self): """ - Retrieves a list of the names of components available on the module (e.g., BIOS, CPLD, FPGA, etc.) + Retrieves the number of components available on this module Returns: - A list containing the names of components available on the module. + An integer, the number of components available on this module """ - return self._component_name_list + return len(self._component_list) - def get_firmware_version(self, component_name): + def get_all_components(self): """ - Retrieves platform-specific hardware/firmware versions for chassis - componenets such as BIOS, CPLD, FPGA, etc. - Args: - component_name: A string, the component name. + Retrieves all components available on this module Returns: - A string containing platform-specific component versions + A list of objects derived from ComponentBase representing all components + available on this module """ - raise NotImplementedError + return self._component_list - def install_component_firmware(self, component_name, image_path): + def get_component(self, index): """ - Install firmware to component + Retrieves component represented by (0-based) index + Args: - component_name: A string, the component name. - image_path: A string, path to firmware image. + index: An integer, the index (0-based) of the component to retrieve Returns: - A boolean, True if install was successful, False if not + An object dervied from ComponentBase representing the specified component """ - raise NotImplementedError + component = None + + try: + component = self._component_list[index] + except IndexError: + sys.stderr.write("Component index {} out of range (0-{})\n".format( + index, len(self._component_list)-1)) + + return component ############################################## # Fan module methods