Skip to content

Commit

Permalink
Enhance new platform API (sonic-net#19)
Browse files Browse the repository at this point in the history
* Changes of SONiC new platform API based on latest design

* Moved get_change_event from DeviceBase to ChassisBase and ModuleBase

* chassis_base.py : added get_change_event
device_base.py : fixed typo
fan_base.py : defined DEVICE_TYPE
module_base.py : defined DEVICE_TYPE, fixed typo
psu_base.py : defined DEVICE_TYPE
sfp_base.py : defined DEVICE_TYPE, fixed typo, modified descriptions of set_power_override
thermal_base.py : defined DEVICE_TYPE

* module_base.py : modified get_change_event to return devices in nested dict

* Added dom related status support for SFP, including temperature, voltage, TX bias, TX power and RX power

* 1. Per channel return for TX bias, TX power and RX power in sfp_base.py.
2. Support system EEPROM and serial number in chassis_base.py.

* 1. Added SYS EEPROM functions to module_base.py.  2. Fixed typos.  3. Merge get_watchdog to return self._watchdog in chassis_base

* 1. Fixed various typos.  2. Changed get_ampere to get_current, get_watt to get_power in psu_base.py

* Changed get_system_eeprom return to use type code defined in ONIE TlvInfo EEPROM as the keys
  • Loading branch information
JohnFanDNI authored and jleveque committed Apr 5, 2019
1 parent 92b54b1 commit e550a3c
Show file tree
Hide file tree
Showing 7 changed files with 744 additions and 36 deletions.
146 changes: 146 additions & 0 deletions sonic_platform_base/chassis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class ChassisBase(device_base.DeviceBase):
"""
Base class for interfacing with a platform chassis
"""
# Device type definition. Note, this is a constant.
DEVICE_TYPE = "chassis"

# Possible reboot causes
REBOOT_CAUSE_POWER_LOSS = "power_loss"
Expand All @@ -36,6 +38,14 @@ class ChassisBase(device_base.DeviceBase):
# available on the chassis
_psu_list = []

# List of ThermalBase-derived objects representing all thermals
# available on the chassis
_thermal_list = []

# List of SfpBase-derived objects representing all sfps
# available on the chassis
_sfp_list = []

# Object derived from WatchdogBase for interacting with hardware watchdog
_watchdog = None

Expand All @@ -49,6 +59,29 @@ def get_base_mac(self):
"""
raise NotImplementedError

def get_serial_number(self):
"""
Retrieves the hardware serial number for the chassis
Returns:
A string containing the hardware serial number for this chassis.
"""
raise NotImplementedError

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.
Ex. { ‘0x21’:’AG9064’, ‘0x22’:’V1.0’, ‘0x23’:’AG9064-0109867821’,
‘0x24’:’001c0f000fcd0a’, ‘0x25’:’02/03/2018 16:22:00’,
‘0x26’:’01’, ‘0x27’:’REV01’, ‘0x28’:’AG9064-C2358-16G’}
"""
raise NotImplementedError

def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
Expand Down Expand Up @@ -208,6 +241,93 @@ def get_psu(self, index):

return psu

##############################################
# THERMAL methods
##############################################

def get_num_thermals(self):
"""
Retrieves the number of thermals available on this chassis
Returns:
An integer, the number of thermals available on this chassis
"""
return len(self._thermal_list)

def get_all_thermals(self):
"""
Retrieves all thermals available on this chassis
Returns:
A list of objects derived from ThermalBase representing all thermals
available on this chassis
"""
return self._thermal_list

def get_thermal(self, index):
"""
Retrieves thermal unit represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the thermal to
retrieve
Returns:
An object dervied from ThermalBase representing the specified thermal
"""
thermal = None

try:
thermal = self._thermal_list[index]
except IndexError:
sys.stderr.write("THERMAL index {} out of range (0-{})\n".format(
index, len(self._thermal_list)-1))

return thermal

##############################################
# SFP methods
##############################################

def get_num_sfps(self):
"""
Retrieves the number of sfps available on this chassis
Returns:
An integer, the number of sfps available on this chassis
"""
return len(self._sfp_list)

def get_all_sfps(self):
"""
Retrieves all sfps available on this chassis
Returns:
A list of objects derived from SfpBase representing all sfps
available on this chassis
"""
return self._sfp_list

def get_sfp(self, index):
"""
Retrieves sfp represented by (0-based) index <index>
Args:
index: An integer, the index (0-based) of the sfp to retrieve
Returns:
An object dervied from SfpBase representing the specified sfp
"""
sfp = None

try:
sfp = self._sfp_list[index]
except IndexError:
sys.stderr.write("SFP index {} out of range (0-{})\n".format(
index, len(self._sfp_list)-1))

return sfp

##############################################
# Other methods
##############################################
Expand All @@ -221,3 +341,29 @@ def get_watchdog(self):
watchdog device
"""
return self._watchdog

def get_change_event(self, timeout=0):
"""
Returns a nested dictionary containing all devices which have
experienced a change at chassis level
Args:
timeout: Timeout in milliseconds (optional). If timeout == 0,
this method will block until a change is detected.
Returns:
(bool, dict):
- True if call successful, False if not;
- A nested dictionary where key is a device type,
value is a dictionary with key:value pairs in the format of
{'device_id':'device_event'},
where device_id is the device ID for this device and
device_event,
status='1' represents device inserted,
status='0' represents device removed.
Ex. {'fan':{'0':'0', '2':'1'}, 'sfp':{'11':'0'}}
indicates that fan 0 has been removed, fan 2
has been inserted and sfp 11 has been removed.
"""
raise NotImplementedError

26 changes: 8 additions & 18 deletions sonic_platform_base/device_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class DeviceBase(object):
peripheral device
"""

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""

def get_presence(self):
"""
Retrieves the presence of the device
Expand Down Expand Up @@ -46,21 +54,3 @@ def get_status(self):
A boolean value, True if device is operating properly, False if not
"""
raise NotImplementedError

def get_change_event(self, timeout=0):
"""
Returns a dictionary containing all devices which have experienced a
change
Args:
timeout: Timeout in milliseconds (optional). If timeout == 0,
this method will block until a change is detected.
Returns:
(bool, dict):
- True if call successful, False if not;
- Dict where key is device ID and value is device event,
status='1' represents device inserted,
status='0' represents device removed. Ex. {'0': '1', '1': '0'}
"""
raise NotImplementedError
2 changes: 2 additions & 0 deletions sonic_platform_base/fan_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class FanBase(device_base.DeviceBase):
"""
Abstract base class for interfacing with a fan module
"""
# Device type definition. Note, this is a constant.
DEVICE_TYPE = "fan"

# Possible fan directions (relative to port-side of device)
FAN_DIRECTION_INTAKE = "intake"
Expand Down
Loading

0 comments on commit e550a3c

Please sign in to comment.