-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sonic_platform and get_sfpt to chassis
- Loading branch information
Jostar Yang
committed
Jun 28, 2021
1 parent
40590f2
commit a8e7457
Showing
9 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
85 changes: 85 additions & 0 deletions
85
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/chassis.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/eeprom.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
48 changes: 48 additions & 0 deletions
48
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/fan.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
25 changes: 25 additions & 0 deletions
25
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/platform.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
44 changes: 44 additions & 0 deletions
44
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/psu.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
17 changes: 17 additions & 0 deletions
17
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/sfp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
17 changes: 17 additions & 0 deletions
17
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/thermal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
23 changes: 23 additions & 0 deletions
23
platform/broadcom/sonic-platform-modules-accton/as5835-54t/sonic_platform/watchdog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |