Skip to content

Commit

Permalink
Added new API to interact with the platform components (sonic-net#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
nazariig authored and jleveque committed Sep 10, 2019
1 parent c21507e commit 33b037d
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 40 deletions.
51 changes: 31 additions & 20 deletions sonic_platform_base/chassis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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

Expand Down Expand Up @@ -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 <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
Expand Down
52 changes: 52 additions & 0 deletions sonic_platform_base/component_base.py
Original file line number Diff line number Diff line change
@@ -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
51 changes: 31 additions & 20 deletions sonic_platform_base/module_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand Down Expand Up @@ -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 <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
Expand Down

0 comments on commit 33b037d

Please sign in to comment.