7f4ab8fbd8
Submodule updates include the following commits: * src/sonic-utilities 9dc58ea...f9eb739 (18): > Remove unnecessary calls to str.encode() now that the package is Python 3; Fix deprecation warning (#1260) > [generate_dump] Ignoring file/directory not found Errors (#1201) > Fixed porstat rate and util issues (#1140) > fix error: interface counters is mismatch after warm-reboot (#1099) > Remove unnecessary calls to str.decode() now that the package is Python 3 (#1255) > [acl-loader] Make list sorting compliant with Python 3 (#1257) > Replace hard-coded fast-reboot with variable. And some typo corrections (#1254) > [configlet][portconfig] Remove calls to dict.has_key() which is not available in Python 3 (#1247) > Remove unnecessary conversions to list() and calls to dict.keys() (#1243) > Clean up LGTM alerts (#1239) > Add 'requests' as install dependency in setup.py (#1240) > Convert to Python 3 (#1128) > Fix mock SonicV2Connector in python3: use decode_responses mode so caller code will be the same as python2 (#1238) > [tests] Do not trim from PATH if we did not append to it; Clean up/fix shebangs in scripts (#1233) > Updates to bgp config and show commands with BGP_INTERNAL_NEIGHBOR table (#1224) > [cli]: NAT show commands newline issue after migrated to Python3 (#1204) > [doc]: Update Command-Reference.md (#1231) > Added 'import sys' in feature.py file (#1232) * src/sonic-py-swsssdk 9d9f0c6...1664be9 (2): > Fix: no need to decode() after redis client scan, so it will work for both python2 and python3 (#96) > FieldValueMap `contains`(`in`) will also work when migrated to libswsscommon(C++ with SWIG wrapper) (#94) - Also fix Python 3-related issues: - Use integer (floor) division in config_samples.py (sonic-config-engine) - Replace print statement with print function in eeprom.py plugin for x86_64-kvm_x86_64-r0 platform - Update all platform plugins to be compatible with both Python 2 and Python 3 - Remove shebangs from plugins files which are not intended to be executable - Replace tabs with spaces in Python plugin files and fix alignment, because Python 3 is more strict - Remove trailing whitespace from plugins files
153 lines
5.5 KiB
Python
153 lines
5.5 KiB
Python
#############################################################################
|
|
# Celestica
|
|
#
|
|
# Thermal contains an implementation of SONiC Platform Base API and
|
|
# provides the thermal device status which are available in the platform
|
|
#
|
|
#############################################################################
|
|
|
|
import os
|
|
import re
|
|
import os.path
|
|
|
|
try:
|
|
from sonic_platform_base.thermal_base import ThermalBase
|
|
from .helper import APIHelper
|
|
except ImportError as e:
|
|
raise ImportError(str(e) + "- required module not found")
|
|
|
|
IPMI_SENSOR_NETFN = "0x04"
|
|
IPMI_SS_READ_CMD = "0x2D {}"
|
|
IPMI_SS_THRESHOLD_CMD = "0x27 {}"
|
|
DEFUALT_LOWER_TRESHOLD = 0.0
|
|
HIGH_TRESHOLD_SET_KEY = "unc"
|
|
|
|
|
|
class Thermal(ThermalBase):
|
|
"""Platform-specific Thermal class"""
|
|
|
|
def __init__(self, thermal_index):
|
|
ThermalBase.__init__(self)
|
|
self._api_helper = APIHelper()
|
|
self.index = thermal_index
|
|
self.THERMAL_LIST = [
|
|
('TEMP_FAN_U52', 'Fan Tray Middle Temperature Sensor', '0x00'),
|
|
('TEMP_FAN_U17', 'Fan Tray Right Temperature Sensor', '0x01'),
|
|
('TEMP_SW_U52', 'Switchboard Left Inlet Temperature Sensor', '0x02'),
|
|
('TEMP_SW_U16', 'Switchboard Right Inlet Temperature Sensor', '0x03'),
|
|
('TEMP_BB_U3', 'Baseboard Temperature Sensor', '0x04'),
|
|
('TEMP_CPU', 'CPU Internal Temperature Sensor', '0x05'),
|
|
('TEMP_SW_Internal', 'ASIC Internal Temperature Sensor', '0x61'),
|
|
('SW_U04_Temp', 'IR3595 Chip Left Temperature Sensor', '0x4F'),
|
|
('SW_U14_Temp', 'IR3595 Chip Right Temperature Sensor', '0x56'),
|
|
('SW_U4403_Temp', 'IR3584 Chip Temperature Sensor', '0x5D'),
|
|
]
|
|
self.sensor_id = self.THERMAL_LIST[self.index][0]
|
|
self.sensor_des = self.THERMAL_LIST[self.index][1]
|
|
self.sensor_reading_addr = self.THERMAL_LIST[self.index][2]
|
|
|
|
def __set_threshold(self, key, value):
|
|
print('{} {}'.format(key, value))
|
|
|
|
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
|
|
"""
|
|
temperature = 0.0
|
|
status, raw_ss_read = self._api_helper.ipmi_raw(
|
|
IPMI_SENSOR_NETFN, IPMI_SS_READ_CMD.format(self.sensor_reading_addr))
|
|
if status and len(raw_ss_read.split()) > 0:
|
|
ss_read = raw_ss_read.split()[0]
|
|
temperature = float(int(ss_read, 16))
|
|
return temperature
|
|
|
|
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
|
|
"""
|
|
high_threshold = 0.0
|
|
status, raw_up_thres_read = self._api_helper.ipmi_raw(
|
|
IPMI_SENSOR_NETFN, IPMI_SS_THRESHOLD_CMD.format(self.sensor_reading_addr))
|
|
if status and len(raw_up_thres_read.split()) > 6:
|
|
ss_read = raw_up_thres_read.split()[4]
|
|
high_threshold = float(int(ss_read, 16))
|
|
return high_threshold
|
|
|
|
def get_low_threshold(self):
|
|
"""
|
|
Retrieves the low threshold temperature of thermal
|
|
Returns:
|
|
A float number, the low threshold temperature of thermal in Celsius
|
|
up to nearest thousandth of one degree Celsius, e.g. 30.125
|
|
"""
|
|
return DEFUALT_LOWER_TRESHOLD
|
|
|
|
def set_high_threshold(self, temperature):
|
|
"""
|
|
Sets the high threshold temperature of thermal
|
|
Args :
|
|
temperature: A float number up to nearest thousandth of one degree Celsius,
|
|
e.g. 30.125
|
|
Returns:
|
|
A boolean, True if threshold is set successfully, False if not
|
|
"""
|
|
status, ret_txt = self._api_helper.ipmi_set_ss_thres(self.sensor_id, HIGH_TRESHOLD_SET_KEY, temperature)
|
|
return status
|
|
|
|
def set_low_threshold(self, temperature):
|
|
"""
|
|
Sets the low threshold temperature of thermal
|
|
Args :
|
|
temperature: A float number up to nearest thousandth of one degree Celsius,
|
|
e.g. 30.125
|
|
Returns:
|
|
A boolean, True if threshold is set successfully, False if not
|
|
"""
|
|
return False
|
|
|
|
def get_name(self):
|
|
"""
|
|
Retrieves the name of the thermal device
|
|
Returns:
|
|
string: The name of the thermal device
|
|
"""
|
|
return self.THERMAL_LIST[self.index][0]
|
|
|
|
def get_presence(self):
|
|
"""
|
|
Retrieves the presence of the device
|
|
Returns:
|
|
bool: True if device is present, False if not
|
|
"""
|
|
return True if self.get_temperature() > 0 else False
|
|
|
|
def get_model(self):
|
|
"""
|
|
Retrieves the model number (or part number) of the device
|
|
Returns:
|
|
string: Model/part number of device
|
|
"""
|
|
return self.sensor_des
|
|
|
|
def get_serial(self):
|
|
"""
|
|
Retrieves the serial number of the device
|
|
Returns:
|
|
string: Serial number of device
|
|
"""
|
|
return "Unknown"
|
|
|
|
def get_status(self):
|
|
"""
|
|
Retrieves the operational status of the device
|
|
Returns:
|
|
A boolean value, True if device is operating properly, False if not
|
|
"""
|
|
return self.get_presence()
|