From 3938f182935a7f9ae7eaf4df6f4f7904c6c1c82a Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Fri, 30 Nov 2018 11:47:58 +0700 Subject: [PATCH 1/5] Revert sonic-platform-common submocule --- .gitmodules | 2 +- src/sonic-platform-common | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 413e71ddcd1c..bb4eae528c72 100755 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/src/sonic-platform-common b/src/sonic-platform-common index d03c24161b2f..76ae431e41dc 160000 --- a/src/sonic-platform-common +++ b/src/sonic-platform-common @@ -1 +1 @@ -Subproject commit d03c24161b2f4c0c3c0023c81b99e68343e61410 +Subproject commit 76ae431e41dca1255f8056b590668c9ca187f031 From da4b0af6e935506df5dc31a1055f0261a65ae9a9 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Fri, 30 Nov 2018 11:50:12 +0700 Subject: [PATCH 2/5] Update sfputil to fixed sfp dom issue --- .../plugins/sfputil.py | 23 ++++++++++++----- .../plugins/sfputil.py | 23 ++++++++++++----- .../plugins/sfputil.py | 25 +++++++++++++------ 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py index e640de82c91d..3d0982f7eb2e 100755 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py @@ -24,7 +24,6 @@ class SfpUtil(SfpUtilBase): _port_name = "" _port_to_eeprom_mapping = {} _port_to_i2cbus_mapping = {} - @property def port_start(self): @@ -53,13 +52,22 @@ def get_port_name(self, port_num): self._port_name = "SFP" + str(port_num) return self._port_name + def get_eeprom_dom_raw(self, port_num): + if port_num in self.qsfp_ports: + # QSFP DOM EEPROM is also at addr 0x50 and thus also stored in eeprom_ifraw + return None + else: + # Read dom eeprom at addr 0x51 + return self._read_eeprom_devid(port_num, self.DOM_EEPROM_ADDR, 256) + def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = '/sys/bus/i2c/devices/i2c-{0}/{0}-0050/eeprom' for x in range(self.PORT_START, self.PORT_END+1): self.port_to_i2cbus_mapping[x] = (x + self.EEPROM_OFFSET) - self.port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET) + self.port_to_eeprom_mapping[x] = eeprom_path.format( + x + self.EEPROM_OFFSET) SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -75,7 +83,7 @@ def get_presence(self, port_num): # Read status try: - reg_file = open(reg_path) + reg_file = open(reg_path) content = reg_file.readline().rstrip() reg_value = int(content) except IOError as e: @@ -98,7 +106,8 @@ def set_low_power_mode(self, port_num, lpmode): try: port_name = self.get_port_name(port_num) - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -118,7 +127,8 @@ def reset(self, port_num): try: port_name = self.get_port_name(port_num) - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -133,7 +143,8 @@ def reset(self, port_num): # Flip the bit back high and write back to the register to take port out of reset try: - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: print "Error: unable to open file: %s" % str(e) return False diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py index 3f30544e26f5..44fa92c5718e 100755 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py @@ -24,7 +24,6 @@ class SfpUtil(SfpUtilBase): _port_name = "" _port_to_eeprom_mapping = {} _port_to_i2cbus_mapping = {} - @property def port_start(self): @@ -53,13 +52,22 @@ def get_port_name(self, port_num): self._port_name = "SFP" + str(port_num) return self._port_name + def get_eeprom_dom_raw(self, port_num): + if port_num in self.qsfp_ports: + # QSFP DOM EEPROM is also at addr 0x50 and thus also stored in eeprom_ifraw + return None + else: + # Read dom eeprom at addr 0x51 + return self._read_eeprom_devid(port_num, self.DOM_EEPROM_ADDR, 256) + def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = '/sys/bus/i2c/devices/i2c-{0}/{0}-0050/eeprom' for x in range(self.PORT_START, self.PORT_END+1): self.port_to_i2cbus_mapping[x] = (x + self.EEPROM_OFFSET) - self.port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET) + self.port_to_eeprom_mapping[x] = eeprom_path.format( + x + self.EEPROM_OFFSET) SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -75,7 +83,7 @@ def get_presence(self, port_num): # Read status try: - reg_file = open(reg_path) + reg_file = open(reg_path) content = reg_file.readline().rstrip() reg_value = int(content) except IOError as e: @@ -98,7 +106,8 @@ def set_low_power_mode(self, port_num, lpmode): try: port_name = self.get_port_name(port_num) - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -118,7 +127,8 @@ def reset(self, port_num): try: port_name = self.get_port_name(port_num) - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -133,7 +143,8 @@ def reset(self, port_num): # Flip the bit back high and write back to the register to take port out of reset try: - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: print "Error: unable to open file: %s" % str(e) return False diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py index 2b69f41589cd..88c300685e0b 100755 --- a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py @@ -24,7 +24,6 @@ class SfpUtil(SfpUtilBase): _port_name = "" _port_to_eeprom_mapping = {} _port_to_i2cbus_mapping = {} - @property def port_start(self): @@ -53,13 +52,22 @@ def get_port_name(self, port_num): self._port_name = "SFP" + str(port_num) return self._port_name + def get_eeprom_dom_raw(self, port_num): + if port_num in self.qsfp_ports: + # QSFP DOM EEPROM is also at addr 0x50 and thus also stored in eeprom_ifraw + return None + else: + # Read dom eeprom at addr 0x51 + return self._read_eeprom_devid(port_num, self.DOM_EEPROM_ADDR, 256) + def __init__(self): # Override port_to_eeprom_mapping for class initialization eeprom_path = '/sys/bus/i2c/devices/i2c-{0}/{0}-0050/eeprom' for x in range(self.PORT_START, self.PORT_END+1): self.port_to_i2cbus_mapping[x] = (x + self.EEPROM_OFFSET) - self.port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET) + self.port_to_eeprom_mapping[x] = eeprom_path.format( + x + self.EEPROM_OFFSET) SfpUtilBase.__init__(self) def get_presence(self, port_num): @@ -75,7 +83,7 @@ def get_presence(self, port_num): # Read status try: - reg_file = open(reg_path) + reg_file = open(reg_path) content = reg_file.readline().rstrip() reg_value = int(content) except IOError as e: @@ -98,7 +106,8 @@ def set_low_power_mode(self, port_num, lpmode): try: port_name = self.get_port_name(port_num) - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_lpmode"]), "r+") except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -118,7 +127,8 @@ def reset(self, port_num): try: port_name = self.get_port_name(port_num) - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -133,7 +143,8 @@ def reset(self, port_num): # Flip the bit back high and write back to the register to take port out of reset try: - reg_file = open("/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") + reg_file = open( + "/".join([self.PORT_INFO_PATH, port_name, "qsfp_reset"]), "w") except IOError as e: print "Error: unable to open file: %s" % str(e) return False @@ -142,4 +153,4 @@ def reset(self, port_num): reg_file.write(hex(1)) reg_file.close() - return True \ No newline at end of file + return True From 9d38d766947353c4105328163b87ea15cc809f54 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Fri, 30 Nov 2018 13:41:24 +0700 Subject: [PATCH 3/5] Update device plugins so support platformutil version 1.1 --- .../plugins/cputemputil.py | 18 +-- .../plugins/fanutil.py | 125 ++++++++++++++---- .../plugins/psuutil.py | 95 ++++++++++--- .../plugins/sensorutil.py | 50 ++++++- .../plugins/cputemputil.py | 2 +- .../plugins/fanutil.py | 125 ++++++++++++++---- .../plugins/psuutil.py | 95 ++++++++++--- .../plugins/sensorutil.py | 50 ++++++- .../plugins/fanutil.py | 118 +++++++++++++---- .../plugins/psuutil.py | 88 +++++++++--- .../plugins/sensorutil.py | 43 ++++++ platform/broadcom/sonic-platform-modules-cel | 2 +- 12 files changed, 666 insertions(+), 145 deletions(-) diff --git a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/cputemputil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/cputemputil.py index 375de67dd2a0..ac2589d044fd 100644 --- a/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/cputemputil.py +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/cputemputil.py @@ -9,32 +9,34 @@ __author__ = 'Wirut G.' __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. 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 09b1f1e58638..b6eb3b18ab35 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 @@ -1,19 +1,24 @@ #!/usr/bin/env python +__author__ = 'Wirut G.' +__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: @@ -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 @@ -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" @@ -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 @@ -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)) @@ -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, @@ -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 @@ -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)) @@ -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, @@ -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 @@ -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)) @@ -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) @@ -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 @@ -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() @@ -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" @@ -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 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 aff5650beac7..59bcf449c2a2 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 @@ -1,24 +1,30 @@ #!/usr/bin/env python +__author__ = 'Wirut G.' +__license__ = "GPL" +__version__ = "0.1.1" +__status__ = "Development" + import requests +import re try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" def __init__(self): PsuBase.__init__(self) - self.fru_status_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/fruid/status" - self.psu_info_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/fruid/psu" - + self.fru_status_url = "http://240.1.1.1:8080/api/sys/fruid/status" + self.psu_info_url = "http://240.1.1.1:8080/api/sys/fruid/psu" + self.fru_status_list = None self.psu_info_list = None - def request_data(self): # Reqest data from BMC if not exist. if self.fru_status_list is None or self.psu_info_list is None: @@ -30,7 +36,6 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -57,7 +62,7 @@ def get_psu_status(self, index): :param index: An integer, 1-based index of the PSU of which to query status :return: Boolean, True if PSU is operating properly, False if PSU is faulty """ - + # init data psu_key = "PSU" + str(index) psu_status_key = "Power Status" @@ -68,9 +73,9 @@ def get_psu_status(self, index): self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU power status. - for fru_status in self.fru_status_list: + for fru_status in self.fru_status_list: is_psu = fru_status.get(psu_key) - psu_status = str(fru_status.get(psu_status_key)).strip() + psu_status = str(fru_status.get(psu_status_key)).strip() if is_psu is not None and psu_status == "OK": psu_power_status = True @@ -99,9 +104,9 @@ def get_psu_presence(self, index): self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU present status. - for fru_status in self.fru_status_list: + for fru_status in self.fru_status_list: is_psu = fru_status.get(psu_key) - psu_status = str(fru_status.get(psu_presence_key)).strip() + psu_status = str(fru_status.get(psu_presence_key)).strip() if is_psu is not None and psu_status == "Present": psu_presence_status = True @@ -115,21 +120,21 @@ def get_psu_presence(self, index): def get_psu_sn(self, index): """ Get the serial number of the psu, - + :param index: An integer, 1-based index of the PSU. :return: Serial number """ serial_number = "N/A" psu_key = "PSU" + str(index) + " FRU" psu_sn_key = "Serial Number" - + try: # Request and validate sensor's information. self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU fru info. - for psu_fru in self.psu_info_list: - psu_sn = str(psu_fru.get(psu_sn_key)).strip() + for psu_fru in self.psu_info_list: + psu_sn = str(psu_fru.get(psu_sn_key)).strip() if psu_fru.get(psu_key) is not None: serial_number = psu_sn if psu_sn.strip() != "" else "N/A" break @@ -142,21 +147,21 @@ def get_psu_sn(self, index): def get_psu_pn(self, index): """ Get the product name of the psu - + :param index: An integer, 1-based index of the PSU. :return: Product name """ product_name = "N/A" psu_key = "PSU" + str(index) + " FRU" psu_pn_key = "Product Name" - + try: # Request and validate sensor's information self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU fru info. - for psu_fru in self.psu_info_list: - psu_pn = str(psu_fru.get(psu_pn_key)).strip() + for psu_fru in self.psu_info_list: + psu_pn = str(psu_fru.get(psu_pn_key)).strip() if psu_fru.get(psu_key) is not None: product_name = psu_pn if psu_pn.strip() != "" else "N/A" break @@ -165,3 +170,55 @@ def get_psu_pn(self, index): return "N/A" return product_name + + def get_all(self): + """ + Number: mandatory, max number of PSU, integer + PSU1, PSU2, ...: mandatory, PSU name, string + Present: mandatory for each PSU, present status, boolean, True for present, False for NOT present + PowerStatus: conditional, if PRESENT is True, power status of PSU,boolean, True for powered, False for NOT powered + PN, conditional, if PRESENT is True, PN of the PSU, string + SN, conditional, if PRESENT is True, SN of the PSU, string + """ + + # Init data + all_psu_dict = dict() + all_psu_dict["Number"] = self.get_num_psus() + psu_sn_key = "Serial Number" + psu_pn_key = "Product Name" + + # Request and validate sensor's information. + self.fru_status_list, self.psu_info_list = self.request_data() + + # Set PSU FRU data. + psu_info_dict = dict() + for psu_fru in self.psu_info_list: + psu_data = dict() + psu_data["PN"] = str(psu_fru.get(psu_pn_key)).strip( + ) if psu_fru.get(psu_pn_key) is not None else "N/A" + psu_data["SN"] = str(psu_fru.get(psu_sn_key)).strip( + ) if psu_fru.get(psu_sn_key) is not None else "N/A" + raw_key = [v for v in psu_fru.keys() if 'PSU' in v] + if len(raw_key) > 0: + psu_idx = int(re.findall('\d+', raw_key[0])[0]) + psu_info_dict[psu_idx] = psu_data + + # Set PSU status. + for fru_status in self.fru_status_list: + psu_status_dict = dict() + find_psu = [v for v in fru_status.keys() if "PSU" in v] + if len(find_psu) > 0: + psu_idx = int(re.findall('\d+', find_psu[0])[0]) + psu_ps_status = True if str(fru_status.get( + "Present")).strip() == "Present" else False + psu_pw_status = True if str(fru_status.get( + "Power Status")).strip() == "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"] + 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 8eca1d93af11..dca219bc6185 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 @@ -1,5 +1,10 @@ #!/usr/bin/env python +__author__ = 'Wirut G.' +__license__ = "GPL" +__version__ = "0.1.1" +__status__ = "Development" + import requests @@ -7,7 +12,7 @@ class SensorUtil(): """Platform-specific SensorUtil class""" def __init__(self): - self.sensor_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/sensors" + self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors" self.sensor_info_list = None def request_data(self): @@ -240,3 +245,46 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return 0 return sensor_input_high_threshold + + def get_all(self): + + all_sensor_dict = dict() + + # 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. + del sensor_info["name"] + del sensor_info["Adapter"] + + # Set sensor data. + sensor_dict = dict() + for k, v in sensor_info.items(): + sensor_i_dict = dict() + sensor_data_str = v.split() + indices_h = [i for i, s in enumerate( + sensor_data_str) if 'max' in s or 'high' in s] + indices_l = [i for i, s in enumerate( + sensor_data_str) if 'min' in s or 'low' in s] + h_thres = float( + sensor_data_str[indices_h[0] + 2]) if len(indices_h) != 0 else 0 + l_thres = float( + sensor_data_str[indices_l[0] + 2]) if len(indices_l) != 0 else 0 + thres_unit = sensor_data_str[-1] + + sensor_i_dict["Type"] = self.input_type_selector( + sensor_data_str[1]) + sensor_i_dict["Value"] = float( + sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 + sensor_i_dict["HighThd"] = h_thres * \ + 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 + sensor_dict[k] = sensor_i_dict + + all_sensor_dict[sensor_name] = sensor_dict + + return all_sensor_dict diff --git a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/cputemputil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/cputemputil.py index 375de67dd2a0..b5af46115b5c 100644 --- a/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/cputemputil.py +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/cputemputil.py @@ -18,7 +18,7 @@ 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): 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 09b1f1e58638..b6eb3b18ab35 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 @@ -1,19 +1,24 @@ #!/usr/bin/env python +__author__ = 'Wirut G.' +__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: @@ -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 @@ -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" @@ -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 @@ -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)) @@ -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, @@ -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 @@ -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)) @@ -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, @@ -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 @@ -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)) @@ -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) @@ -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 @@ -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() @@ -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" @@ -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 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 aff5650beac7..59bcf449c2a2 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 @@ -1,24 +1,30 @@ #!/usr/bin/env python +__author__ = 'Wirut G.' +__license__ = "GPL" +__version__ = "0.1.1" +__status__ = "Development" + import requests +import re try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" def __init__(self): PsuBase.__init__(self) - self.fru_status_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/fruid/status" - self.psu_info_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/fruid/psu" - + self.fru_status_url = "http://240.1.1.1:8080/api/sys/fruid/status" + self.psu_info_url = "http://240.1.1.1:8080/api/sys/fruid/psu" + self.fru_status_list = None self.psu_info_list = None - def request_data(self): # Reqest data from BMC if not exist. if self.fru_status_list is None or self.psu_info_list is None: @@ -30,7 +36,6 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -57,7 +62,7 @@ def get_psu_status(self, index): :param index: An integer, 1-based index of the PSU of which to query status :return: Boolean, True if PSU is operating properly, False if PSU is faulty """ - + # init data psu_key = "PSU" + str(index) psu_status_key = "Power Status" @@ -68,9 +73,9 @@ def get_psu_status(self, index): self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU power status. - for fru_status in self.fru_status_list: + for fru_status in self.fru_status_list: is_psu = fru_status.get(psu_key) - psu_status = str(fru_status.get(psu_status_key)).strip() + psu_status = str(fru_status.get(psu_status_key)).strip() if is_psu is not None and psu_status == "OK": psu_power_status = True @@ -99,9 +104,9 @@ def get_psu_presence(self, index): self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU present status. - for fru_status in self.fru_status_list: + for fru_status in self.fru_status_list: is_psu = fru_status.get(psu_key) - psu_status = str(fru_status.get(psu_presence_key)).strip() + psu_status = str(fru_status.get(psu_presence_key)).strip() if is_psu is not None and psu_status == "Present": psu_presence_status = True @@ -115,21 +120,21 @@ def get_psu_presence(self, index): def get_psu_sn(self, index): """ Get the serial number of the psu, - + :param index: An integer, 1-based index of the PSU. :return: Serial number """ serial_number = "N/A" psu_key = "PSU" + str(index) + " FRU" psu_sn_key = "Serial Number" - + try: # Request and validate sensor's information. self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU fru info. - for psu_fru in self.psu_info_list: - psu_sn = str(psu_fru.get(psu_sn_key)).strip() + for psu_fru in self.psu_info_list: + psu_sn = str(psu_fru.get(psu_sn_key)).strip() if psu_fru.get(psu_key) is not None: serial_number = psu_sn if psu_sn.strip() != "" else "N/A" break @@ -142,21 +147,21 @@ def get_psu_sn(self, index): def get_psu_pn(self, index): """ Get the product name of the psu - + :param index: An integer, 1-based index of the PSU. :return: Product name """ product_name = "N/A" psu_key = "PSU" + str(index) + " FRU" psu_pn_key = "Product Name" - + try: # Request and validate sensor's information self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU fru info. - for psu_fru in self.psu_info_list: - psu_pn = str(psu_fru.get(psu_pn_key)).strip() + for psu_fru in self.psu_info_list: + psu_pn = str(psu_fru.get(psu_pn_key)).strip() if psu_fru.get(psu_key) is not None: product_name = psu_pn if psu_pn.strip() != "" else "N/A" break @@ -165,3 +170,55 @@ def get_psu_pn(self, index): return "N/A" return product_name + + def get_all(self): + """ + Number: mandatory, max number of PSU, integer + PSU1, PSU2, ...: mandatory, PSU name, string + Present: mandatory for each PSU, present status, boolean, True for present, False for NOT present + PowerStatus: conditional, if PRESENT is True, power status of PSU,boolean, True for powered, False for NOT powered + PN, conditional, if PRESENT is True, PN of the PSU, string + SN, conditional, if PRESENT is True, SN of the PSU, string + """ + + # Init data + all_psu_dict = dict() + all_psu_dict["Number"] = self.get_num_psus() + psu_sn_key = "Serial Number" + psu_pn_key = "Product Name" + + # Request and validate sensor's information. + self.fru_status_list, self.psu_info_list = self.request_data() + + # Set PSU FRU data. + psu_info_dict = dict() + for psu_fru in self.psu_info_list: + psu_data = dict() + psu_data["PN"] = str(psu_fru.get(psu_pn_key)).strip( + ) if psu_fru.get(psu_pn_key) is not None else "N/A" + psu_data["SN"] = str(psu_fru.get(psu_sn_key)).strip( + ) if psu_fru.get(psu_sn_key) is not None else "N/A" + raw_key = [v for v in psu_fru.keys() if 'PSU' in v] + if len(raw_key) > 0: + psu_idx = int(re.findall('\d+', raw_key[0])[0]) + psu_info_dict[psu_idx] = psu_data + + # Set PSU status. + for fru_status in self.fru_status_list: + psu_status_dict = dict() + find_psu = [v for v in fru_status.keys() if "PSU" in v] + if len(find_psu) > 0: + psu_idx = int(re.findall('\d+', find_psu[0])[0]) + psu_ps_status = True if str(fru_status.get( + "Present")).strip() == "Present" else False + psu_pw_status = True if str(fru_status.get( + "Power Status")).strip() == "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"] + 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 8eca1d93af11..dca219bc6185 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 @@ -1,5 +1,10 @@ #!/usr/bin/env python +__author__ = 'Wirut G.' +__license__ = "GPL" +__version__ = "0.1.1" +__status__ = "Development" + import requests @@ -7,7 +12,7 @@ class SensorUtil(): """Platform-specific SensorUtil class""" def __init__(self): - self.sensor_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/sensors" + self.sensor_url = "http://240.1.1.1:8080/api/sys/sensors" self.sensor_info_list = None def request_data(self): @@ -240,3 +245,46 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return 0 return sensor_input_high_threshold + + def get_all(self): + + all_sensor_dict = dict() + + # 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. + del sensor_info["name"] + del sensor_info["Adapter"] + + # Set sensor data. + sensor_dict = dict() + for k, v in sensor_info.items(): + sensor_i_dict = dict() + sensor_data_str = v.split() + indices_h = [i for i, s in enumerate( + sensor_data_str) if 'max' in s or 'high' in s] + indices_l = [i for i, s in enumerate( + sensor_data_str) if 'min' in s or 'low' in s] + h_thres = float( + sensor_data_str[indices_h[0] + 2]) if len(indices_h) != 0 else 0 + l_thres = float( + sensor_data_str[indices_l[0] + 2]) if len(indices_l) != 0 else 0 + thres_unit = sensor_data_str[-1] + + sensor_i_dict["Type"] = self.input_type_selector( + sensor_data_str[1]) + sensor_i_dict["Value"] = float( + sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 + sensor_i_dict["HighThd"] = h_thres * \ + 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 + sensor_dict[k] = sensor_i_dict + + all_sensor_dict[sensor_name] = 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 d314e7080262..3d70a4646dc3 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 @@ -3,6 +3,7 @@ import re import requests + class FanUtil(): """Platform-specific FanUtil class""" @@ -13,7 +14,6 @@ def __init__(self): 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: @@ -25,27 +25,24 @@ 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 """ - num_fans = 10 + num_fans = 8 return num_fans - def get_fan_speed(self, fan_name): """ Get the current speed of the fan, the unit is "RPM" @@ -58,7 +55,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 @@ -67,7 +64,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)) @@ -78,8 +75,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, @@ -93,7 +89,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 @@ -102,7 +98,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)) @@ -113,7 +109,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, @@ -128,7 +123,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 @@ -137,7 +132,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)) @@ -148,13 +143,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) @@ -172,14 +166,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 @@ -192,8 +185,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() @@ -202,7 +195,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" @@ -222,9 +215,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 - \ No newline at end of file + + 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 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 55a10d1860d6..2a12cbbeec48 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 @@ -1,11 +1,13 @@ #!/usr/bin/env python import requests +import re try: from sonic_psu.psu_base import PsuBase except ImportError as e: - raise ImportError (str(e) + "- required module not found") + raise ImportError(str(e) + "- required module not found") + class PsuUtil(PsuBase): """Platform-specific PSUutil class""" @@ -14,11 +16,10 @@ def __init__(self): PsuBase.__init__(self) self.fru_status_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/fruid/status" self.psu_info_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/fruid/psu" - + self.fru_status_list = None self.psu_info_list = None - def request_data(self): # Reqest data from BMC if not exist. if self.fru_status_list is None or self.psu_info_list is None: @@ -30,7 +31,6 @@ def request_data(self): self.psu_info_list = psu_info_json.get('Information') return self.fru_status_list, self.psu_info_list - def get_num_psus(self): """ Retrieves the number of PSUs available on the device @@ -57,7 +57,7 @@ def get_psu_status(self, index): :param index: An integer, 1-based index of the PSU of which to query status :return: Boolean, True if PSU is operating properly, False if PSU is faulty """ - + # init data psu_key = "PSU" + str(index) psu_status_key = "Power Status" @@ -68,9 +68,9 @@ def get_psu_status(self, index): self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU power status. - for fru_status in self.fru_status_list: + for fru_status in self.fru_status_list: is_psu = fru_status.get(psu_key) - psu_status = str(fru_status.get(psu_status_key)).strip() + psu_status = str(fru_status.get(psu_status_key)).strip() if is_psu is not None and psu_status == "OK": psu_power_status = True @@ -99,9 +99,9 @@ def get_psu_presence(self, index): self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU present status. - for fru_status in self.fru_status_list: + for fru_status in self.fru_status_list: is_psu = fru_status.get(psu_key) - psu_status = str(fru_status.get(psu_presence_key)).strip() + psu_status = str(fru_status.get(psu_presence_key)).strip() if is_psu is not None and psu_status == "Present": psu_presence_status = True @@ -115,21 +115,21 @@ def get_psu_presence(self, index): def get_psu_sn(self, index): """ Get the serial number of the psu, - + :param index: An integer, 1-based index of the PSU. :return: Serial number """ serial_number = "N/A" psu_key = "PSU" + str(index) + " FRU" psu_sn_key = "Serial Number" - + try: # Request and validate sensor's information. self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU fru info. - for psu_fru in self.psu_info_list: - psu_sn = str(psu_fru.get(psu_sn_key)).strip() + for psu_fru in self.psu_info_list: + psu_sn = str(psu_fru.get(psu_sn_key)).strip() if psu_fru.get(psu_key) is not None: serial_number = psu_sn if psu_sn.strip() != "" else "N/A" break @@ -142,21 +142,21 @@ def get_psu_sn(self, index): def get_psu_pn(self, index): """ Get the product name of the psu - + :param index: An integer, 1-based index of the PSU. :return: Product name """ product_name = "N/A" psu_key = "PSU" + str(index) + " FRU" psu_pn_key = "Product Name" - + try: # Request and validate sensor's information self.fru_status_list, self.psu_info_list = self.request_data() # Get PSU fru info. - for psu_fru in self.psu_info_list: - psu_pn = str(psu_fru.get(psu_pn_key)).strip() + for psu_fru in self.psu_info_list: + psu_pn = str(psu_fru.get(psu_pn_key)).strip() if psu_fru.get(psu_key) is not None: product_name = psu_pn if psu_pn.strip() != "" else "N/A" break @@ -164,4 +164,56 @@ def get_psu_pn(self, index): except: return "N/A" - return product_name \ No newline at end of file + return product_name + + def get_all(self): + """ + Number: mandatory, max number of PSU, integer + PSU1, PSU2, ...: mandatory, PSU name, string + Present: mandatory for each PSU, present status, boolean, True for present, False for NOT present + PowerStatus: conditional, if PRESENT is True, power status of PSU,boolean, True for powered, False for NOT powered + PN, conditional, if PRESENT is True, PN of the PSU, string + SN, conditional, if PRESENT is True, SN of the PSU, string + """ + + # Init data + all_psu_dict = dict() + all_psu_dict["Number"] = self.get_num_psus() + psu_sn_key = "Serial Number" + psu_pn_key = "Product Name" + + # Request and validate sensor's information. + self.fru_status_list, self.psu_info_list = self.request_data() + + # Set PSU FRU data. + psu_info_dict = dict() + for psu_fru in self.psu_info_list: + psu_data = dict() + psu_data["PN"] = str(psu_fru.get(psu_pn_key)).strip( + ) if psu_fru.get(psu_pn_key) is not None else "N/A" + psu_data["SN"] = str(psu_fru.get(psu_sn_key)).strip( + ) if psu_fru.get(psu_sn_key) is not None else "N/A" + raw_key = [v for v in psu_fru.keys() if 'PSU' in v] + if len(raw_key) > 0: + psu_idx = int(re.findall('\d+', raw_key[0])[0]) + psu_info_dict[psu_idx] = psu_data + + # Set PSU status. + for fru_status in self.fru_status_list: + psu_status_dict = dict() + find_psu = [v for v in fru_status.keys() if "PSU" in v] + if len(find_psu) > 0: + psu_idx = int(re.findall('\d+', find_psu[0])[0]) + psu_ps_status = True if str(fru_status.get( + "Present")).strip() == "Present" else False + psu_pw_status = True if str(fru_status.get( + "Power Status")).strip() == "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"] + 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 8eca1d93af11..2f3e5a740682 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 @@ -240,3 +240,46 @@ def get_sensor_input_high_threshold(self, sensor_index, input_index): return 0 return sensor_input_high_threshold + + def get_all(self): + + all_sensor_dict = dict() + + # 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. + del sensor_info["name"] + del sensor_info["Adapter"] + + # Set sensor data. + sensor_dict = dict() + for k, v in sensor_info.items(): + sensor_i_dict = dict() + sensor_data_str = v.split() + indices_h = [i for i, s in enumerate( + sensor_data_str) if 'max' in s or 'high' in s] + indices_l = [i for i, s in enumerate( + sensor_data_str) if 'min' in s or 'low' in s] + h_thres = float( + sensor_data_str[indices_h[0] + 2]) if len(indices_h) != 0 else 0 + l_thres = float( + sensor_data_str[indices_l[0] + 2]) if len(indices_l) != 0 else 0 + thres_unit = sensor_data_str[-1] + + sensor_i_dict["Type"] = self.input_type_selector( + sensor_data_str[1]) + sensor_i_dict["Value"] = float( + sensor_data_str[0]) if sensor_data_str[0] != "N/A" else 0 + sensor_i_dict["HighThd"] = h_thres * \ + 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 + sensor_dict[k] = sensor_i_dict + + all_sensor_dict[sensor_name] = sensor_dict + + return all_sensor_dict diff --git a/platform/broadcom/sonic-platform-modules-cel b/platform/broadcom/sonic-platform-modules-cel index 81d4911fcd2a..e70feb83559b 160000 --- a/platform/broadcom/sonic-platform-modules-cel +++ b/platform/broadcom/sonic-platform-modules-cel @@ -1 +1 @@ -Subproject commit 81d4911fcd2a3bbe24949092458ae6ad4d226b89 +Subproject commit e70feb83559b8bbddb5752cfe05b14e41e5c0c9c From 57cce2d69309b42bf49b5647a20f5559c474ab12 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Fri, 30 Nov 2018 13:45:18 +0700 Subject: [PATCH 4/5] Update install script to disable sync_bmc.timer by default. --- platform/broadcom/sonic-platform-modules-cel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/broadcom/sonic-platform-modules-cel b/platform/broadcom/sonic-platform-modules-cel index e70feb83559b..9e59e1ee8f41 160000 --- a/platform/broadcom/sonic-platform-modules-cel +++ b/platform/broadcom/sonic-platform-modules-cel @@ -1 +1 @@ -Subproject commit e70feb83559b8bbddb5752cfe05b14e41e5c0c9c +Subproject commit 9e59e1ee8f41c7d25f30502546c7469fcc73a305 From 7aa0923e18c1543abc0dfe312460ad765414e7da Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Fri, 30 Nov 2018 13:46:35 +0700 Subject: [PATCH 5/5] Update eth0.4088 vlan to support ipv4. --- platform/broadcom/sonic-platform-modules-cel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/broadcom/sonic-platform-modules-cel b/platform/broadcom/sonic-platform-modules-cel index 9e59e1ee8f41..addeda9549b0 160000 --- a/platform/broadcom/sonic-platform-modules-cel +++ b/platform/broadcom/sonic-platform-modules-cel @@ -1 +1 @@ -Subproject commit 9e59e1ee8f41c7d25f30502546c7469fcc73a305 +Subproject commit addeda9549b04f59f1a1bd32f18f2a76671d4ed7