[Mellanox]Implement plugins for PSU, fan and thermal (#4041)
* [plugins]add fan functions, add voltage, current, power for psu * [plugins]link fanutil.py and psuutil.py to those in 2700 * [plugin]add thermal * [plugin]add symbol links for thermalutil for all SKUs
This commit is contained in:
parent
cb2edcf3df
commit
3239d7fc5b
1
device/mellanox/x86_64-mlnx_msn2010-r0/plugins/fanutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2010-r0/plugins/fanutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/fanutil.py
|
1
device/mellanox/x86_64-mlnx_msn2010-r0/plugins/thermalutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2010-r0/plugins/thermalutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/thermalutil.py
|
1
device/mellanox/x86_64-mlnx_msn2100-r0/plugins/fanutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2100-r0/plugins/fanutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/fanutil.py
|
1
device/mellanox/x86_64-mlnx_msn2100-r0/plugins/thermalutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2100-r0/plugins/thermalutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/thermalutil.py
|
1
device/mellanox/x86_64-mlnx_msn2410-r0/plugins/fanutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2410-r0/plugins/fanutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/fanutil.py
|
@ -1,74 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
#############################################################################
|
|
||||||
# Mellanox
|
|
||||||
#
|
|
||||||
# Module contains an implementation of SONiC PSU Base API and
|
|
||||||
# provides the PSUs status which are available in the platform
|
|
||||||
#
|
|
||||||
#############################################################################
|
|
||||||
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
try:
|
|
||||||
from sonic_psu.psu_base import PsuBase
|
|
||||||
except ImportError as e:
|
|
||||||
raise ImportError (str(e) + "- required module not found")
|
|
||||||
|
|
||||||
class PsuUtil(PsuBase):
|
|
||||||
"""Platform-specific PSUutil class"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
PsuBase.__init__(self)
|
|
||||||
|
|
||||||
self.psu_path = "/var/run/hw-management/thermal/"
|
|
||||||
self.psu_presence = "psu{}_status"
|
|
||||||
self.psu_oper_status = "psu{}_pwr_status"
|
|
||||||
|
|
||||||
def get_num_psus(self):
|
|
||||||
"""
|
|
||||||
Retrieves the number of PSUs available on the device
|
|
||||||
|
|
||||||
:return: An integer, the number of PSUs available on the device
|
|
||||||
"""
|
|
||||||
return 2
|
|
||||||
|
|
||||||
def get_psu_status(self, index):
|
|
||||||
"""
|
|
||||||
Retrieves the oprational status of power supply unit (PSU) defined
|
|
||||||
by 1-based index <index>
|
|
||||||
|
|
||||||
:param index: An integer, 1-based index of the PSU of which to query status
|
|
||||||
:return: Boolean, True if PSU is operating properly, False if PSU is faulty
|
|
||||||
"""
|
|
||||||
if index is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
status = 0
|
|
||||||
try:
|
|
||||||
with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status:
|
|
||||||
status = int(power_status.read())
|
|
||||||
except IOError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return status == 1
|
|
||||||
|
|
||||||
def get_psu_presence(self, index):
|
|
||||||
"""
|
|
||||||
Retrieves the presence status of power supply unit (PSU) defined
|
|
||||||
by 1-based index <index>
|
|
||||||
|
|
||||||
:param index: An integer, 1-based index of the PSU of which to query status
|
|
||||||
:return: Boolean, True if PSU is plugged, False if not
|
|
||||||
"""
|
|
||||||
if index is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
status = 0
|
|
||||||
try:
|
|
||||||
with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status:
|
|
||||||
status = int(presence_status.read())
|
|
||||||
except IOError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return status == 1
|
|
1
device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2410-r0/plugins/psuutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/psuutil.py
|
1
device/mellanox/x86_64-mlnx_msn2410-r0/plugins/thermalutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2410-r0/plugins/thermalutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/thermalutil.py
|
199
device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py
Normal file
199
device/mellanox/x86_64-mlnx_msn2700-r0/plugins/fanutil.py
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
# Mellanox
|
||||||
|
#
|
||||||
|
# Module contains an implementation of SONiC PSU Base API and
|
||||||
|
# provides the PSUs status which are available in the platform
|
||||||
|
#
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
import os.path
|
||||||
|
import syslog
|
||||||
|
import subprocess
|
||||||
|
from glob import glob
|
||||||
|
from sonic_fan.fan_base import FanBase
|
||||||
|
except ImportError as e:
|
||||||
|
raise ImportError (str(e) + "- required module not found")
|
||||||
|
|
||||||
|
def log_err(msg):
|
||||||
|
syslog.openlog("fanutil")
|
||||||
|
syslog.syslog(syslog.LOG_ERR, msg)
|
||||||
|
syslog.closelog()
|
||||||
|
|
||||||
|
class FanUtil(FanBase):
|
||||||
|
"""Platform-specific FanUtil class"""
|
||||||
|
|
||||||
|
PWM_MAX = 255
|
||||||
|
MAX_FAN_PER_DRAWER = 2
|
||||||
|
GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"
|
||||||
|
sku_without_fan_direction = ['ACS-MSN2010', 'ACS-MSN2100', 'ACS-MSN2410', 'ACS-MSN2700', 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740']
|
||||||
|
sku_with_unpluggable_fan = ['ACS-MSN2010', 'ACS-MSN2100']
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
FanBase.__init__(self)
|
||||||
|
|
||||||
|
self.sku_name = self._get_sku_name()
|
||||||
|
|
||||||
|
self.fan_path = "/var/run/hw-management/"
|
||||||
|
if self.sku_name in self.sku_with_unpluggable_fan:
|
||||||
|
self.fan_status = None
|
||||||
|
self.unpluggable_fan = True
|
||||||
|
else:
|
||||||
|
self.fan_status = "thermal/fan{}_status"
|
||||||
|
self.unpluggable_fan = False
|
||||||
|
self.fan_get_speed = "thermal/fan{}_speed_get"
|
||||||
|
self.fan_set_speed = "thermal/fan{}_speed_set"
|
||||||
|
if self.sku_name in self.sku_without_fan_direction:
|
||||||
|
self.fan_direction = None
|
||||||
|
else:
|
||||||
|
self.fan_direction = "system/fan_dir"
|
||||||
|
|
||||||
|
self.fan_led_green = "led/led_fan*_green"
|
||||||
|
self.num_of_fan, self.num_of_drawer = self._extract_num_of_fans_and_fan_drawers()
|
||||||
|
|
||||||
|
def _get_sku_name(self):
|
||||||
|
p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE)
|
||||||
|
out, err = p.communicate()
|
||||||
|
return out.rstrip('\n')
|
||||||
|
|
||||||
|
def _extract_num_of_fans_and_fan_drawers(self):
|
||||||
|
# So far we don't have files representing the number of fans and drawers
|
||||||
|
# The only way to retrieve the number is to count files.
|
||||||
|
# for number of fans, we get it via couting the speed files.
|
||||||
|
# for number of draws, we get it via couting the green led files.
|
||||||
|
list_of_fan_speed = glob(self.fan_path + self.fan_get_speed.format("*"))
|
||||||
|
num_of_fan = len(list_of_fan_speed)
|
||||||
|
list_of_fan_leds = glob(self.fan_path + self.fan_led_green)
|
||||||
|
num_of_drawer = len(list_of_fan_leds)
|
||||||
|
|
||||||
|
return num_of_fan, num_of_drawer
|
||||||
|
|
||||||
|
def _convert_fan_index_to_drawer_index(self, index):
|
||||||
|
return (index + self.MAX_FAN_PER_DRAWER - 1) / self.MAX_FAN_PER_DRAWER
|
||||||
|
|
||||||
|
def _read_file(self, file_pattern, index = 0):
|
||||||
|
"""
|
||||||
|
Reads the file of the fan
|
||||||
|
|
||||||
|
:param file_pattern: The filename convention
|
||||||
|
:param index: An integer, 1-based index of the fan of which to query status
|
||||||
|
:return: int
|
||||||
|
"""
|
||||||
|
return_value = 0
|
||||||
|
try:
|
||||||
|
with open(os.path.join(self.fan_path, file_pattern.format(index)), 'r') as file_to_read:
|
||||||
|
return_value = int(file_to_read.read())
|
||||||
|
except IOError:
|
||||||
|
log_err("Read file {} failed".format(self.fan_path + file_pattern.format(index)))
|
||||||
|
return return_value
|
||||||
|
|
||||||
|
return return_value
|
||||||
|
|
||||||
|
def get_num_fans(self):
|
||||||
|
"""
|
||||||
|
Retrieves the number of FANs supported on the device
|
||||||
|
|
||||||
|
:return: An integer, the number of FANs supported on the device
|
||||||
|
"""
|
||||||
|
return self.num_of_fan
|
||||||
|
|
||||||
|
def get_status(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the operational status of FAN defined
|
||||||
|
by index 1-based <index>
|
||||||
|
|
||||||
|
:param index: An integer, 1-based index of the PSU of which to query status
|
||||||
|
:return: Boolean,
|
||||||
|
- True if FAN is running with some speed
|
||||||
|
- False if FAN has stopped running
|
||||||
|
"""
|
||||||
|
if not self.get_presence(index):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return self.get_speed(index) != 0
|
||||||
|
|
||||||
|
def get_presence(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the presence status of a FAN defined
|
||||||
|
by 1-based index <index>
|
||||||
|
|
||||||
|
:param index: An integer, 1-based index of the FAN of which to query status
|
||||||
|
:return: Boolean, True if FAN is plugged, False if not
|
||||||
|
"""
|
||||||
|
if index > self.num_of_fan:
|
||||||
|
raise RuntimeError("index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan))
|
||||||
|
|
||||||
|
if self.unpluggable_fan:
|
||||||
|
return True
|
||||||
|
|
||||||
|
draw_index = self._convert_fan_index_to_drawer_index(index)
|
||||||
|
presence = self._read_file(self.fan_status, draw_index)
|
||||||
|
|
||||||
|
return presence != 0
|
||||||
|
|
||||||
|
def get_direction(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the airflow direction of a FAN defined
|
||||||
|
by 1-based index <index>
|
||||||
|
|
||||||
|
:param index: An integer, 1-based index of the FAN of which to query status
|
||||||
|
:return: string, denoting FAN airflow direction
|
||||||
|
Note:
|
||||||
|
What Mellanox calls forward:
|
||||||
|
Air flows from fans side to QSFP side, for example: MSN2700-CS2F
|
||||||
|
which means intake in community
|
||||||
|
What Mellanox calls reverse:
|
||||||
|
Air flow from QSFP side to fans side, for example: MSN2700-CS2R
|
||||||
|
which means exhaust in community
|
||||||
|
According to hw-mgmt:
|
||||||
|
1 stands for forward, in other words intake
|
||||||
|
0 stands for reverse, in other words exhaust
|
||||||
|
"""
|
||||||
|
if not self.fan_direction:
|
||||||
|
return self.FAN_DIRECTION_NOT_APPLICABLE
|
||||||
|
|
||||||
|
if index > self.num_of_fan:
|
||||||
|
raise RuntimeError("index ({}) shouldn't be greater than number of fans ({})".format(index, self.num_of_fan))
|
||||||
|
|
||||||
|
drawer_index = self._convert_fan_index_to_drawer_index(index)
|
||||||
|
|
||||||
|
fan_dir_bits = self._read_file(self.fan_direction)
|
||||||
|
fan_mask = 1 << drawer_index - 1
|
||||||
|
if fan_dir_bits & fan_mask:
|
||||||
|
return self.FAN_DIRECTION_INTAKE
|
||||||
|
else:
|
||||||
|
return self.FAN_DIRECTION_EXHAUST
|
||||||
|
|
||||||
|
def get_speed(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the speed of a Front FAN in the tray in revolutions per minute defined
|
||||||
|
by 1-based index <index>
|
||||||
|
|
||||||
|
:param index: An integer, 1-based index of the FAN of which to query speed
|
||||||
|
:return: integer, denoting front FAN speed
|
||||||
|
"""
|
||||||
|
speed = self._read_file(self.fan_get_speed, index)
|
||||||
|
|
||||||
|
return speed
|
||||||
|
|
||||||
|
def set_speed(self, val):
|
||||||
|
"""
|
||||||
|
Sets the speed of all the FANs to a value denoted by the duty-cycle percentage val
|
||||||
|
|
||||||
|
:param val: An integer, <0-100> denoting FAN duty cycle percentage
|
||||||
|
:return: Boolean, True if operation is successful, False if not
|
||||||
|
"""
|
||||||
|
status = True
|
||||||
|
pwm = int(round(self.PWM_MAX*val/100.0))
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(os.path.join(self.fan_path, self.fan_set_speed.format(1)), 'w') as fan_pwm:
|
||||||
|
fan_pwm.write(str(pwm))
|
||||||
|
except (ValueError, IOError):
|
||||||
|
log_err("Read file {} failed".format(self.fan_path + self.fan_set_speed.format(1)))
|
||||||
|
status = False
|
||||||
|
|
||||||
|
return status
|
@ -8,22 +8,50 @@
|
|||||||
#
|
#
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
import os.path
|
||||||
|
import syslog
|
||||||
|
import subprocess
|
||||||
from sonic_psu.psu_base import PsuBase
|
from sonic_psu.psu_base import PsuBase
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
raise ImportError (str(e) + "- required module not found")
|
raise ImportError (str(e) + "- required module not found")
|
||||||
|
|
||||||
|
def log_err(msg):
|
||||||
|
syslog.openlog("psuutil")
|
||||||
|
syslog.syslog(syslog.LOG_ERR, msg)
|
||||||
|
syslog.closelog()
|
||||||
|
|
||||||
|
|
||||||
class PsuUtil(PsuBase):
|
class PsuUtil(PsuBase):
|
||||||
"""Platform-specific PSUutil class"""
|
"""Platform-specific PSUutil class"""
|
||||||
|
|
||||||
|
MAX_PSU_FAN = 1
|
||||||
|
MAX_NUM_PSU = 2
|
||||||
|
GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"
|
||||||
|
# for spectrum1 switches with plugable PSUs, the output voltage file is psuX_volt
|
||||||
|
# for spectrum2 switches the output voltage file is psuX_volt_out2
|
||||||
|
sku_spectrum1_with_plugable_psu = ['ACS-MSN2410', 'ACS-MSN2700', 'Mellanox-SN2700', 'Mellanox-SN2700-D48C8', 'LS-SN2700', 'ACS-MSN2740']
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
PsuBase.__init__(self)
|
PsuBase.__init__(self)
|
||||||
|
|
||||||
self.psu_path = "/var/run/hw-management/thermal/"
|
self.sku_name = self._get_sku_name()
|
||||||
self.psu_presence = "psu{}_status"
|
|
||||||
self.psu_oper_status = "psu{}_pwr_status"
|
self.psu_path = "/var/run/hw-management/"
|
||||||
|
self.psu_presence = "thermal/psu{}_status"
|
||||||
|
self.psu_oper_status = "thermal/psu{}_pwr_status"
|
||||||
|
self.psu_current = "power/psu{}_curr"
|
||||||
|
self.psu_power = "power/psu{}_power"
|
||||||
|
if self.sku_name in self.sku_spectrum1_with_plugable_psu:
|
||||||
|
self.psu_voltage = "power/psu{}_volt"
|
||||||
|
else:
|
||||||
|
self.psu_voltage = "power/psu{}_volt_out2"
|
||||||
|
self.fan_speed = "thermal/psu{}_fan1_speed_get"
|
||||||
|
|
||||||
|
def _get_sku_name(self):
|
||||||
|
p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE)
|
||||||
|
out, err = p.communicate()
|
||||||
|
return out.rstrip('\n')
|
||||||
|
|
||||||
def get_num_psus(self):
|
def get_num_psus(self):
|
||||||
"""
|
"""
|
||||||
@ -31,7 +59,25 @@ class PsuUtil(PsuBase):
|
|||||||
|
|
||||||
:return: An integer, the number of PSUs available on the device
|
:return: An integer, the number of PSUs available on the device
|
||||||
"""
|
"""
|
||||||
return 2
|
return self.MAX_NUM_PSU
|
||||||
|
|
||||||
|
def _read_file(self, file_pattern, index):
|
||||||
|
"""
|
||||||
|
Reads the file of the PSU
|
||||||
|
|
||||||
|
:param file_pattern: The filename convention
|
||||||
|
:param index: An integer, 1-based index of the PSU of which to query status
|
||||||
|
:return: int
|
||||||
|
"""
|
||||||
|
return_value = 0
|
||||||
|
try:
|
||||||
|
with open(self.psu_path + file_pattern.format(index), 'r') as file_to_read:
|
||||||
|
return_value = int(file_to_read.read())
|
||||||
|
except IOError:
|
||||||
|
log_err("Read file {} failed".format(self.psu_path + file_pattern.format(index)))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
return return_value
|
||||||
|
|
||||||
def get_psu_status(self, index):
|
def get_psu_status(self, index):
|
||||||
"""
|
"""
|
||||||
@ -43,13 +89,10 @@ class PsuUtil(PsuBase):
|
|||||||
"""
|
"""
|
||||||
if index is None:
|
if index is None:
|
||||||
return False
|
return False
|
||||||
|
if index > self.MAX_NUM_PSU:
|
||||||
|
raise RuntimeError("index ({}) shouldn't be greater than {}".format(index, self.MAX_NUM_PSU))
|
||||||
|
|
||||||
status = 0
|
status = self._read_file(self.psu_oper_status, index)
|
||||||
try:
|
|
||||||
with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status:
|
|
||||||
status = int(power_status.read())
|
|
||||||
except IOError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return status == 1
|
return status == 1
|
||||||
|
|
||||||
@ -62,13 +105,80 @@ class PsuUtil(PsuBase):
|
|||||||
:return: Boolean, True if PSU is plugged, False if not
|
:return: Boolean, True if PSU is plugged, False if not
|
||||||
"""
|
"""
|
||||||
if index is None:
|
if index is None:
|
||||||
return False
|
raise RuntimeError("index shouldn't be None")
|
||||||
|
if index > self.MAX_NUM_PSU:
|
||||||
|
raise RuntimeError("index ({}) shouldn't be greater than {}".format(index, self.MAX_NUM_PSU))
|
||||||
|
|
||||||
status = 0
|
status = self._read_file(self.psu_presence, index)
|
||||||
try:
|
|
||||||
with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status:
|
|
||||||
status = int(presence_status.read())
|
|
||||||
except IOError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return status == 1
|
return status == 1
|
||||||
|
|
||||||
|
def get_output_voltage(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the ouput volatage in milli volts of a power supply unit (PSU) defined
|
||||||
|
by 1-based index <index>
|
||||||
|
:param index: An integer, 1-based index of the PSU of which to query o/p volatge
|
||||||
|
:return: An integer, value of o/p voltage in mV if PSU is good, else zero
|
||||||
|
"""
|
||||||
|
if index is None:
|
||||||
|
raise RuntimeError("index shouldn't be None")
|
||||||
|
|
||||||
|
if not self.get_psu_presence(index) or not self.get_psu_status(index):
|
||||||
|
return 0
|
||||||
|
|
||||||
|
voltage = self._read_file(self.psu_voltage, index)
|
||||||
|
|
||||||
|
return voltage
|
||||||
|
|
||||||
|
def get_output_current(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the output current in milli amperes of a power supply unit (PSU) defined
|
||||||
|
by 1-based index <index>
|
||||||
|
:param index: An integer, 1-based index of the PSU of which to query o/p current
|
||||||
|
:return: An integer, value of o/p current in mA if PSU is good, else zero
|
||||||
|
"""
|
||||||
|
if index is None:
|
||||||
|
raise RuntimeError("index shouldn't be None")
|
||||||
|
|
||||||
|
if not self.get_psu_presence(index) or not self.get_psu_status(index):
|
||||||
|
return 0
|
||||||
|
|
||||||
|
current = self._read_file(self.psu_current, index)
|
||||||
|
|
||||||
|
return current
|
||||||
|
|
||||||
|
def get_output_power(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the output power in micro watts of a power supply unit (PSU) defined
|
||||||
|
by 1-based index <index>
|
||||||
|
:param index: An integer, 1-based index of the PSU of which to query o/p power
|
||||||
|
:return: An integer, value of o/p power in micro Watts if PSU is good, else zero
|
||||||
|
"""
|
||||||
|
if index is None:
|
||||||
|
raise RuntimeError("index shouldn't be None")
|
||||||
|
|
||||||
|
if not self.get_psu_presence(index) or not self.get_psu_status(index):
|
||||||
|
return 0
|
||||||
|
|
||||||
|
power = self._read_file(self.psu_power, index)
|
||||||
|
|
||||||
|
return power
|
||||||
|
|
||||||
|
def get_fan_speed(self, index, fan_index):
|
||||||
|
"""
|
||||||
|
Retrieves the speed of fan, in rpm, denoted by 1-based <fan_index> of a power
|
||||||
|
supply unit (PSU) defined by 1-based index <index>
|
||||||
|
:param index: An integer, 1-based index of the PSU of which to query fan speed
|
||||||
|
:param fan_index: An integer, 1-based index of the PSU-fan of which to query speed
|
||||||
|
:return: An integer, value of PSU-fan speed in rpm if PSU-fan is good, else zero
|
||||||
|
"""
|
||||||
|
if index is None:
|
||||||
|
raise RuntimeError("index shouldn't be None")
|
||||||
|
if fan_index > self.MAX_PSU_FAN:
|
||||||
|
raise RuntimeError("fan_index ({}) shouldn't be greater than {}".format(fan_index, self.MAX_PSU_FAN))
|
||||||
|
if not self.get_psu_presence(index) or not self.get_psu_status(index):
|
||||||
|
return 0
|
||||||
|
|
||||||
|
fan_speed = self._read_file(self.fan_speed, index)
|
||||||
|
|
||||||
|
return fan_speed
|
||||||
|
456
device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py
Normal file
456
device/mellanox/x86_64-mlnx_msn2700-r0/plugins/thermalutil.py
Normal file
@ -0,0 +1,456 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
# Mellanox
|
||||||
|
#
|
||||||
|
# Module contains an implementation of SONiC Thermal Base API and
|
||||||
|
# provides the thermal sensor status which are available in the platform
|
||||||
|
#
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
try:
|
||||||
|
from os.path import join
|
||||||
|
import syslog
|
||||||
|
import subprocess
|
||||||
|
from sonic_thermal.thermal_base import ThermalBase
|
||||||
|
except ImportError as e:
|
||||||
|
raise ImportError (str(e) + "- required module not found")
|
||||||
|
|
||||||
|
def log_info(msg):
|
||||||
|
syslog.openlog("thermalutil")
|
||||||
|
syslog.syslog(syslog.LOG_INFO, msg)
|
||||||
|
syslog.closelog()
|
||||||
|
|
||||||
|
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE = "cpu_core"
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK = "cpu_pack"
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE = "module"
|
||||||
|
THERMAL_DEV_CATEGORY_PSU = "psu"
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX = "gearbox"
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT = "ambient"
|
||||||
|
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT = "asic_amb"
|
||||||
|
THERMAL_DEV_FAN_AMBIENT = "fan_amb"
|
||||||
|
THERMAL_DEV_PORT_AMBIENT = "port_amb"
|
||||||
|
THERMAL_DEV_COMEX_AMBIENT = "comex_amb"
|
||||||
|
THERMAL_DEV_BOARD_AMBIENT = "board_amb"
|
||||||
|
|
||||||
|
THERMAL_API_GET_TEMPERATURE = "get_temperature"
|
||||||
|
THERMAL_API_GET_HIGH_THRESHOLD = "get_high_threshold"
|
||||||
|
THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD = "get_high_critical_threshold"
|
||||||
|
|
||||||
|
THERMAL_API_INVALID_HIGH_THRESHOLD = 0.0
|
||||||
|
|
||||||
|
HW_MGMT_THERMAL_ROOT = "/var/run/hw-management/thermal/"
|
||||||
|
|
||||||
|
thermal_api_handler_cpu_core = {
|
||||||
|
THERMAL_API_GET_TEMPERATURE:"cpu_core{}",
|
||||||
|
THERMAL_API_GET_HIGH_THRESHOLD:"cpu_core{}_max",
|
||||||
|
THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"cpu_core{}_crit"
|
||||||
|
}
|
||||||
|
thermal_api_handler_cpu_pack = {
|
||||||
|
THERMAL_API_GET_TEMPERATURE:"cpu_pack",
|
||||||
|
THERMAL_API_GET_HIGH_THRESHOLD:"cpu_pack_max",
|
||||||
|
THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"cpu_pack_crit"
|
||||||
|
}
|
||||||
|
thermal_api_handler_module = {
|
||||||
|
THERMAL_API_GET_TEMPERATURE:"module{}_temp_input",
|
||||||
|
THERMAL_API_GET_HIGH_THRESHOLD:"module{}_temp_crit",
|
||||||
|
THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:"module{}_temp_emergency"
|
||||||
|
}
|
||||||
|
thermal_api_handler_psu = {
|
||||||
|
THERMAL_API_GET_TEMPERATURE:"psu{}_temp",
|
||||||
|
THERMAL_API_GET_HIGH_THRESHOLD:"psu{}_temp_max",
|
||||||
|
THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:None
|
||||||
|
}
|
||||||
|
thermal_api_handler_gearbox = {
|
||||||
|
THERMAL_API_GET_TEMPERATURE:"gearbox{}_temp_input",
|
||||||
|
THERMAL_API_GET_HIGH_THRESHOLD:None,
|
||||||
|
THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD:None
|
||||||
|
}
|
||||||
|
thermal_ambient_apis = {
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT : "asic",
|
||||||
|
THERMAL_DEV_PORT_AMBIENT : "port_amb",
|
||||||
|
THERMAL_DEV_FAN_AMBIENT : "fan_amb",
|
||||||
|
THERMAL_DEV_COMEX_AMBIENT : "comex_amb",
|
||||||
|
THERMAL_DEV_BOARD_AMBIENT : "board_amb"
|
||||||
|
}
|
||||||
|
thermal_ambient_name = {
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT : "Ambient ASIC Temp",
|
||||||
|
THERMAL_DEV_PORT_AMBIENT : "Ambient Port Side Temp",
|
||||||
|
THERMAL_DEV_FAN_AMBIENT : "Ambient Fan Side Temp",
|
||||||
|
THERMAL_DEV_COMEX_AMBIENT : "Ambient COMEX Temp",
|
||||||
|
THERMAL_DEV_BOARD_AMBIENT : "Ambient Board Temp"
|
||||||
|
}
|
||||||
|
thermal_api_handlers = {
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE : thermal_api_handler_cpu_core,
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK : thermal_api_handler_cpu_pack,
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE : thermal_api_handler_module,
|
||||||
|
THERMAL_DEV_CATEGORY_PSU : thermal_api_handler_psu,
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX : thermal_api_handler_gearbox
|
||||||
|
}
|
||||||
|
thermal_name = {
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE : "CPU Core {} Temp",
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK : "CPU Pack Temp",
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE : "xSFP module {} Temp",
|
||||||
|
THERMAL_DEV_CATEGORY_PSU : "PSU-{} Temp",
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX : "Gearbox {} Temp"
|
||||||
|
}
|
||||||
|
|
||||||
|
thermal_device_categories_all = [
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE,
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK,
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE,
|
||||||
|
THERMAL_DEV_CATEGORY_PSU,
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT,
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX
|
||||||
|
]
|
||||||
|
|
||||||
|
thermal_device_categories_singleton = [
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK,
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT
|
||||||
|
]
|
||||||
|
thermal_api_names = [
|
||||||
|
THERMAL_API_GET_TEMPERATURE,
|
||||||
|
THERMAL_API_GET_HIGH_THRESHOLD
|
||||||
|
]
|
||||||
|
|
||||||
|
hwsku_dict_thermal = {'ACS-MSN2700': 0, 'LS-SN2700':0, 'ACS-MSN2740': 3, 'ACS-MSN2100': 1, 'ACS-MSN2410': 2, 'ACS-MSN2010': 4, 'ACS-MSN3700': 5, 'ACS-MSN3700C': 6, 'Mellanox-SN2700': 0, 'Mellanox-SN2700-D48C8': 0, 'ACS-MSN3800': 7, 'Mellanox-SN3800-D112C8': 7}
|
||||||
|
thermal_profile_list = [
|
||||||
|
# 2700
|
||||||
|
{
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE:(1, 32),
|
||||||
|
THERMAL_DEV_CATEGORY_PSU:(1, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK:(0,1),
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT:(0,
|
||||||
|
[
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT,
|
||||||
|
THERMAL_DEV_PORT_AMBIENT,
|
||||||
|
THERMAL_DEV_FAN_AMBIENT
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
# 2100
|
||||||
|
{
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4),
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE:(1, 16),
|
||||||
|
THERMAL_DEV_CATEGORY_PSU:(0, 0),
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT:(0,
|
||||||
|
[
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT,
|
||||||
|
THERMAL_DEV_PORT_AMBIENT,
|
||||||
|
THERMAL_DEV_FAN_AMBIENT,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
# 2410
|
||||||
|
{
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE:(1, 56),
|
||||||
|
THERMAL_DEV_CATEGORY_PSU:(1, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK:(0,1),
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT:(0,
|
||||||
|
[
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT,
|
||||||
|
THERMAL_DEV_PORT_AMBIENT,
|
||||||
|
THERMAL_DEV_FAN_AMBIENT,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
# 2740
|
||||||
|
{
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4),
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE:(1, 32),
|
||||||
|
THERMAL_DEV_CATEGORY_PSU:(1, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT:(0,
|
||||||
|
[
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT,
|
||||||
|
THERMAL_DEV_PORT_AMBIENT,
|
||||||
|
THERMAL_DEV_FAN_AMBIENT,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
# 2010
|
||||||
|
{
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4),
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE:(1, 22),
|
||||||
|
THERMAL_DEV_CATEGORY_PSU:(0, 0),
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT:(0,
|
||||||
|
[
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT,
|
||||||
|
THERMAL_DEV_PORT_AMBIENT,
|
||||||
|
THERMAL_DEV_FAN_AMBIENT,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
# 3700
|
||||||
|
{
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4),
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE:(1, 32),
|
||||||
|
THERMAL_DEV_CATEGORY_PSU:(1, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK:(0,1),
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT:(0,
|
||||||
|
[
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT,
|
||||||
|
THERMAL_DEV_COMEX_AMBIENT,
|
||||||
|
THERMAL_DEV_PORT_AMBIENT,
|
||||||
|
THERMAL_DEV_FAN_AMBIENT
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
# 3700c
|
||||||
|
{
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE:(0, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE:(1, 32),
|
||||||
|
THERMAL_DEV_CATEGORY_PSU:(1, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK:(0,1),
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX:(0,0),
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT:(0,
|
||||||
|
[
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT,
|
||||||
|
THERMAL_DEV_COMEX_AMBIENT,
|
||||||
|
THERMAL_DEV_PORT_AMBIENT,
|
||||||
|
THERMAL_DEV_FAN_AMBIENT
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
# 3800
|
||||||
|
{
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_CORE:(0, 4),
|
||||||
|
THERMAL_DEV_CATEGORY_MODULE:(1, 64),
|
||||||
|
THERMAL_DEV_CATEGORY_PSU:(1, 2),
|
||||||
|
THERMAL_DEV_CATEGORY_CPU_PACK:(0,1),
|
||||||
|
THERMAL_DEV_CATEGORY_GEARBOX:(1,32),
|
||||||
|
THERMAL_DEV_CATEGORY_AMBIENT:(0,
|
||||||
|
[
|
||||||
|
THERMAL_DEV_ASIC_AMBIENT,
|
||||||
|
THERMAL_DEV_COMEX_AMBIENT,
|
||||||
|
THERMAL_DEV_PORT_AMBIENT,
|
||||||
|
THERMAL_DEV_FAN_AMBIENT
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Thermal(object):
|
||||||
|
def __init__(self, category, index, has_index):
|
||||||
|
"""
|
||||||
|
index should be a string for category ambient and int for other categories
|
||||||
|
"""
|
||||||
|
if category == THERMAL_DEV_CATEGORY_AMBIENT:
|
||||||
|
self.name = thermal_ambient_name[index]
|
||||||
|
self.index = index
|
||||||
|
elif has_index:
|
||||||
|
self.name = thermal_name[category].format(index)
|
||||||
|
self.index = index
|
||||||
|
else:
|
||||||
|
self.name = thermal_name[category]
|
||||||
|
self.index = 0
|
||||||
|
|
||||||
|
self.category = category
|
||||||
|
self.temperature = self._get_file_from_api(THERMAL_API_GET_TEMPERATURE)
|
||||||
|
self.high_threshold = self._get_file_from_api(THERMAL_API_GET_HIGH_THRESHOLD)
|
||||||
|
self.high_critical_threshold = self._get_file_from_api(THERMAL_API_GET_HIGH_CRITICAL_THRESHOLD)
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
"""
|
||||||
|
Retrieves the name of the device
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
string: The name of the device
|
||||||
|
"""
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def _read_generic_file(self, filename, len):
|
||||||
|
"""
|
||||||
|
Read a generic file, returns the contents of the file
|
||||||
|
"""
|
||||||
|
result = None
|
||||||
|
try:
|
||||||
|
with open(filename, 'r') as fileobj:
|
||||||
|
result = fileobj.read()
|
||||||
|
except Exception as e:
|
||||||
|
log_info("Fail to read file {} due to {}".format(filename, repr(e)))
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _get_file_from_api(self, api_name):
|
||||||
|
if self.category == THERMAL_DEV_CATEGORY_AMBIENT:
|
||||||
|
if api_name == THERMAL_API_GET_TEMPERATURE:
|
||||||
|
filename = thermal_ambient_apis[self.index]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
handler = thermal_api_handlers[self.category][api_name]
|
||||||
|
if self.category in thermal_device_categories_singleton:
|
||||||
|
filename = handler
|
||||||
|
else:
|
||||||
|
if handler:
|
||||||
|
filename = handler.format(self.index)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
return join(HW_MGMT_THERMAL_ROOT, filename)
|
||||||
|
|
||||||
|
def get_temperature(self):
|
||||||
|
"""
|
||||||
|
Retrieves current temperature reading from thermal
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A float number of current temperature in Celsius up to nearest thousandth
|
||||||
|
of one degree Celsius, e.g. 30.125
|
||||||
|
"""
|
||||||
|
value_str = self._read_generic_file(self.temperature, 0)
|
||||||
|
if value_str is None:
|
||||||
|
return None
|
||||||
|
value_float = float(value_str)
|
||||||
|
if self.category == THERMAL_DEV_CATEGORY_MODULE and value_float == THERMAL_API_INVALID_HIGH_THRESHOLD:
|
||||||
|
return None
|
||||||
|
return value_float / 1000.0
|
||||||
|
|
||||||
|
def get_high_threshold(self):
|
||||||
|
"""
|
||||||
|
Retrieves the high threshold temperature of thermal
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A float number, the high threshold temperature of thermal in Celsius
|
||||||
|
up to nearest thousandth of one degree Celsius, e.g. 30.125
|
||||||
|
"""
|
||||||
|
if self.high_threshold is None:
|
||||||
|
return None
|
||||||
|
value_str = self._read_generic_file(self.high_threshold, 0)
|
||||||
|
if value_str is None:
|
||||||
|
return None
|
||||||
|
value_float = float(value_str)
|
||||||
|
if self.category == THERMAL_DEV_CATEGORY_MODULE and value_float == THERMAL_API_INVALID_HIGH_THRESHOLD:
|
||||||
|
return None
|
||||||
|
return value_float / 1000.0
|
||||||
|
|
||||||
|
def get_high_critical_threshold(self):
|
||||||
|
"""
|
||||||
|
Retrieves the high critical threshold temperature of thermal
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A float number, the high critical threshold temperature of thermal in Celsius
|
||||||
|
up to nearest thousandth of one degree Celsius, e.g. 30.125
|
||||||
|
"""
|
||||||
|
if self.high_critical_threshold is None:
|
||||||
|
return None
|
||||||
|
value_str = self._read_generic_file(self.high_critical_threshold, 0)
|
||||||
|
if value_str is None:
|
||||||
|
return None
|
||||||
|
value_float = float(value_str)
|
||||||
|
if self.category == THERMAL_DEV_CATEGORY_MODULE and value_float == THERMAL_API_INVALID_HIGH_THRESHOLD:
|
||||||
|
return None
|
||||||
|
return value_float / 1000.0
|
||||||
|
|
||||||
|
|
||||||
|
class ThermalUtil(ThermalBase):
|
||||||
|
"""Platform-specific Thermalutil class"""
|
||||||
|
|
||||||
|
MAX_PSU_FAN = 1
|
||||||
|
MAX_NUM_PSU = 2
|
||||||
|
GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"
|
||||||
|
number_of_thermals = 0
|
||||||
|
thermal_list = []
|
||||||
|
|
||||||
|
def _get_sku_name(self):
|
||||||
|
p = subprocess.Popen(self.GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE)
|
||||||
|
out, err = p.communicate()
|
||||||
|
return out.rstrip('\n')
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
sku = self._get_sku_name()
|
||||||
|
# create thermal objects for all categories of sensors
|
||||||
|
tp_index = hwsku_dict_thermal[sku]
|
||||||
|
thermal_profile = thermal_profile_list[tp_index]
|
||||||
|
for category in thermal_device_categories_all:
|
||||||
|
if category == THERMAL_DEV_CATEGORY_AMBIENT:
|
||||||
|
count, ambient_list = thermal_profile[category]
|
||||||
|
for ambient in ambient_list:
|
||||||
|
thermal = Thermal(category, ambient, True)
|
||||||
|
self.thermal_list.append(thermal)
|
||||||
|
else:
|
||||||
|
start, count = 0, 0
|
||||||
|
if category in thermal_profile:
|
||||||
|
start, count = thermal_profile[category]
|
||||||
|
if count == 0:
|
||||||
|
continue
|
||||||
|
if count == 1:
|
||||||
|
thermal = Thermal(category, 0, False)
|
||||||
|
self.thermal_list.append(thermal)
|
||||||
|
else:
|
||||||
|
for index in range(count):
|
||||||
|
thermal = Thermal(category, start + index, True)
|
||||||
|
self.thermal_list.append(thermal)
|
||||||
|
self.number_of_thermals = len(self.thermal_list)
|
||||||
|
|
||||||
|
def get_num_thermals(self):
|
||||||
|
"""
|
||||||
|
Retrieves the number of thermal sensors supported on the device
|
||||||
|
|
||||||
|
:return: An integer, the number of thermal sensors supported on the device
|
||||||
|
"""
|
||||||
|
return self.number_of_thermals
|
||||||
|
|
||||||
|
def get_name(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the human-readable name of a thermal sensor by 1-based index
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
:param index: An integer, 1-based index of the thermal sensor of which to query status
|
||||||
|
:return: String,
|
||||||
|
A string representing the name of the thermal sensor.
|
||||||
|
"""
|
||||||
|
if index >= self.number_of_thermals:
|
||||||
|
raise RuntimeError("index ({}) shouldn't be greater than {}".format(index, self.number_of_thermals))
|
||||||
|
return self.thermal_list[index].get_name()
|
||||||
|
|
||||||
|
def get_temperature(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves current temperature reading from thermal sensor by 1-based index
|
||||||
|
|
||||||
|
:param index: An integer, 1-based index of the thermal sensor of which to query status
|
||||||
|
:return: Float,
|
||||||
|
A float number of current temperature in Celsius up to nearest thousandth
|
||||||
|
of one degree Celsius, e.g. 30.125
|
||||||
|
"""
|
||||||
|
if index >= self.number_of_thermals:
|
||||||
|
raise RuntimeError("index ({}) shouldn't be greater than {}".format(index, self.number_of_thermals))
|
||||||
|
return self.thermal_list[index].get_temperature()
|
||||||
|
|
||||||
|
def get_high_threshold(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the high threshold temperature of thermal by 1-based index
|
||||||
|
Actions should be taken if the temperature becomes higher than the threshold.
|
||||||
|
|
||||||
|
:param index: An integer, 1-based index of the thermal sensor of which to query status
|
||||||
|
:return: A float number, the high threshold temperature of thermal in Celsius
|
||||||
|
up to nearest thousandth of one degree Celsius, e.g. 30.125
|
||||||
|
"""
|
||||||
|
if index >= self.number_of_thermals:
|
||||||
|
raise RuntimeError("index ({}) shouldn't be greater than {}".format(index, self.number_of_thermals))
|
||||||
|
return self.thermal_list[index].get_high_threshold()
|
||||||
|
|
||||||
|
def get_high_critical_threshold(self, index):
|
||||||
|
"""
|
||||||
|
Retrieves the high critical threshold temperature of thermal by 1-based index
|
||||||
|
Actions should be taken immediately if the temperature becomes higher than the high critical
|
||||||
|
threshold otherwise the device will be damaged.
|
||||||
|
|
||||||
|
:param index: An integer, 1-based index of the thermal sensor of which to query status
|
||||||
|
:return: A float number, the high critical threshold temperature of thermal in Celsius
|
||||||
|
up to nearest thousandth of one degree Celsius, e.g. 30.125
|
||||||
|
"""
|
||||||
|
if index >= self.number_of_thermals:
|
||||||
|
raise RuntimeError("index ({}) shouldn't be greater than {}".format(index, self.number_of_thermals))
|
||||||
|
return self.thermal_list[index].get_high_critical_threshold()
|
1
device/mellanox/x86_64-mlnx_msn2740-r0/plugins/fanutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2740-r0/plugins/fanutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/fanutil.py
|
@ -1,74 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
#############################################################################
|
|
||||||
# Mellanox
|
|
||||||
#
|
|
||||||
# Module contains an implementation of SONiC PSU Base API and
|
|
||||||
# provides the PSUs status which are available in the platform
|
|
||||||
#
|
|
||||||
#############################################################################
|
|
||||||
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
try:
|
|
||||||
from sonic_psu.psu_base import PsuBase
|
|
||||||
except ImportError as e:
|
|
||||||
raise ImportError (str(e) + "- required module not found")
|
|
||||||
|
|
||||||
class PsuUtil(PsuBase):
|
|
||||||
"""Platform-specific PSUutil class"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
PsuBase.__init__(self)
|
|
||||||
|
|
||||||
self.psu_path = "/var/run/hw-management/thermal/"
|
|
||||||
self.psu_presence = "psu{}_status"
|
|
||||||
self.psu_oper_status = "psu{}_pwr_status"
|
|
||||||
|
|
||||||
def get_num_psus(self):
|
|
||||||
"""
|
|
||||||
Retrieves the number of PSUs available on the device
|
|
||||||
|
|
||||||
:return: An integer, the number of PSUs available on the device
|
|
||||||
"""
|
|
||||||
return 2
|
|
||||||
|
|
||||||
def get_psu_status(self, index):
|
|
||||||
"""
|
|
||||||
Retrieves the oprational status of power supply unit (PSU) defined
|
|
||||||
by 1-based index <index>
|
|
||||||
|
|
||||||
:param index: An integer, 1-based index of the PSU of which to query status
|
|
||||||
:return: Boolean, True if PSU is operating properly, False if PSU is faulty
|
|
||||||
"""
|
|
||||||
if index is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
status = 0
|
|
||||||
try:
|
|
||||||
with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status:
|
|
||||||
status = int(power_status.read())
|
|
||||||
except IOError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return status == 1
|
|
||||||
|
|
||||||
def get_psu_presence(self, index):
|
|
||||||
"""
|
|
||||||
Retrieves the presence status of power supply unit (PSU) defined
|
|
||||||
by 1-based index <index>
|
|
||||||
|
|
||||||
:param index: An integer, 1-based index of the PSU of which to query status
|
|
||||||
:return: Boolean, True if PSU is plugged, False if not
|
|
||||||
"""
|
|
||||||
if index is None:
|
|
||||||
return False
|
|
||||||
|
|
||||||
status = 0
|
|
||||||
try:
|
|
||||||
with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status:
|
|
||||||
status = int(presence_status.read())
|
|
||||||
except IOError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return status == 1
|
|
1
device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2740-r0/plugins/psuutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/psuutil.py
|
1
device/mellanox/x86_64-mlnx_msn2740-r0/plugins/thermalutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn2740-r0/plugins/thermalutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/thermalutil.py
|
1
device/mellanox/x86_64-mlnx_msn3700-r0/plugins/fanutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn3700-r0/plugins/fanutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/fanutil.py
|
1
device/mellanox/x86_64-mlnx_msn3700c-r0/plugins/fanutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn3700c-r0/plugins/fanutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/fanutil.py
|
1
device/mellanox/x86_64-mlnx_msn3700c-r0/plugins/thermalutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn3700c-r0/plugins/thermalutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/thermalutil.py
|
1
device/mellanox/x86_64-mlnx_msn3800-r0/plugins/fanutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn3800-r0/plugins/fanutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/fanutil.py
|
1
device/mellanox/x86_64-mlnx_msn3800-r0/plugins/thermalutil.py
Symbolic link
1
device/mellanox/x86_64-mlnx_msn3800-r0/plugins/thermalutil.py
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../x86_64-mlnx_msn2700-r0/plugins/thermalutil.py
|
Loading…
Reference in New Issue
Block a user