forked from alibaba-archive/alibabacloud-tool-bmc-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhal_temp.py
86 lines (68 loc) · 2.41 KB
/
hal_temp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
###############################################################################
#
# Hardware Abstraction Layer APIs -- Temperature APIs.
#
# Copyright (C) Alibaba, INC.
#
###############################################################################
HAL_TEMP_SENSOR = "TEMPERATURE_SENSORS"
HAL_TEMP_CPU = "Cpu"
HAL_TEMP_INLET = "Inlet"
HAL_TEMP_SWITCH = "Switch"
"""
class for HAL temperature APIs.
@param temp_dict Dictionary of temperature, in Celcius degress and floating
point number.
Example:
{
"Value": 30.0, # -99999.0
"Min": -10.0, # -99999.0
"Max": 50.0 # -99999.0
}
"""
class HalTemperature(object):
def __init__(self, sensor_obj):
"""
@param sensor_obj Instance of HalSensor from hal_sensor module
@note Raise Exception when temperature sensors' name map is not
loaded successfully
"""
self.sensors = sensor_obj
self.temp_name = [HAL_TEMP_CPU, HAL_TEMP_INLET, HAL_TEMP_SWITCH]
self.temp_name_maps = {}
if self.load_temp_sensors() != 0:
raise Exception("Invalid temperature sensors configuration")
def load_temp_sensors(self):
"""
Load temperature sensors' map
@return 0 for success, -1 for failure
"""
if HAL_TEMP_SENSOR not in self.sensors.config:
return -1
temp_sensor_dict = self.sensors.config[HAL_TEMP_SENSOR]
for name in self.temp_name:
if name not in temp_sensor_dict:
return -1
self.temp_name_maps[name] = temp_sensor_dict[name]
return 0
def get_cpu_temp(self):
"""
Get CPU temperature.
@return temp_dict for tempperature or None for failure
"""
name = self.temp_name_maps[HAL_TEMP_CPU]
return self.sensors.get_sensor(name)
def get_inlet_temp(self):
"""
Get Inlet temperature.
@return temp_dict for tempperature or None for failure
"""
name = self.temp_name_maps[HAL_TEMP_INLET]
return self.sensors.get_sensor(name)
def get_switch_temp(self):
"""
Get Switch ASIC temperature.
@return temp_dict for tempperature or None for failure
"""
name = self.temp_name_maps[HAL_TEMP_SWITCH]
return self.sensors.get_sensor(name)