Skip to content

Commit

Permalink
Adding support to firmware status
Browse files Browse the repository at this point in the history
  • Loading branch information
lkunjumon committed Jul 30, 2021
1 parent 347af22 commit a1ca97d
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):

"""
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a1ca97d

Please sign in to comment.