Skip to content

Commit

Permalink
Merge pull request sonic-net#870 from pjaipakdee19/dev_seastone2_api
Browse files Browse the repository at this point in the history
[device/celestica-silverstone2]: Implement ThermalBase API
  • Loading branch information
Wirut Getbamrung authored Jul 13, 2020
2 parents a6264b5 + c336121 commit adeca8a
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self):

self.__initialize_fan()
self.__initialize_psu()
self.__initialize_thermals()

# self.is_host = self._api_common.is_host()

Expand Down Expand Up @@ -70,11 +71,17 @@ def __initialize_psu(self):
psu_index += 1
self._psu_list.append(psu)

# def __initialize_thermals(self):
# from sonic_platform.thermal import Thermal
# for index in range(0, NUM_THERMAL):
# thermal = Thermal(index)
# self._thermal_list.append(thermal)
def __initialize_thermals(self):
from sonic_platform.thermal import Thermal

thermal_config_path = self._api_common.get_config_path(Thermal.THERMAL_CONFIG)
thermal_config = self._api_common.load_json_file(thermal_config_path)

thermal_index = 0
for index in range(0, thermal_config['thermal_num']):
thermal = Thermal(thermal_index, conf=thermal_config)
thermal_index += 1
self._thermal_list.append(thermal)

# def __initialize_eeprom(self):
# from sonic_platform.eeprom import Tlv
Expand Down
230 changes: 230 additions & 0 deletions device/celestica/x86_64-cel_seastone_2-r0/sonic_platform/thermal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
#!/usr/bin/env python

#############################################################################
# Celestica
#
# Module contains an implementation of SONiC Platform Base API and
# provides the thermal status which are available in the platform
#
#############################################################################

import json
import math
import os.path
import inspect

try:
from sonic_platform_base.thermal_base import ThermalBase
from common import Common
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Thermal(ThermalBase):
"""Platform-specific Thermal class"""

THERMAL_CONFIG = 'thermal.json'

def __init__(self, index, thermal_index=0 ,conf=None):
ThermalBase.__init__(self)

self.thermal_index = index

self._config = conf
self._api_common = Common()

self._name = self.get_name()

def get_name(self):
"""
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.
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)

return self._api_common.get_output(self.thermal_index, config, Common.NULL_VAL)

def get_temperature(self):
"""
Retrieves current temperature reading from thermal
by using command ipmitool raw 0x04 0x2D [address]
Returns:
A float number of current temperature in Celsius up to nearest thousandth
of one degree Celsius, e.g. 30.125
"""

f_name = inspect.stack()[0][3]
config = self._config.get(f_name)

return self._api_common.get_output(self.thermal_index, config, Common.NULL_VAL)


def get_high_threshold(self):
"""
Retrieves the high threshold temperature of thermal
For AMI BMC device :
Example output
Temp | 35.000 | degrees C|ok | na | na | na | na | na | na
The thresholds listed are, in order: lnr, lcr, lnc, unc, ucr, unr
These are acronyms for:
Lower Non-Recoverable
Lower Critical
Lower Non-Critical
Upper Non-Critical
Upper Critical
Upper Non-Recoverable
Returns:
unc as float number and return 0 if the BMC output is na.
A float number, the high threshold temperature of thermal in Celsius
up to nearest thousandth of one degree Celsius, e.g. 30.125
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = 0
output = self._api_common.get_output(self.thermal_index, config, default) if self.get_presence() else default
return float(output)

def get_low_threshold(self):
"""
Retrieves the low threshold temperature of thermal
Returns:
lnc as float number and return 0 if the BMC output is na.
A float number, the low threshold temperature of thermal in Celsius
up to nearest thousandth of one degree Celsius, e.g. 30.125
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = 0
output = self._api_common.get_output(self.thermal_index, config, default) if self.get_presence() else default
return float(output)

def set_high_threshold(self, temperature):
"""
Sets the high threshold temperature of thermal
For AMI BMC device :
use ipmitool command
ipmitool sensor thresh [sensor name] unc [0>= temp_value <=62]
if the current value of unc is 'na' ipmitool can't be set the value
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
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = 0
output = self._api_common.set_output(self.thermal_index, temperature ,config) if self.get_presence() else default
return output

def set_low_threshold(self, temperature):
"""
Sets the low threshold temperature of thermal
For AMI BMC device :
use ipmitool command
ipmitool sensor thresh [sensor name] lnc [temp_value]
if the current value of lnc is 'na' ipmitool can't be set the value
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
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = 0
output = self._api_common.set_output(self.thermal_index, temperature ,config) if self.get_presence() else default
return output

def get_high_critical_threshold(self):
"""
Retrieves the high critical threshold temperature of thermal
Returns:
ucr as float number and return 0 if the BMC output is na.
A float number, the high critical threshold temperature of thermal in Celsius
up to nearest thousandth of one degree Celsius, e.g. 30.125
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = 0
output = self._api_common.get_output(self.thermal_index, config, default) if self.get_presence() else default
return float(output)

def get_low_critical_threshold(self):
"""
Retrieves the low critical threshold temperature of thermal
Returns:
lnr as float number and return 0 if the BMC output is na.
A float number, the low critical threshold temperature of thermal in Celsius
up to nearest thousandth of one degree Celsius, e.g. 30.125
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = 0
output = self._api_common.get_output(self.thermal_index, config, default) if self.get_presence() else default
return float(output)

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
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = 0
return self._api_common.get_output(self.thermal_index, config, default) if self.get_presence() else default

def get_serial(self):
"""
Retrieves the serial number of the device
Returns:
string: Serial number of device
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = 0
return self._api_common.get_output(self.thermal_index, config, default) if self.get_presence() else default

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
f_name = inspect.stack()[0][3]
config = self._config.get(f_name)
default = False
output = self._api_common.get_output(self.thermal_index, config, default) if self.get_presence() else default
output = json.loads(output.lower())
return output
Loading

0 comments on commit adeca8a

Please sign in to comment.