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

Update device plugins and bug fixes #8

Merged
merged 5 commits into from Nov 30, 2018
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
url = https://github.com/Ingrasys-sonic/sonic-platform-modules-ingrasys
[submodule "src/sonic-platform-common"]
path = src/sonic-platform-common
url = https://github.com/celestica-Inc/sonic-platform-common
url = https://github.com/Azure/sonic-platform-common
[submodule "src/sonic-platform-daemons"]
path = src/sonic-platform-daemons
url = https://github.com/Azure/sonic-platform-daemons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,34 @@
__author__ = 'Wirut G.<wgetbumr@celestica.com>'
__license__ = "GPL"
__version__ = "0.1.0"
__status__ = "Development"
__status__ = "Development"


import subprocess
import requests


class CpuTempUtil():
"""Platform-specific CpuTempUtil class"""

def __init__(self):
self.temp_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/temp"

pass

def get_cpu_temp(self):

# Get list of temperature of CPU cores.
p = subprocess.Popen(['sensors', '-Au', 'coretemp-isa-0000'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
p = subprocess.Popen(['sensors', '-Au', 'coretemp-isa-0000'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
raw_data_list = out.splitlines()
temp_string_list = [i for i, s in enumerate(raw_data_list) if '_input' in s]
temp_string_list = [i for i, s in enumerate(
raw_data_list) if '_input' in s]
tmp_list = [0]

for temp_string in temp_string_list:
tmp_list.append(float(raw_data_list[temp_string].split(":")[1]))

return tmp_list

return tmp_list

def get_max_cpu_tmp(self):
# Get maximum temperature from list of temperature of CPU cores.
Expand Down
125 changes: 99 additions & 26 deletions device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#!/usr/bin/env python

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

import re
import requests


class FanUtil():
"""Platform-specific FanUtil class"""

def __init__(self):

self.fan_fru_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/fruid/fan"
self.sensor_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/sensors"
self.fan_fru_url = "http://240.1.1.1:8080/api/sys/fruid/fan"
self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors"
self.fru_data_list = None
self.sensor_data_list = None


def request_data(self):
# Reqest data from BMC if not exist.
if self.fru_data_list is None or self.sensor_data_list is None:
Expand All @@ -25,18 +30,16 @@ def request_data(self):
self.sensor_data_list = sensor_json.get('Information')
return self.fru_data_list, self.sensor_data_list


def name_to_index(self, fan_name):
# Get fan index from fan name
match = re.match(r"(FAN)([0-9]+)-(1|2)", fan_name, re.I)
fan_index = None
if match:
i_list = list(match.groups())
fan_index = int(i_list[1])*2 - (int(i_list[2])%2)
fan_index = int(i_list[1])*2 - (int(i_list[2]) % 2)
return fan_index


def get_num_fans(self):
def get_num_fans(self):
"""
Get the number of fans
:return: int num_fans
Expand All @@ -45,7 +48,6 @@ def get_num_fans(self):

return num_fans


def get_fan_speed(self, fan_name):
"""
Get the current speed of the fan, the unit is "RPM"
Expand All @@ -58,7 +60,7 @@ def get_fan_speed(self, fan_name):

# Set key and index.
fan_speed = 0
position_key = "Front" if index % 2 !=0 else "Rear"
position_key = "Front" if index % 2 != 0 else "Rear"
index = int(round(float(index)/2))
fan_key = "Fan " + str(index) + " " + position_key

Expand All @@ -67,7 +69,7 @@ def get_fan_speed(self, fan_name):

# Get fan's speed.
for sensor_data in self.sensor_data_list:
sensor_name = sensor_data.get('name')
sensor_name = sensor_data.get('name')
if "fan" in str(sensor_name):
fan_data = sensor_data.get(fan_key)
fan_sp_list = map(int, re.findall(r'\d+', fan_data))
Expand All @@ -78,8 +80,7 @@ def get_fan_speed(self, fan_name):

return fan_speed


def get_fan_low_threshold(self, fan_name):
def get_fan_low_threshold(self, fan_name):
"""
Get the low speed threshold of the fan.
if the current speed < low speed threshold,
Expand All @@ -93,7 +94,7 @@ def get_fan_low_threshold(self, fan_name):

# Set key and index.
fan_low_threshold = 0
position_key = "Front" if index % 2 !=0 else "Rear"
position_key = "Front" if index % 2 != 0 else "Rear"
index = int(round(float(index)/2))
fan_key = "Fan " + str(index) + " " + position_key

Expand All @@ -102,7 +103,7 @@ def get_fan_low_threshold(self, fan_name):

# Get fan's threshold.
for sensor_data in self.sensor_data_list:
sensor_name = sensor_data.get('name')
sensor_name = sensor_data.get('name')
if "fan" in str(sensor_name):
fan_data = sensor_data.get(fan_key)
fan_sp_list = map(int, re.findall(r'\d+', fan_data))
Expand All @@ -113,7 +114,6 @@ def get_fan_low_threshold(self, fan_name):

return fan_low_threshold


def get_fan_high_threshold(self, fan_name):
"""
Get the hight speed threshold of the fan,
Expand All @@ -128,7 +128,7 @@ def get_fan_high_threshold(self, fan_name):

# Set key and index.
fan_high_threshold = 0
position_key = "Front" if index % 2 !=0 else "Rear"
position_key = "Front" if index % 2 != 0 else "Rear"
index = int(round(float(index)/2))
fan_key = "Fan " + str(index) + " " + position_key

Expand All @@ -137,7 +137,7 @@ def get_fan_high_threshold(self, fan_name):

# Get fan's threshold.
for sensor_data in self.sensor_data_list:
sensor_name = sensor_data.get('name')
sensor_name = sensor_data.get('name')
if "fan" in str(sensor_name):
fan_data = sensor_data.get(fan_key)
fan_sp_list = map(int, re.findall(r'\d+', fan_data))
Expand All @@ -148,13 +148,12 @@ def get_fan_high_threshold(self, fan_name):

return fan_high_threshold


def get_fan_pn(self, fan_name):
"""
Get the product name of the fan
:return: str fan_pn
"""

try:
# Get real fan index
index = self.name_to_index(fan_name)
Expand All @@ -172,14 +171,13 @@ def get_fan_pn(self, fan_name):
matching_fan = [s for s in fan_fru if fan_fru_key in s]
if matching_fan:
pn = [s for s in fan_fru if "Part" in s]
fan_pn = pn[0].split()[4]
fan_pn = pn[0].split()[4]

except:
return "N/A"

return fan_pn


def get_fan_sn(self, fan_name):
"""
Get the serial number of the fan
Expand All @@ -192,8 +190,8 @@ def get_fan_sn(self, fan_name):
# Set key and index.
fan_sn = "N/A"
index = int(round(float(index)/2))
fan_fru_key = "Fantray" + str(index)
fan_fru_key = "Fantray" + str(index)

# Request and validate fan information.
self.fru_data_list, self.sensor_data_list = self.request_data()

Expand All @@ -202,7 +200,7 @@ def get_fan_sn(self, fan_name):
matching_fan = [s for s in fan_fru if fan_fru_key in s]
if matching_fan:
serial = [s for s in fan_fru if "Serial" in s]
fan_sn = serial[0].split()[3]
fan_sn = serial[0].split()[3]

except:
return "N/A"
Expand All @@ -222,9 +220,84 @@ def get_fans_name_list(self):
# Set fan name and add to the list.
for x in range(1, n_fan + 1):
f_index = int(round(float(x)/2))
pos = 1 if x%2 else 2
pos = 1 if x % 2 else 2
fan_name = 'FAN{}-{}'.format(f_index, pos)
fan_names.append(fan_name)

return fan_names


def get_all(self):
"""
Get all information of system FANs, returns JSON objects in python 'DICT'.
Number, mandatory, max number of FAN, integer
FAN1_1, FAN1_2, ... mandatory, FAN name, string
Present, mandatory for each FAN, present status, boolean, True for present, False for NOT present, read directly from h/w
Running, conditional, if PRESENT is True, running status of the FAN, True for running, False for stopped, read directly from h/w
Speed, conditional, if PRESENT is True, real FAN speed, float, read directly from h/w
LowThd, conditional, if PRESENT is True, lower bound of FAN speed, float, read from h/w
HighThd, conditional, if PRESENT is True, upper bound of FAN speed, float, read from h/w
PN, conditional, if PRESENT is True, PN of the FAN, string
SN, conditional, if PRESENT is True, SN of the FAN, string)
"""

self.fru_data_list, self.sensor_data_list = self.request_data()
all_fan_dict = dict()

# Get the number of fans
n_fan = self.get_num_fans()
all_fan_dict["Number"] = len(self.fru_data_list)

# Set fan FRU data.
fan_fru_dict = dict()
for fan_fru in self.fru_data_list:
if len(fan_fru) == 0:
continue
fru_dict = dict()
fan_key = fan_fru[0].split()
fan_sn = "N/A"
fan_pn = "N/A"
fan_speed = "N/A"
fan_ht = "N/A"
fan_ps = False
fan_lt = "N/A"

if str(fan_key[-1]).lower() == "absent":
fan_idx = int(re.findall('\d+', fan_key[0])[0])
else:
fan_idx = int(re.findall('\d+', fan_key[-1])[0])
fan_ps = True
pn = [s for s in fan_fru if "Part" in s]
sn = [s for s in fan_fru if "Serial" in s]
fan_pn = pn[0].split()[-1] if len(pn) > 0 else 'N/A'
fan_sn = sn[0].split()[-1] if len(sn) > 0 else 'N/A'

fru_dict["PN"] = fan_pn
fru_dict["SN"] = fan_sn
fru_dict["Present"] = fan_ps
fan_fru_dict[fan_idx] = fru_dict

# Set fan sensor data.
for sensor_data in self.sensor_data_list:
sensor_name = sensor_data.get('name')
if "fan" in str(sensor_name):
for x in range(1, n_fan + 1):
fan_dict = dict()
f_index = int(round(float(x)/2))
pos = 1 if x % 2 else 2
position_key = "Front" if x % 2 != 0 else "Rear"
fan_key = "Fan " + str(f_index) + " " + position_key
fan_data = sensor_data.get(fan_key)
fan_sp_list = map(int, re.findall(r'\d+', fan_data))
fan_dict["Present"] = fan_fru_dict[f_index]["Present"]
if fan_dict["Present"]:
fan_dict["Speed"] = fan_sp_list[0]
fan_dict["Running"] = True if fan_dict["Speed"] > 0 else False
fan_dict["LowThd"] = fan_sp_list[1]
fan_dict["HighThd"] = fan_sp_list[2]
fan_dict["PN"] = fan_fru_dict[f_index]["PN"]
fan_dict["SN"] = fan_fru_dict[f_index]["SN"]
fan_name = 'FAN{}-{}'.format(f_index, pos)
all_fan_dict[fan_name] = fan_dict
break

return all_fan_dict
Loading