From 79ae4b6925d03283daf3753c0ee42eb5dbaaab27 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Tue, 29 Jan 2019 18:51:14 +0700 Subject: [PATCH] [device/alibaba] - Update device plugin to support new platformutil --- .../plugins/fanutil.py | 35 ++++++++++------- .../plugins/psuutil.py | 20 +++++++++- .../plugins/sensorutil.py | 24 ++++++++++++ .../plugins/fanutil.py | 35 ++++++++++------- .../plugins/psuutil.py | 20 +++++++++- .../plugins/sensorutil.py | 24 ++++++++++++ .../plugins/fanutil.py | 39 ++++++++++++------- .../plugins/psuutil.py | 20 +++++++++- .../plugins/sensorutil.py | 24 ++++++++++++ platform/broadcom/sonic-platform-modules-cel | 2 +- 10 files changed, 200 insertions(+), 43 deletions(-) diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py index 33866a6f9377..5586e1299e83 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fanutil.py @@ -2,11 +2,11 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.1" +__version__ = "0.1.2" __status__ = "Development" -import re import requests +import re class FanUtil(): @@ -249,27 +249,33 @@ def get_all(self): # Set fan FRU data. fan_fru_dict = dict() + fan_raw_idx = 1 for fan_fru in self.fru_data_list: - if len(fan_fru) == 0: - continue fru_dict = dict() - fan_key = fan_fru[0].split() fan_ps = False - if str(fan_key[-1]).lower() == "absent": - fan_idx = int(re.findall('\d+', fan_key[0])[0]) + if len(fan_fru) == 0: + fan_idx = fan_raw_idx 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].strip() if len(pn) > 0 else 'N/A' - fan_sn = sn[0].split(":")[-1].strip() if len(sn) > 0 else 'N/A' + fan_key = fan_fru[0].split() + 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].strip() if len(pn) > 0 else 'N/A' + fan_sn = sn[0].split( + ":")[-1].strip() if len(sn) > 0 else 'N/A' fru_dict["PN"] = "N/A" if not fan_pn or fan_pn == "" else fan_pn fru_dict["SN"] = "N/A" if not fan_sn or fan_sn == "" else fan_sn fru_dict["Present"] = fan_ps fan_fru_dict[fan_idx] = fru_dict + fan_raw_idx += 1 # Set fan sensor data. for sensor_data in self.sensor_data_list: @@ -291,6 +297,9 @@ def get_all(self): 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_dict["AirFlow"] = "FTOB" if "R1241-F9001" in fan_dict["PN"] else "Unknown" + fan_dict["AirFlow"] = "BTOF" if "R1241-F9002" in fan_dict["PN"] else fan_dict["AirFlow"] + fan_dict["Status"] = True if fan_dict["AirFlow"] != "Unknown" else False fan_name = 'FAN{}_{}'.format(f_index, pos) all_fan_dict[fan_name] = fan_dict break diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py index 242beb570e6a..b752c6169645 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/psuutil.py @@ -2,7 +2,7 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.2" +__version__ = "0.1.3" __status__ = "Development" import requests @@ -36,6 +36,15 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list + def airflow_selector(self, pn): + # Set input type. + return { + "DPS-1100FB": "FTOB", + "DPS-1100AB": "BTOF", + "FSJ026-A20G": "FTOB", + "FSJ038-A20G": "BTOF" + }.get(pn, "Unknown") + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -213,12 +222,21 @@ def get_all(self): "Present")).strip() == "Present" else False psu_pw_status = True if str(fru_status.get( "Power Status")).strip() == "OK" else False + psu_pw_type = str(fru_status.get( + "Power Type")).strip() + ac_status = True if str(fru_status.get( + "AC Status")).strip().upper() == "OK" else False psu_status_dict["Present"] = psu_ps_status if psu_ps_status: psu_status_dict["PowerStatus"] = psu_pw_status psu_status_dict["PN"] = psu_info_dict[psu_idx]["PN"] psu_status_dict["SN"] = psu_info_dict[psu_idx]["SN"] + psu_status_dict["InputType"] = psu_pw_type + psu_status_dict["InputStatus"] = True if psu_pw_status and psu_ps_status else False + psu_status_dict["OutputStatus"] = ac_status + psu_status_dict["AirFlow"] = self.airflow_selector( + psu_status_dict["PN"].split()[0]) all_psu_dict[find_psu[0]] = psu_status_dict return all_psu_dict diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py index bb526aa8a174..4bf14ce6310b 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sensorutil.py @@ -13,6 +13,7 @@ class SensorUtil(): def __init__(self): self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors" + self.sys_fruid_url = "http://240.1.1.1:8080/api/sys/fruid/sys" self.sensor_info_list = None def request_data(self): @@ -21,6 +22,9 @@ def request_data(self): sensor_data_req = requests.get(self.sensor_url) sensor_json = sensor_data_req.json() self.sensor_info_list = sensor_json.get('Information') + sys_fruid_req = requests.get(self.sys_fruid_url) + sys_fruid_json = sys_fruid_req.json() + self.sys_fruid_list = sys_fruid_json.get('Information') return self.sensor_info_list def input_type_selector(self, unit): @@ -291,6 +295,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return sensor_input_high_threshold + def get_sys_airflow(self): + sys_air_flow = "Unknown" + sys_pn_data = [ + v.split(":") for v in self.sys_fruid_list if "Product Part Number" in v] + + if len(sys_pn_data) == 0: + return sys_air_flow + + sys_pn = sys_pn_data[0][1] + if "R1241-F0001" in sys_pn: + sys_air_flow = "FTOB" + elif"R1241-F0002" in sys_pn: + sys_air_flow = "BTOF" + + return sys_air_flow + def get_all(self): all_sensor_dict = dict() @@ -336,4 +356,8 @@ def get_all(self): all_sensor_dict[self.sensor_name].update(sensor_dict) + sensor_dict = dict() + sensor_dict["Sys_AirFlow"] = self.get_sys_airflow() + all_sensor_dict["TEMPERATURE"].update(sensor_dict) + return all_sensor_dict diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fanutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fanutil.py index 33866a6f9377..5586e1299e83 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fanutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fanutil.py @@ -2,11 +2,11 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.1" +__version__ = "0.1.2" __status__ = "Development" -import re import requests +import re class FanUtil(): @@ -249,27 +249,33 @@ def get_all(self): # Set fan FRU data. fan_fru_dict = dict() + fan_raw_idx = 1 for fan_fru in self.fru_data_list: - if len(fan_fru) == 0: - continue fru_dict = dict() - fan_key = fan_fru[0].split() fan_ps = False - if str(fan_key[-1]).lower() == "absent": - fan_idx = int(re.findall('\d+', fan_key[0])[0]) + if len(fan_fru) == 0: + fan_idx = fan_raw_idx 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].strip() if len(pn) > 0 else 'N/A' - fan_sn = sn[0].split(":")[-1].strip() if len(sn) > 0 else 'N/A' + fan_key = fan_fru[0].split() + 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].strip() if len(pn) > 0 else 'N/A' + fan_sn = sn[0].split( + ":")[-1].strip() if len(sn) > 0 else 'N/A' fru_dict["PN"] = "N/A" if not fan_pn or fan_pn == "" else fan_pn fru_dict["SN"] = "N/A" if not fan_sn or fan_sn == "" else fan_sn fru_dict["Present"] = fan_ps fan_fru_dict[fan_idx] = fru_dict + fan_raw_idx += 1 # Set fan sensor data. for sensor_data in self.sensor_data_list: @@ -291,6 +297,9 @@ def get_all(self): 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_dict["AirFlow"] = "FTOB" if "R1241-F9001" in fan_dict["PN"] else "Unknown" + fan_dict["AirFlow"] = "BTOF" if "R1241-F9002" in fan_dict["PN"] else fan_dict["AirFlow"] + fan_dict["Status"] = True if fan_dict["AirFlow"] != "Unknown" else False fan_name = 'FAN{}_{}'.format(f_index, pos) all_fan_dict[fan_name] = fan_dict break diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py index 242beb570e6a..b752c6169645 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/psuutil.py @@ -2,7 +2,7 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.2" +__version__ = "0.1.3" __status__ = "Development" import requests @@ -36,6 +36,15 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list + def airflow_selector(self, pn): + # Set input type. + return { + "DPS-1100FB": "FTOB", + "DPS-1100AB": "BTOF", + "FSJ026-A20G": "FTOB", + "FSJ038-A20G": "BTOF" + }.get(pn, "Unknown") + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -213,12 +222,21 @@ def get_all(self): "Present")).strip() == "Present" else False psu_pw_status = True if str(fru_status.get( "Power Status")).strip() == "OK" else False + psu_pw_type = str(fru_status.get( + "Power Type")).strip() + ac_status = True if str(fru_status.get( + "AC Status")).strip().upper() == "OK" else False psu_status_dict["Present"] = psu_ps_status if psu_ps_status: psu_status_dict["PowerStatus"] = psu_pw_status psu_status_dict["PN"] = psu_info_dict[psu_idx]["PN"] psu_status_dict["SN"] = psu_info_dict[psu_idx]["SN"] + psu_status_dict["InputType"] = psu_pw_type + psu_status_dict["InputStatus"] = True if psu_pw_status and psu_ps_status else False + psu_status_dict["OutputStatus"] = ac_status + psu_status_dict["AirFlow"] = self.airflow_selector( + psu_status_dict["PN"].split()[0]) all_psu_dict[find_psu[0]] = psu_status_dict return all_psu_dict diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py index bb526aa8a174..4bf14ce6310b 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sensorutil.py @@ -13,6 +13,7 @@ class SensorUtil(): def __init__(self): self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors" + self.sys_fruid_url = "http://240.1.1.1:8080/api/sys/fruid/sys" self.sensor_info_list = None def request_data(self): @@ -21,6 +22,9 @@ def request_data(self): sensor_data_req = requests.get(self.sensor_url) sensor_json = sensor_data_req.json() self.sensor_info_list = sensor_json.get('Information') + sys_fruid_req = requests.get(self.sys_fruid_url) + sys_fruid_json = sys_fruid_req.json() + self.sys_fruid_list = sys_fruid_json.get('Information') return self.sensor_info_list def input_type_selector(self, unit): @@ -291,6 +295,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return sensor_input_high_threshold + def get_sys_airflow(self): + sys_air_flow = "Unknown" + sys_pn_data = [ + v.split(":") for v in self.sys_fruid_list if "Product Part Number" in v] + + if len(sys_pn_data) == 0: + return sys_air_flow + + sys_pn = sys_pn_data[0][1] + if "R1241-F0001" in sys_pn: + sys_air_flow = "FTOB" + elif"R1241-F0002" in sys_pn: + sys_air_flow = "BTOF" + + return sys_air_flow + def get_all(self): all_sensor_dict = dict() @@ -336,4 +356,8 @@ def get_all(self): all_sensor_dict[self.sensor_name].update(sensor_dict) + sensor_dict = dict() + sensor_dict["Sys_AirFlow"] = self.get_sys_airflow() + all_sensor_dict["TEMPERATURE"].update(sensor_dict) + return all_sensor_dict diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py index d3e8334271b8..554914bcfbba 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py @@ -1,7 +1,12 @@ #!/usr/bin/env python -import re +__author__ = 'Wirut G.' +__license__ = "GPL" +__version__ = "0.1.2" +__status__ = "Development" + import requests +import re class FanUtil(): @@ -244,27 +249,33 @@ def get_all(self): # Set fan FRU data. fan_fru_dict = dict() + fan_raw_idx = 1 for fan_fru in self.fru_data_list: - if len(fan_fru) == 0: - continue fru_dict = dict() - fan_key = fan_fru[0].split() fan_ps = False - if str(fan_key[-1]).lower() == "absent": - fan_idx = int(re.findall('\d+', fan_key[0])[0]) + if len(fan_fru) == 0: + fan_idx = fan_raw_idx 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].strip() if len(pn) > 0 else 'N/A' - fan_sn = sn[0].split(":")[-1].strip() if len(sn) > 0 else 'N/A' + fan_key = fan_fru[0].split() + 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].strip() if len(pn) > 0 else 'N/A' + fan_sn = sn[0].split( + ":")[-1].strip() if len(sn) > 0 else 'N/A' fru_dict["PN"] = "N/A" if not fan_pn or fan_pn == "" else fan_pn fru_dict["SN"] = "N/A" if not fan_sn or fan_sn == "" else fan_sn fru_dict["Present"] = fan_ps fan_fru_dict[fan_idx] = fru_dict + fan_raw_idx += 1 # Set fan sensor data. for sensor_data in self.sensor_data_list: @@ -286,8 +297,10 @@ def get_all(self): 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_dict["AirFlow"] = "FTOB" if "R1240-G0009" in fan_dict["PN"] else "Unknown" + fan_dict["Status"] = True if fan_dict["AirFlow"] != "Unknown" else False fan_name = 'FAN{}_{}'.format(f_index, pos) all_fan_dict[fan_name] = fan_dict break - return all_fan_dict \ No newline at end of file + return all_fan_dict diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py index e4910b1914b7..cfc4bc5ff3f5 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/psuutil.py @@ -2,7 +2,7 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.2" +__version__ = "0.1.3" __status__ = "Development" import requests @@ -36,6 +36,15 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list + def airflow_selector(self, pn): + # Set input type. + return { + "DPS-1100FB": "FTOB", + "DPS-1100AB": "BTOF", + "FSJ026-A20G": "FTOB", + "FSJ038-A20G": "BTOF" + }.get(pn, "Unknown") + def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -213,12 +222,21 @@ def get_all(self): "Present")).strip() == "Present" else False psu_pw_status = True if str(fru_status.get( "Power Status")).strip() == "OK" else False + psu_pw_type = str(fru_status.get( + "Power Type")).strip() + ac_status = True if str(fru_status.get( + "AC Status")).strip().upper() == "OK" else False psu_status_dict["Present"] = psu_ps_status if psu_ps_status: psu_status_dict["PowerStatus"] = psu_pw_status psu_status_dict["PN"] = psu_info_dict[psu_idx]["PN"] psu_status_dict["SN"] = psu_info_dict[psu_idx]["SN"] + psu_status_dict["InputType"] = psu_pw_type + psu_status_dict["InputStatus"] = True if psu_pw_status and psu_ps_status else False + psu_status_dict["OutputStatus"] = ac_status + psu_status_dict["AirFlow"] = self.airflow_selector( + psu_status_dict["PN"].split()[0]) all_psu_dict[find_psu[0]] = psu_status_dict return all_psu_dict diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py index 41c42fc90ed9..fc437dc8c8b7 100644 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sensorutil.py @@ -13,6 +13,7 @@ class SensorUtil(): def __init__(self): self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors" + self.sys_fruid_url = "http://240.1.1.1:8080/api/sys/fruid/sys" self.sensor_info_list = None def request_data(self): @@ -21,6 +22,9 @@ def request_data(self): sensor_data_req = requests.get(self.sensor_url) sensor_json = sensor_data_req.json() self.sensor_info_list = sensor_json.get('Information') + sys_fruid_req = requests.get(self.sys_fruid_url) + sys_fruid_json = sys_fruid_req.json() + self.sys_fruid_list = sys_fruid_json.get('Information') return self.sensor_info_list def input_type_selector(self, unit): @@ -311,6 +315,22 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return sensor_input_high_threshold + def get_sys_airflow(self): + sys_air_flow = "Unknown" + sys_pn_data = [ + v.split(":") for v in self.sys_fruid_list if "Product Part Number" in v] + + if len(sys_pn_data) == 0: + return sys_air_flow + + sys_pn = sys_pn_data[0][1] + if "R1240-F0001" in sys_pn: + sys_air_flow = "FTOB" + elif"R1240-F0002" in sys_pn: + sys_air_flow = "BTOF" + + return sys_air_flow + def get_all(self): all_sensor_dict = dict() @@ -356,4 +376,8 @@ def get_all(self): all_sensor_dict[self.sensor_name].update(sensor_dict) + sensor_dict = dict() + sensor_dict["Sys_AirFlow"] = self.get_sys_airflow() + all_sensor_dict["TEMPERATURE"].update(sensor_dict) + return all_sensor_dict diff --git a/platform/broadcom/sonic-platform-modules-cel b/platform/broadcom/sonic-platform-modules-cel index 83254f93135e..797a650609a3 160000 --- a/platform/broadcom/sonic-platform-modules-cel +++ b/platform/broadcom/sonic-platform-modules-cel @@ -1 +1 @@ -Subproject commit 83254f93135ec7c6cdc3e166401640337a35f832 +Subproject commit 797a650609a3a318e50e4d05304dda6584457391