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 ea2b920afef..33866a6f937 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 @@ -221,7 +221,7 @@ def get_fans_name_list(self): for x in range(1, n_fan + 1): f_index = int(round(float(x)/2)) pos = 1 if x % 2 else 2 - fan_name = 'FAN{}-{}'.format(f_index, pos) + fan_name = 'FAN{}_{}'.format(f_index, pos) fan_names.append(fan_name) return fan_names @@ -291,7 +291,7 @@ 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_name = 'FAN{}-{}'.format(f_index, pos) + 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/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py new file mode 100644 index 00000000000..32a509202b9 --- /dev/null +++ b/device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/fwmgrutil.py @@ -0,0 +1,130 @@ +# fwmgrutil.py +# +# Platform-specific firmware management interface for SONiC +# + +import subprocess +import requests + +try: + from sonic_fwmgr.fwgmr_base import FwMgrUtilBase +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + +class FwMgrUtil(FwMgrUtilBase): + + """Platform-specific FwMgrUtil class""" + + def __init__(self): + self.platform_name = "AS1332h" + self.onie_config_file = "/host/machine.conf" + self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc" + self.onie_config_file = "/host/machine.conf" + self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name + self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name + self.switchboard_cpld1_path = "/sys/devices/platform/%s.switchboard/CPLD1/getreg" % self.platform_name + self.switchboard_cpld2_path = "/sys/devices/platform/%s.switchboard/CPLD2/getreg" % self.platform_name + + def __get_register_value(self, path, register): + cmd = "echo {1} > {0}; cat {0}".format(path, register) + p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err is not '': + return 'None' + else: + return raw_data.strip() + + def get_bmc_version(self): + """Get BMC version from SONiC + :returns: version string + + """ + bmc_version = "None" + + bmc_version_key = "OpenBMC Version" + bmc_info_req = requests.get(self.bmc_info_url) + bmc_info_json = bmc_info_req.json() + bmc_info = bmc_info_json.get('Information') + bmc_version = bmc_info.get(bmc_version_key) + + return bmc_version + + def get_cpld_version(self): + """Get CPLD version from SONiC + :returns: dict like {'CPLD_1': version_string, 'CPLD_2': version_string} + """ + + CPLD_B = self.__get_register_value(self.cpldb_version_path, '0xA100') + CPLD_C = self.__get_register_value(self.cpldb_version_path, '0xA1E0') + CPLD_1 = self.__get_register_value(self.switchboard_cpld1_path, '0x00') + CPLD_2 = self.__get_register_value(self.switchboard_cpld2_path, '0x00') + + CPLD_B = 'None' if CPLD_B is 'None' else "{}.{}".format(int(CPLD_B[2],16),int(CPLD_B[3],16)) + CPLD_C = 'None' if CPLD_C is 'None' else "{}.{}".format(int(CPLD_C[2],16),int(CPLD_C[3],16)) + CPLD_1 = 'None' if CPLD_1 is 'None' else "{}.{}".format(int(CPLD_1[2],16),int(CPLD_1[3],16)) + CPLD_2 = 'None' if CPLD_2 is 'None' else "{}.{}".format(int(CPLD_2[2],16),int(CPLD_2[3],16)) + + cpld_version_dict = {} + cpld_version_dict.update({'CPLD_B':CPLD_B}) + cpld_version_dict.update({'CPLD_C':CPLD_C}) + cpld_version_dict.update({'CPLD_1':CPLD_1}) + cpld_version_dict.update({'CPLD_2':CPLD_2}) + + return cpld_version_dict + + def get_bios_version(self): + """Get BIOS version from SONiC + :returns: version string + + """ + bios_version = 'None' + + p = subprocess.Popen( + ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) + raw_data = str(p.communicate()[0]) + raw_data_list = raw_data.split("\n") + bios_version = raw_data_list[0] if len( + raw_data_list) == 1 else raw_data_list[-2] + + return bios_version + + def get_onie_version(self): + """Get ONiE version from SONiC + :returns: version string + + """ + onie_verison = 'None' + + onie_version_keys = "onie_version" + onie_config_file = open(self.onie_config_file, "r") + for line in onie_config_file.readlines(): + if onie_version_keys in line: + onie_version_raw = line.split('=') + onie_verison = onie_version_raw[1].strip() + break + return onie_verison + + def get_pcie_version(self): + """Get PCiE version from SONiC + :returns: version string + """ + cmd = "sudo bcmcmd 'pciephy fw version'" + p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err is not '': + return 'None' + else: + lines = raw_data.split('\n') + version = lines[0].split(':')[1].strip() + return str(version) + + def get_fpga_version(self): + """Get FPGA version from SONiC + :returns: version string + + """ + version = self.__get_register_value(self.fpga_version_path, '0x00') + if version is not 'None': + version = "{}.{}".format(int(version[2:][:4],16), int(version[2:][4:],16)) + return str(version) 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 2f2f415698d..bb526aa8a17 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 @@ -2,7 +2,7 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.1" +__version__ = "0.2.0" __status__ = "Development" import requests @@ -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 """ @@ -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 """ @@ -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 @@ -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 """ @@ -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 """ @@ -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 high_threshold :return: float sensor_input_high_threshold """ @@ -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. @@ -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 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 ea2b920afef..33866a6f937 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 @@ -221,7 +221,7 @@ def get_fans_name_list(self): for x in range(1, n_fan + 1): f_index = int(round(float(x)/2)) pos = 1 if x % 2 else 2 - fan_name = 'FAN{}-{}'.format(f_index, pos) + fan_name = 'FAN{}_{}'.format(f_index, pos) fan_names.append(fan_name) return fan_names @@ -291,7 +291,7 @@ 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_name = 'FAN{}-{}'.format(f_index, pos) + 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/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py new file mode 100644 index 00000000000..fcd28b028a9 --- /dev/null +++ b/device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/fwmgrutil.py @@ -0,0 +1,130 @@ +# fwmgrutil.py +# +# Platform-specific firmware management interface for SONiC +# + +import subprocess +import requests + +try: + from sonic_fwmgr.fwgmr_base import FwMgrUtilBase +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + +class FwMgrUtil(FwMgrUtilBase): + + """Platform-specific FwMgrUtil class""" + + def __init__(self): + self.platform_name = "AS1348f8h" + self.onie_config_file = "/host/machine.conf" + self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc" + self.onie_config_file = "/host/machine.conf" + self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name + self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name + self.switchboard_cpld1_path = "/sys/devices/platform/%s.switchboard/CPLD1/getreg" % self.platform_name + self.switchboard_cpld2_path = "/sys/devices/platform/%s.switchboard/CPLD2/getreg" % self.platform_name + + def __get_register_value(self, path, register): + cmd = "echo {1} > {0}; cat {0}".format(path, register) + p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err is not '': + return 'None' + else: + return raw_data.strip() + + def get_bmc_version(self): + """Get BMC version from SONiC + :returns: version string + + """ + bmc_version = "None" + + bmc_version_key = "OpenBMC Version" + bmc_info_req = requests.get(self.bmc_info_url) + bmc_info_json = bmc_info_req.json() + bmc_info = bmc_info_json.get('Information') + bmc_version = bmc_info.get(bmc_version_key) + + return bmc_version + + def get_cpld_version(self): + """Get CPLD version from SONiC + :returns: dict like {'CPLD_1': version_string, 'CPLD_2': version_string} + """ + + CPLD_B = self.__get_register_value(self.cpldb_version_path, '0xA100') + CPLD_C = self.__get_register_value(self.cpldb_version_path, '0xA1E0') + CPLD_1 = self.__get_register_value(self.switchboard_cpld1_path, '0x00') + CPLD_2 = self.__get_register_value(self.switchboard_cpld2_path, '0x00') + + CPLD_B = 'None' if CPLD_B is 'None' else "{}.{}".format(int(CPLD_B[2],16),int(CPLD_B[3],16)) + CPLD_C = 'None' if CPLD_C is 'None' else "{}.{}".format(int(CPLD_C[2],16),int(CPLD_C[3],16)) + CPLD_1 = 'None' if CPLD_1 is 'None' else "{}.{}".format(int(CPLD_1[2],16),int(CPLD_1[3],16)) + CPLD_2 = 'None' if CPLD_2 is 'None' else "{}.{}".format(int(CPLD_2[2],16),int(CPLD_2[3],16)) + + cpld_version_dict = {} + cpld_version_dict.update({'CPLD_B':CPLD_B}) + cpld_version_dict.update({'CPLD_C':CPLD_C}) + cpld_version_dict.update({'CPLD_1':CPLD_1}) + cpld_version_dict.update({'CPLD_2':CPLD_2}) + + return cpld_version_dict + + def get_bios_version(self): + """Get BIOS version from SONiC + :returns: version string + + """ + bios_version = 'None' + + p = subprocess.Popen( + ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) + raw_data = str(p.communicate()[0]) + raw_data_list = raw_data.split("\n") + bios_version = raw_data_list[0] if len( + raw_data_list) == 1 else raw_data_list[-2] + + return bios_version + + def get_onie_version(self): + """Get ONiE version from SONiC + :returns: version string + + """ + onie_verison = 'None' + + onie_version_keys = "onie_version" + onie_config_file = open(self.onie_config_file, "r") + for line in onie_config_file.readlines(): + if onie_version_keys in line: + onie_version_raw = line.split('=') + onie_verison = onie_version_raw[1].strip() + break + return onie_verison + + def get_pcie_version(self): + """Get PCiE version from SONiC + :returns: version string + """ + cmd = "sudo bcmcmd 'pciephy fw version'" + p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err is not '': + return 'None' + else: + lines = raw_data.split('\n') + version = lines[0].split(':')[1].strip() + return str(version) + + def get_fpga_version(self): + """Get FPGA version from SONiC + :returns: version string + + """ + version = self.__get_register_value(self.fpga_version_path, '0x00') + if version is not 'None': + version = "{}.{}".format(int(version[2:][:4],16), int(version[2:][4:],16)) + return str(version) 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 2f2f415698d..bb526aa8a17 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 @@ -2,7 +2,7 @@ __author__ = 'Wirut G.' __license__ = "GPL" -__version__ = "0.1.1" +__version__ = "0.2.0" __status__ = "Development" import requests @@ -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 """ @@ -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 """ @@ -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 @@ -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 """ @@ -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 """ @@ -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 high_threshold :return: float sensor_input_high_threshold """ @@ -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. @@ -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 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 e32c2065596..d3e8334271b 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 @@ -216,7 +216,7 @@ def get_fans_name_list(self): for x in range(1, n_fan + 1): f_index = int(round(float(x)/2)) pos = 1 if x % 2 else 2 - fan_name = 'FAN{}-{}'.format(f_index, pos) + fan_name = 'FAN{}_{}'.format(f_index, pos) fan_names.append(fan_name) return fan_names @@ -286,7 +286,7 @@ 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_name = 'FAN{}-{}'.format(f_index, pos) + fan_name = 'FAN{}_{}'.format(f_index, pos) all_fan_dict[fan_name] = fan_dict break diff --git a/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py new file mode 100644 index 00000000000..8c7029b3246 --- /dev/null +++ b/device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fwmgrutil.py @@ -0,0 +1,138 @@ +# fwmgrutil.py +# +# Platform-specific firmware management interface for SONiC +# + +import subprocess +import requests + +try: + from sonic_fwmgr.fwgmr_base import FwMgrUtilBase +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + +class FwMgrUtil(FwMgrUtilBase): + + """Platform-specific FwMgrUtil class""" + + def __init__(self): + self.platform_name = "AS23128h" + self.onie_config_file = "/host/machine.conf" + self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc" + self.onie_config_file = "/host/machine.conf" + self.cpldb_version_path = "/sys/devices/platform/%s.cpldb/getreg" % self.platform_name + self.fpga_version_path = "/sys/devices/platform/%s.switchboard/FPGA/getreg" % self.platform_name + self.switchboard_cpld1_path = "/sys/devices/platform/%s.switchboard/CPLD1/getreg" % self.platform_name + self.switchboard_cpld2_path = "/sys/devices/platform/%s.switchboard/CPLD2/getreg" % self.platform_name + self.switchboard_cpld3_path = "/sys/devices/platform/%s.switchboard/CPLD3/getreg" % self.platform_name + self.switchboard_cpld4_path = "/sys/devices/platform/%s.switchboard/CPLD4/getreg" % self.platform_name + + def __get_register_value(self, path, register): + cmd = "echo {1} > {0}; cat {0}".format(path, register) + p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err is not '': + return 'None' + else: + return raw_data.strip() + + def get_bmc_version(self): + """Get BMC version from SONiC + :returns: version string + + """ + bmc_version = "None" + + bmc_version_key = "OpenBMC Version" + bmc_info_req = requests.get(self.bmc_info_url) + bmc_info_json = bmc_info_req.json() + bmc_info = bmc_info_json.get('Information') + bmc_version = bmc_info.get(bmc_version_key) + + return bmc_version + + def get_cpld_version(self): + """Get CPLD version from SONiC + :returns: dict like {'CPLD_1': version_string, 'CPLD_2': version_string} + """ + + CPLD_B = self.__get_register_value(self.cpldb_version_path, '0xA100') + CPLD_C = self.__get_register_value(self.cpldb_version_path, '0xA1E0') + CPLD_1 = self.__get_register_value(self.switchboard_cpld1_path, '0x00') + CPLD_2 = self.__get_register_value(self.switchboard_cpld2_path, '0x00') + CPLD_3 = self.__get_register_value(self.switchboard_cpld3_path, '0x00') + CPLD_4 = self.__get_register_value(self.switchboard_cpld4_path, '0x00') + + CPLD_B = 'None' if CPLD_B is 'None' else "{}.{}".format(int(CPLD_B[2],16),int(CPLD_B[3],16)) + CPLD_C = 'None' if CPLD_C is 'None' else "{}.{}".format(int(CPLD_C[2],16),int(CPLD_C[3],16)) + CPLD_1 = 'None' if CPLD_1 is 'None' else "{}.{}".format(int(CPLD_1[2],16),int(CPLD_1[3],16)) + CPLD_2 = 'None' if CPLD_2 is 'None' else "{}.{}".format(int(CPLD_2[2],16),int(CPLD_2[3],16)) + CPLD_3 = 'None' if CPLD_3 is 'None' else "{}.{}".format(int(CPLD_3[2],16),int(CPLD_3[3],16)) + CPLD_4 = 'None' if CPLD_4 is 'None' else "{}.{}".format(int(CPLD_4[2],16),int(CPLD_4[3],16)) + + cpld_version_dict = {} + cpld_version_dict.update({'CPLD_B':CPLD_B}) + cpld_version_dict.update({'CPLD_C':CPLD_C}) + cpld_version_dict.update({'CPLD_1':CPLD_1}) + cpld_version_dict.update({'CPLD_2':CPLD_2}) + cpld_version_dict.update({'CPLD_3':CPLD_3}) + cpld_version_dict.update({'CPLD_4':CPLD_4}) + + return cpld_version_dict + + def get_bios_version(self): + """Get BIOS version from SONiC + :returns: version string + + """ + bios_version = 'None' + + p = subprocess.Popen( + ["sudo", "dmidecode", "-s", "bios-version"], stdout=subprocess.PIPE) + raw_data = str(p.communicate()[0]) + raw_data_list = raw_data.split("\n") + bios_version = raw_data_list[0] if len( + raw_data_list) == 1 else raw_data_list[-2] + + return bios_version + + def get_onie_version(self): + """Get ONiE version from SONiC + :returns: version string + + """ + onie_verison = 'None' + + onie_version_keys = "onie_version" + onie_config_file = open(self.onie_config_file, "r") + for line in onie_config_file.readlines(): + if onie_version_keys in line: + onie_version_raw = line.split('=') + onie_verison = onie_version_raw[1].strip() + break + return onie_verison + + def get_pcie_version(self): + """Get PCiE version from SONiC + :returns: version string + """ + cmd = "sudo bcmcmd 'pciephy fw version'" + p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + raw_data, err = p.communicate() + if err is not '': + return 'None' + else: + lines = raw_data.split('\n') + version = lines[0].split(':')[1].strip() + return str(version) + + def get_fpga_version(self): + """Get FPGA version from SONiC + :returns: version string + + """ + version = self.__get_register_value(self.fpga_version_path, '0x00') + if version is not 'None': + version = "{}.{}".format(int(version[2:][:4],16), int(version[2:][4:],16)) + return str(version) 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 4f33d03b205..d98812bc30f 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 @@ -1,5 +1,10 @@ #!/usr/bin/env python +__author__ = 'Wirut G.' +__license__ = "GPL" +__version__ = "0.2.0" +__status__ = "Development" + import requests @@ -28,8 +33,73 @@ 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-25-58": "PSU1", + "dps1100-i2c-26-58": "PSU2", + "dps1100-i2c-28-58": "PSU3", + "dps1100-i2c-29-58": "PSU4", + "fancpld-i2c-8-0d": "FAN", + "isl68137-i2c-17-60": "ISL68137" + }.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 'isl68137' in sensor_name: + input_name = { + "iin": self.sensor_name + "_CURR_I", + "iout2": self.sensor_name + "_CURR_O", + "pin": self.sensor_name + "_POWER_I", + "pout2": self.sensor_name + "_POWER_O", + "vin": self.sensor_name + "_VOL_I", + "vout2": self.sensor_name + "_VOL_O", + "temp1": self.sensor_name + "_TEMP1" + }.get(input_name, input_name) + + elif 'tmp75' in sensor_name or 'max31730' in sensor_name: + input_name = { + "tmp75-i2c-7-4f": "BASEBOARD_INLET_RIGHT", + "tmp75-i2c-7-4e": "BASEBOARD_INLET_CENTER", + "tmp75-i2c-7-4d": "SWITCH_OUTLET", + "tmp75-i2c-31-48": "PSU_INLET_LEFT", + "tmp75-i2c-31-49": "PSU_INLET_RIGHT", + "tmp75-i2c-39-48": "FANBOARD_LEFT", + "tmp75-i2c-39-49": "FANBOARD_RIGHT", + "tmp75-i2c-42-48": "LINECARD_TOP_RIGHT", + "tmp75-i2c-42-49": "LINECARD_TOP_LEFT", + "tmp75-i2c-43-48": "LINECARD_BOTTOM_RIGHT", + "tmp75-i2c-43-49": "LINECARD_BOTTOM_LEFT", + "max31730-i2c-7-4c": "SWITCH_REMOTE_" + input_name + }.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 """ @@ -48,7 +118,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 """ @@ -68,7 +138,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 @@ -90,7 +160,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 """ @@ -115,7 +185,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 """ @@ -170,7 +240,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 high_threshold :return: float sensor_input_high_threshold """ @@ -248,7 +318,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. @@ -278,8 +347,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 diff --git a/platform/broadcom/sonic-platform-modules-cel b/platform/broadcom/sonic-platform-modules-cel index 460f57e94d6..8e7c7689db1 160000 --- a/platform/broadcom/sonic-platform-modules-cel +++ b/platform/broadcom/sonic-platform-modules-cel @@ -1 +1 @@ -Subproject commit 460f57e94d6954f6981ceeb52ea8e12a7fc8a3d2 +Subproject commit 8e7c7689db1759c1e2f03d0ada101c50a1fc4c2f diff --git a/src/sonic-device-data/tests/permitted_list b/src/sonic-device-data/tests/permitted_list index 29570987a09..1275fe1cf7c 100644 --- a/src/sonic-device-data/tests/permitted_list +++ b/src/sonic-device-data/tests/permitted_list @@ -150,4 +150,6 @@ pbmp_gport_stack.0 reglist_enable cls_cmd_daemon serdes_lane_config_dfe -serdes_fec_enable \ No newline at end of file +serdes_fec_enable +port_fec +serdes_tx_taps_ce \ No newline at end of file