Skip to content

Commit

Permalink
Add sonic_platform and get_sfpt to chassis
Browse files Browse the repository at this point in the history
  • Loading branch information
Jostar Yang committed Jun 28, 2021
1 parent 40590f2 commit a8e7457
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# All the derived classes for PDDF
__all__ = ["platform", "chassis", "sfp", "psu", "thermal", "fan"]
from . import platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python

#############################################################################
# PDDF
# Module contains an implementation of SONiC Chassis API
#
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

class Chassis(PddfChassis):
"""
PDDF Platform-specific Chassis class
"""

def __init__(self, pddf_data=None, pddf_plugin_data=None):
PddfChassis.__init__(self, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0}
def get_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
change_dict = {}
change_dict['sfp'] = port_dict

if timeout < 1000:
timeout = 1000
timeout = timeout / float(1000) # Convert to secs

if now < (self.sfp_change_event_data['last'] + timeout) and self.sfp_change_event_data['valid']:
return True, change_dict

bitmap = 0
for i in range(54):
modpres = self.get_sfp(i).get_presence()
if modpres:
bitmap = bitmap | (1 << i)

changed_ports = self.sfp_change_event_data['present'] ^ bitmap
if changed_ports:
for i in range(54):
if (changed_ports & (1 << i)):
if (bitmap & (1 << i)) == 0:
port_dict[i+1] = '0'
else:
port_dict[i+1] = '1'


# Update teh cache dict
self.sfp_change_event_data['present'] = bitmap
self.sfp_change_event_data['last'] = now
self.sfp_change_event_data['valid'] = 1
return True, change_dict
else:
return True, change_dict


def get_sfp(self, index):
"""
Retrieves sfp represented by (1-based) index <index>
Args:
index: An integer, the index (1-based) of the sfp to retrieve.
The index should be the sequence of a physical port in a chassis,
starting from 1.
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
Returns:
An object derived from SfpBase representing the specified sfp
"""
sfp = None

try:
# The index will start from 1
sfp = self._sfp_list[index-1]
except IndexError:
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python

try:
from sonic_platform_pddf_base.pddf_eeprom import PddfEeprom
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Eeprom(PddfEeprom):

def __init__(self, pddf_data=None, pddf_plugin_data=None):
PddfEeprom.__init__(self, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python


try:
from sonic_platform_pddf_base.pddf_fan import PddfFan
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Fan(PddfFan):
"""PDDF Platform-Specific Fan class"""

def __init__(self, tray_idx, fan_idx=0, pddf_data=None, pddf_plugin_data=None, is_psu_fan=False, psu_index=0):
# idx is 0-based
PddfFan.__init__(self, tray_idx, fan_idx, pddf_data, pddf_plugin_data, is_psu_fan, psu_index)

# Provide the functions/variables below for which implementation is to be overwritten
# Since psu_fan airflow direction cant be read from sysfs, it is fixed as 'F2B' or 'intake'
def get_direction(self):
"""
Retrieves the direction of fan
Returns:
A string, either FAN_DIRECTION_INTAKE or FAN_DIRECTION_EXHAUST
depending on fan direction
"""
if self.is_psu_fan:
direction = self.FAN_DIRECTION_INTAKE

else:
idx = (self.fantray_index-1)*self.platform['num_fans_pertray'] + self.fan_index
attr = "fan" + str(idx) + "_direction"
output = self.pddf_obj.get_attr_name_output("FAN-CTRL", attr)
if not output:
return False

mode = output['mode']
val = output['status']

val = val.rstrip()
vmap = self.plugin_data['FAN']['direction'][mode]['valmap']
if val in vmap:
direction = vmap[val]
else:
direction = val

return direction

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

#############################################################################
# PDDF
# Module contains an implementation of SONiC Platform Base API and
# provides the platform information
#
#############################################################################


try:
from sonic_platform_pddf_base.pddf_platform import PddfPlatform
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Platform(PddfPlatform):
"""
PDDF Platform-Specific Platform Class
"""

def __init__(self):
PddfPlatform.__init__(self)

# Provide the functions/variables below for which implementation is to be overwritten
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
#


try:
from sonic_platform_pddf_base.pddf_psu import PddfPsu
except ImportError as e:
raise ImportError (str(e) + "- required module not found")


class Psu(PddfPsu):
"""PDDF Platform-Specific PSU class"""

PLATFORM_PSU_CAPACITY = 1200

def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
PddfPsu.__init__(self, index, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
def get_maximum_supplied_power(self):
"""
Retrieves the maximum supplied power by PSU (or PSU capacity)
Returns:
A float number, the maximum power output in Watts.
e.g. 1200.1
"""
return float(self.PLATFORM_PSU_CAPACITY)

def get_capacity(self):
"""
Gets the capacity (maximum output power) of the PSU in watts
Returns:
An integer, the capacity of PSU
"""
return (self.PLATFORM_PSU_CAPACITY)

def get_type(self):
"""
Gets the type of the PSU
Returns:
A string, the type of PSU (AC/DC)
"""
return "AC"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python

try:
from sonic_platform_pddf_base.pddf_sfp import PddfSfp
except ImportError as e:
raise ImportError (str(e) + "- required module not found")


class Sfp(PddfSfp):
"""
PDDF Platform-Specific Sfp class
"""

def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
PddfSfp.__init__(self, index, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python


try:
from sonic_platform_pddf_base.pddf_thermal import PddfThermal
except ImportError as e:
raise ImportError(str(e) + "- required module not found")



class Thermal(PddfThermal):
"""PDDF Platform-Specific Thermal class"""

def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
PddfThermal.__init__(self, index, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python

#############################################################################
#
# Module contains an implementation of platform specific watchdog API's
#
#############################################################################

try:
from sonic_platform_pddf_base.pddf_watchdog import PddfWatchdog
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

class Watchdog(PddfWatchdog):
"""
PDDF Platform-specific Chassis class
"""

def __init__(self):
PddfWatchdog.__init__(self)
self.timeout= 180

# Provide the functions/variables below for which implementation is to be overwritten

0 comments on commit a8e7457

Please sign in to comment.