Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[device/alibaba] - Update sensor naming format in sensorutil. #20

Merged
merged 2 commits into from Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 59 additions & 10 deletions device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = 'Wirut G.<wgetbumr@celestica.com>'
__license__ = "GPL"
__version__ = "0.1.1"
__version__ = "0.2.0"
__status__ = "Development"

import requests
Expand Down Expand Up @@ -33,8 +33,53 @@ def input_type_selector(self, unit):
"W": "power"
}.get(unit, unit)

def input_name_selector(self, sensor_name, input_name):

self.sensor_name = {
"syscpld-i2c-0-0d": "TEMPERATURE",
"dps1100-i2c-24-58": "PSU1",
"dps1100-i2c-25-59": "PSU2",
"fancpld-i2c-8-0d": "FAN"
}.get(sensor_name, sensor_name)

if 'dps1100' in sensor_name:
input_name = {
"fan1": self.sensor_name + "_FAN",
"iin": self.sensor_name + "_CURR_I",
"iout1": self.sensor_name + "_CURR_O",
"pin": self.sensor_name + "_POWER_I",
"pout1": self.sensor_name + "_POWER_O",
"temp1": self.sensor_name + "_TEMP1",
"temp2": self.sensor_name + "_TEMP2",
"vin": self.sensor_name + "_VOL_I",
"vout1": self.sensor_name + "_VOL_O"
}.get(input_name, input_name)

elif 'tmp75' in sensor_name:
input_name = {
"tmp75-i2c-7-4d": "FTB_INLET_RIGHT",
"tmp75-i2c-7-4c": "FTB_INLET_LEFT",
"tmp75-i2c-7-4b": "FTB_SWITCH_OUTLET",
"tmp75-i2c-7-4a": "BTF_SWITCH_OUTLET",
"tmp75-i2c-39-48": "BTF_INLET_RIGHT",
"tmp75-i2c-39-49": "BTF_INLET_LEFT"
}.get(sensor_name, input_name)
self.sensor_name = "TEMPERATURE"

elif 'fancpld' in sensor_name:
raw_fan_input = input_name.split()
input_name = raw_fan_input[0] + \
raw_fan_input[1] + "_" + raw_fan_input[2]

elif 'ir35' in sensor_name or 'ir38' in sensor_name:
sensor_name_raw = sensor_name.split("-")
sensor_name = sensor_name_raw[0]
self.sensor_name = sensor_name.upper()

return input_name.replace(" ", "_").upper()

def get_num_sensors(self):
"""
"""
Get the number of sensors
:return: int num_sensors
"""
Expand All @@ -53,7 +98,7 @@ def get_num_sensors(self):
return num_sensors

def get_sensor_input_num(self, index):
"""
"""
Get the number of the input items of the specified sensor
:return: int input_num
"""
Expand All @@ -73,7 +118,7 @@ def get_sensor_input_num(self, index):
return input_num

def get_sensor_name(self, index):
"""
"""
Get the device name of the specified sensor.
for example "coretemp-isa-0000"
:return: str sensor_name
Expand All @@ -95,7 +140,7 @@ def get_sensor_name(self, index):

def get_sensor_input_name(self, sensor_index, input_index):
"""
Get the input item name of the specified input item of the
Get the input item name of the specified input item of the
specified sensor index, for example "Physical id 0"
:return: str sensor_input_name
"""
Expand All @@ -120,7 +165,7 @@ def get_sensor_input_name(self, sensor_index, input_index):

def get_sensor_input_type(self, sensor_index, input_index):
"""
Get the item type of the specified input item of the specified sensor index,
Get the item type of the specified input item of the specified sensor index,
The return value should among "valtage","temperature"
:return: str sensor_input_type
"""
Expand Down Expand Up @@ -175,7 +220,7 @@ def get_sensor_input_value(self, sensor_index, input_index):

def get_sensor_input_low_threshold(self, sensor_index, input_index):
"""
Get the low threshold of the value,
Get the low threshold of the value,
the status of this item is not ok if the current value<low_threshold
:return: float sensor_input_low_threshold
"""
Expand Down Expand Up @@ -211,7 +256,7 @@ def get_sensor_input_low_threshold(self, sensor_index, input_index):

def get_sensor_input_high_threshold(self, sensor_index, input_index):
"""
Get the high threshold of the value,
Get the high threshold of the value,
the status of this item is not ok if the current value > high_threshold
:return: float sensor_input_high_threshold
"""
Expand Down Expand Up @@ -253,7 +298,6 @@ def get_all(self):
# Request sensor's information.
self.sensor_info_list = self.request_data()
for sensor_data in self.sensor_info_list:
sensor_name = sensor_data.get('name')
sensor_info = sensor_data.copy()

# Remove none unuse key.
Expand Down Expand Up @@ -283,8 +327,13 @@ def get_all(self):
1000 if str(thres_unit[0]).lower() == 'k' else h_thres
sensor_i_dict["LowThd"] = l_thres * \
1000 if str(thres_unit[0]).lower() == 'k' else l_thres

k = self.input_name_selector(sensor_data.get('name'), k)
sensor_dict[k] = sensor_i_dict

all_sensor_dict[sensor_name] = sensor_dict
if all_sensor_dict.get(self.sensor_name) is None:
all_sensor_dict[self.sensor_name] = dict()

all_sensor_dict[self.sensor_name].update(sensor_dict)

return all_sensor_dict
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = 'Wirut G.<wgetbumr@celestica.com>'
__license__ = "GPL"
__version__ = "0.1.1"
__version__ = "0.2.0"
__status__ = "Development"

import requests
Expand Down Expand Up @@ -33,8 +33,53 @@ def input_type_selector(self, unit):
"W": "power"
}.get(unit, unit)

def input_name_selector(self, sensor_name, input_name):

self.sensor_name = {
"syscpld-i2c-0-0d": "TEMPERATURE",
"dps1100-i2c-24-58": "PSU1",
"dps1100-i2c-25-59": "PSU2",
"fancpld-i2c-8-0d": "FAN"
}.get(sensor_name, sensor_name)

if 'dps1100' in sensor_name:
input_name = {
"fan1": self.sensor_name + "_FAN",
"iin": self.sensor_name + "_CURR_I",
"iout1": self.sensor_name + "_CURR_O",
"pin": self.sensor_name + "_POWER_I",
"pout1": self.sensor_name + "_POWER_O",
"temp1": self.sensor_name + "_TEMP1",
"temp2": self.sensor_name + "_TEMP2",
"vin": self.sensor_name + "_VOL_I",
"vout1": self.sensor_name + "_VOL_O"
}.get(input_name, input_name)

elif 'tmp75' in sensor_name:
input_name = {
"tmp75-i2c-7-4d": "FTB_INLET_RIGHT",
"tmp75-i2c-7-4c": "FTB_INLET_LEFT",
"tmp75-i2c-7-4b": "FTB_SWITCH_OUTLET",
"tmp75-i2c-7-4a": "BTF_SWITCH_OUTLET",
"tmp75-i2c-39-48": "BTF_INLET_RIGHT",
"tmp75-i2c-39-49": "BTF_INLET_LEFT"
}.get(sensor_name, input_name)
self.sensor_name = "TEMPERATURE"

elif 'fancpld' in sensor_name:
raw_fan_input = input_name.split()
input_name = raw_fan_input[0] + \
raw_fan_input[1] + "_" + raw_fan_input[2]

elif 'ir35' in sensor_name or 'ir38' in sensor_name:
sensor_name_raw = sensor_name.split("-")
sensor_name = sensor_name_raw[0]
self.sensor_name = sensor_name.upper()

return input_name.replace(" ", "_").upper()

def get_num_sensors(self):
"""
"""
Get the number of sensors
:return: int num_sensors
"""
Expand All @@ -53,7 +98,7 @@ def get_num_sensors(self):
return num_sensors

def get_sensor_input_num(self, index):
"""
"""
Get the number of the input items of the specified sensor
:return: int input_num
"""
Expand All @@ -73,7 +118,7 @@ def get_sensor_input_num(self, index):
return input_num

def get_sensor_name(self, index):
"""
"""
Get the device name of the specified sensor.
for example "coretemp-isa-0000"
:return: str sensor_name
Expand All @@ -95,7 +140,7 @@ def get_sensor_name(self, index):

def get_sensor_input_name(self, sensor_index, input_index):
"""
Get the input item name of the specified input item of the
Get the input item name of the specified input item of the
specified sensor index, for example "Physical id 0"
:return: str sensor_input_name
"""
Expand All @@ -120,7 +165,7 @@ def get_sensor_input_name(self, sensor_index, input_index):

def get_sensor_input_type(self, sensor_index, input_index):
"""
Get the item type of the specified input item of the specified sensor index,
Get the item type of the specified input item of the specified sensor index,
The return value should among "valtage","temperature"
:return: str sensor_input_type
"""
Expand Down Expand Up @@ -175,7 +220,7 @@ def get_sensor_input_value(self, sensor_index, input_index):

def get_sensor_input_low_threshold(self, sensor_index, input_index):
"""
Get the low threshold of the value,
Get the low threshold of the value,
the status of this item is not ok if the current value<low_threshold
:return: float sensor_input_low_threshold
"""
Expand Down Expand Up @@ -211,7 +256,7 @@ def get_sensor_input_low_threshold(self, sensor_index, input_index):

def get_sensor_input_high_threshold(self, sensor_index, input_index):
"""
Get the high threshold of the value,
Get the high threshold of the value,
the status of this item is not ok if the current value > high_threshold
:return: float sensor_input_high_threshold
"""
Expand Down Expand Up @@ -253,7 +298,6 @@ def get_all(self):
# Request sensor's information.
self.sensor_info_list = self.request_data()
for sensor_data in self.sensor_info_list:
sensor_name = sensor_data.get('name')
sensor_info = sensor_data.copy()

# Remove none unuse key.
Expand Down Expand Up @@ -283,8 +327,13 @@ def get_all(self):
1000 if str(thres_unit[0]).lower() == 'k' else h_thres
sensor_i_dict["LowThd"] = l_thres * \
1000 if str(thres_unit[0]).lower() == 'k' else l_thres

k = self.input_name_selector(sensor_data.get('name'), k)
sensor_dict[k] = sensor_i_dict

all_sensor_dict[sensor_name] = sensor_dict
if all_sensor_dict.get(self.sensor_name) is None:
all_sensor_dict[self.sensor_name] = dict()

all_sensor_dict[self.sensor_name].update(sensor_dict)

return all_sensor_dict
Loading