-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mellanox] Implement PSU APIs based on the new platform API #2460
Merged
+137
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,7 @@ | ||
# SONIC_PLATFORM_API_PY2 package | ||
|
||
SONIC_PLATFORM_API_PY2 = mlnx_platform_api-1.0-py2-none-any.whl | ||
$(SONIC_PLATFORM_API_PY2)_SRC_PATH = $(PLATFORM_PATH)/mlnx-platform-api | ||
$(SONIC_PLATFORM_API_PY2)_PYTHON_VERSION = 2 | ||
SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2) | ||
|
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,30 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='mlnx-platform-api', | ||
version='1.0', | ||
description='SONiC platform API implementation on Mellanox platform', | ||
license='Apache 2.0', | ||
author='SONiC Team', | ||
author_email='[email protected]', | ||
url='https://github.com/Azure/sonic-buildimage', | ||
maintainer='Kevin Wang', | ||
maintainer_email='[email protected]', | ||
packages=[ | ||
'sonic_platform_api', | ||
], | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Environment :: Plugins', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: Information Technology', | ||
'Intended Audience :: System Administrators', | ||
'License :: OSI Approved :: Apache Software License', | ||
'Natural Language :: English', | ||
'Operating System :: POSIX :: Linux', | ||
'Programming Language :: Python :: 2.7', | ||
'Topic :: Utilities', | ||
], | ||
keywords='sonic SONiC platform-api PLATFORM-API', | ||
) | ||
|
Empty file.
28 changes: 28 additions & 0 deletions
28
platform/mellanox/mlnx-platform-api/sonic_platform_api/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,28 @@ | ||
#!/usr/bin/env python | ||
|
||
############################################################################# | ||
# Mellanox | ||
# | ||
# Module contains an implementation of SONiC Platform Base API and | ||
# provides the Chassis information which are available in the platform | ||
# | ||
############################################################################# | ||
|
||
import sys | ||
|
||
try: | ||
from sonic_platform_base.chassis_base import ChassisBase | ||
from sonic_platform_api.psu import Psu | ||
except ImportError as e: | ||
raise ImportError (str(e) + "- required module not found") | ||
|
||
MLNX_NUM_PSU = 2 | ||
|
||
class Chassis(ChassisBase): | ||
"""Platform-specific Chassis class""" | ||
def __init__(self): | ||
ChassisBase.__init__(self) | ||
for index in range(MLNX_NUM_PSU): | ||
psu = Psu(index) | ||
self._psu_list.append(psu) | ||
|
70 changes: 70 additions & 0 deletions
70
platform/mellanox/mlnx-platform-api/sonic_platform_api/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,70 @@ | ||
#!/usr/bin/env python | ||
|
||
############################################################################# | ||
# Mellanox | ||
# | ||
# Module contains an implementation of SONiC Platform Base API and | ||
# provides the PSUs status which are available in the platform | ||
# | ||
############################################################################# | ||
|
||
import os.path | ||
|
||
try: | ||
from sonic_platform_base.psu_base import PsuBase | ||
except ImportError as e: | ||
raise ImportError (str(e) + "- required module not found") | ||
|
||
psu_list = [] | ||
|
||
class Psu(PsuBase): | ||
"""Platform-specific Psu class""" | ||
def __init__(self, psu_index): | ||
global psu_list | ||
PsuBase.__init__(self) | ||
# PSU is 1-based on Mellanox platform | ||
self.index = psu_index + 1 | ||
psu_list.append(psu_index) | ||
self.psu_path = "/var/run/hw-management/thermal/" | ||
self.psu_oper_status = "psu{}_pwr_status".format(self.index) | ||
self.psu_presence = "psu{}_status".format(self.index) | ||
if os.path.exists(os.path.join(self.psu_path, self.psu_presence)): | ||
self.presence_file_exists = True | ||
else: | ||
self.presence_file_exists = False | ||
|
||
def get_status(self): | ||
""" | ||
Retrieves the operational status of power supply unit (PSU) defined | ||
Returns: | ||
bool: True if PSU is operating properly, False if not | ||
""" | ||
status = 0 | ||
try: | ||
with open(os.path.join(self.psu_path, self.psu_oper_status), 'r') as power_status: | ||
status = int(power_status.read()) | ||
except (ValueError, IOError): | ||
status = 0 | ||
|
||
return status == 1 | ||
|
||
def get_presence(self): | ||
""" | ||
Retrieves the presence status of power supply unit (PSU) defined | ||
Returns: | ||
bool: True if PSU is present, False if not | ||
""" | ||
status = 0 | ||
if self.presence_file_exists: | ||
try: | ||
with open(os.path.join(self.psu_path, self.psu_presence), 'r') as presence_status: | ||
status = int(presence_status.read()) | ||
except (ValueError, IOError): | ||
status = 0 | ||
else: | ||
status = self.index in psu_list | ||
|
||
return status == 1 | ||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the thought here is that each platform vendor can name their Python wheel anything they like as long as it installs a package called "sonic_platform", correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, correct. Rename the name to "sonic_platform_api" as there is already a python package named "sonic_platform".