Skip to content

Commit b89eb6d

Browse files
committed
[mellanox] Implement PSU related APIs based on the new platform API
* Implement part of PSU related APIs including get_status(), get_presence() Signed-off-by: Kevin Wang <[email protected]>
1 parent 178764e commit b89eb6d

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SONIC_PLATFORM_API_PY2 package
2+
3+
SONIC_PLATFORM_API_PY2 = mlnx_platform_api-1.0-py2-none-any.whl
4+
$(SONIC_PLATFORM_API_PY2)_SRC_PATH = $(PLATFORM_PATH)/mlnx-platform-api
5+
$(SONIC_PLATFORM_API_PY2)_PYTHON_VERSION = 2
6+
SONIC_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='mlnx-platform-api',
5+
version='1.0',
6+
description='SONiC platform API implementation on Mellanox platform',
7+
license='Apache 2.0',
8+
author='SONiC Team',
9+
author_email='[email protected]',
10+
url='https://github.com/Azure/sonic-buildimage',
11+
maintainer='Kevin Wang',
12+
maintainer_email='[email protected]',
13+
packages=[
14+
'sonic_platform_api',
15+
],
16+
classifiers=[
17+
'Development Status :: 3 - Alpha',
18+
'Environment :: Plugins',
19+
'Intended Audience :: Developers',
20+
'Intended Audience :: Information Technology',
21+
'Intended Audience :: System Administrators',
22+
'License :: OSI Approved :: Apache Software License',
23+
'Natural Language :: English',
24+
'Operating System :: POSIX :: Linux',
25+
'Programming Language :: Python :: 2.7',
26+
'Topic :: Utilities',
27+
],
28+
keywords='sonic SONiC platform-api PLATFORM-API',
29+
)
30+

platform/mellanox/mlnx-platform-api/sonic_platform_api/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
#############################################################################
4+
# Mellanox
5+
#
6+
# Module contains an implementation of SONiC Platform Base API and
7+
# provides the Chassis information which are available in the platform
8+
#
9+
#############################################################################
10+
11+
import sys
12+
13+
try:
14+
from sonic_platform_base.chassis_base import ChassisBase
15+
from sonic_platform_api.psu import Psu
16+
except ImportError as e:
17+
raise ImportError (str(e) + "- required module not found")
18+
19+
MLNX_NUM_PSU = 2
20+
21+
class Chassis(ChassisBase):
22+
"""Platform-specific Chassis class"""
23+
def __init__(self):
24+
ChassisBase.__init__(self)
25+
for index in range(MLNX_NUM_PSU):
26+
psu = Psu(index)
27+
self._psu_list.append(psu)
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python
2+
3+
#############################################################################
4+
# Mellanox
5+
#
6+
# Module contains an implementation of SONiC Platform Base API and
7+
# provides the PSUs status which are available in the platform
8+
#
9+
#############################################################################
10+
11+
import os.path
12+
13+
try:
14+
from sonic_platform_base.psu_base import PsuBase
15+
except ImportError as e:
16+
raise ImportError (str(e) + "- required module not found")
17+
18+
psu_list = []
19+
20+
class Psu(PsuBase):
21+
"""Platform-specific Psu class"""
22+
def __init__(self, psu_index):
23+
global psu_list
24+
PsuBase.__init__(self)
25+
# PSU is 1-based on Mellanox platform
26+
self.index = psu_index + 1
27+
psu_list.append(psu_index)
28+
self.psu_path = "/var/run/hw-management/thermal/"
29+
self.psu_oper_status = "psu{}_pwr_status".format(self.index)
30+
self.psu_presence = "psu{}_status".format(self.index)
31+
if os.path.exists(os.path.join(self.psu_path, self.psu_presence)):
32+
self.presence_file_exists = True
33+
else:
34+
self.presence_file_exists = False
35+
36+
def get_status(self):
37+
"""
38+
Retrieves the operational status of power supply unit (PSU) defined
39+
40+
Returns:
41+
bool: True if PSU is operating properly, False if not
42+
"""
43+
status = 0
44+
try:
45+
with open(os.path.join(self.psu_path, self.psu_oper_status), 'r') as power_status:
46+
status = int(power_status.read())
47+
except (ValueError, IOError):
48+
status = 0
49+
50+
return status == 1
51+
52+
def get_presence(self):
53+
"""
54+
Retrieves the presence status of power supply unit (PSU) defined
55+
56+
Returns:
57+
bool: True if PSU is present, False if not
58+
"""
59+
status = 0
60+
if self.presence_file_exists:
61+
try:
62+
with open(os.path.join(self.psu_path, self.psu_presence), 'r') as presence_status:
63+
status = int(presence_status.read())
64+
except (ValueError, IOError):
65+
status = 0
66+
else:
67+
status = self.index in psu_list
68+
69+
return status == 1
70+

platform/mellanox/rules.mk

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ include $(PLATFORM_PATH)/fw.mk
33
include $(PLATFORM_PATH)/mft.mk
44
include $(PLATFORM_PATH)/mlnx-sai.mk
55
include $(PLATFORM_PATH)/hw-management.mk
6+
include $(PLATFORM_PATH)/mlnx-platform-api.mk
67
include $(PLATFORM_PATH)/docker-syncd-mlnx.mk
78
include $(PLATFORM_PATH)/docker-syncd-mlnx-rpc.mk
89
include $(PLATFORM_PATH)/docker-orchagent-mlnx.mk

rules/docker-platform-monitor.mk

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ $(DOCKER_PLATFORM_MONITOR)_PATH = $(DOCKERS_PATH)/docker-platform-monitor
55
$(DOCKER_PLATFORM_MONITOR)_DEPENDS += $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON) $(SONIC_LEDD) $(SONIC_XCVRD)
66
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_COMMON_PY2)
77
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SWSSSDK_PY2)
8+
$(DOCKER_PLATFORM_MONITOR)_PYTHON_WHEELS += $(SONIC_PLATFORM_API_PY2)
89
$(DOCKER_PLATFORM_MONITOR)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE)
910

1011
SONIC_DOCKER_IMAGES += $(DOCKER_PLATFORM_MONITOR)

0 commit comments

Comments
 (0)