def get_description(self): """ Retrieves the description of the module Returns: string: The description of the module """ channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_CHASSIS_SERVICE) if not channel or not stub: return 'Unavailable' platform_module_type = self.get_platform_type() ret, response = nokia_common.try_grpc( stub.GetModuleName, platform_ndk_pb2.ReqModuleInfoPb(module_type=platform_module_type, hw_slot=self.get_slot())) nokia_common.channel_shutdown(channel) if ret is False: return 'Unavailable' description = response.name if response.name in DESCRIPTION_MAPPING: description = DESCRIPTION_MAPPING[response.name] if platform_module_type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_CONTROL: if nokia_common.get_chassis_type( ) == platform_ndk_pb2.HwChassisType.HW_CHASSIS_TYPE_IXR6: description = "Nokia-IXR7250-SUP-6" else: description = "Nokia-IXR7250-SUP-10" return description
def execute(self, thermal_info_dict): """ Publish thermal information to platform :param thermal_info_dict: A dictionary stores all thermal information. :return: """ from .thermal_infos import ChassisInfo from .thermal_infos import ThermalInfo if ChassisInfo.INFO_NAME in thermal_info_dict: # chassis_info_obj = thermal_info_dict[ChassisInfo.INFO_NAME] # chassis = chassis_info_obj.get_chassis() pass else: return if ThermalInfo.INFO_NAME in thermal_info_dict: thermal_info_obj = thermal_info_dict[ThermalInfo.INFO_NAME] for slot, lc_info in thermal_info_obj.lc_thermal_dict.items(): update_hwslot_temp = platform_ndk_pb2.UpdateTempInfoPb( slot_num=slot, current_temp=int(lc_info['curr_temp']), min_temp=int(lc_info['min_temp']), max_temp=int(lc_info['max_temp']), margin=int(lc_info['margin_temp'])) channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_THERMAL_SERVICE) if not channel or not stub: continue ret, response = nokia_common.try_grpc(stub.UpdateThermalHwSlot, platform_ndk_pb2.ReqTempParamsPb(hwslot_temp=update_hwslot_temp)) nokia_common.channel_shutdown(channel)
def _get_transceiver_status(self): # logger.log_error("Transceiver multi-status") op_type = platform_ndk_pb2.ReqSfpOpsType.SFP_OPS_GET_MPORT_STATUS port_list = [] channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_XCVR_SERVICE) if not channel or not stub: return port_list ret, response = nokia_common.try_grpc( stub.GetSfpPresence, platform_ndk_pb2.ReqSfpOpsPb(type=op_type, hw_port_id_begin=self.port_begin, hw_port_id_end=self.port_end)) nokia_common.channel_shutdown(channel) if ret is False: return port_list # logger.log_error("Transceiver multi-status-done") port_list = [] mport_msg = response.sfp_mstatus i = 0 num_ports = len(mport_msg.port_status) for i in range(num_ports): port_status = mport_msg.port_status[i] port_list.append(port_status.status) # logger.log_error("Transceiver multi-status response with len{}".format(num_ports)) return port_list
def _get_fantray_list(self): if not self.is_cpm: return [] channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_FAN_SERVICE) if not channel or not stub: return ret, response = nokia_common.try_grpc(stub.GetFanNum, platform_ndk_pb2.ReqFanTrayOpsPb()) nokia_common.channel_shutdown(channel) if ret is False: return self.num_fantrays = response.fan_nums.num_fantrays fan_index = 0 for drawer_index in range(self.num_fantrays): fan_drawer = FanDrawer(drawer_index) fan_drawer.set_maximum_consumed_power(self.fantray_power) fan = Fan(fan_index, drawer_index, False, self.fan_stub) fan_drawer._fan_list.append(fan) fan_index = fan_index + 1 self._fan_drawer_list.append(fan_drawer) return self._fan_drawer_list
def get_presence(self): """ Retrieves the presence of the Power Supply Unit (PSU) Returns: bool: True if PSU is present, False if not """ status = False if self.is_cpm == 0: return status channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_PSU_SERVICE) if not channel or not stub: return status ret, response = nokia_common.try_grpc( stub.GetPsuPresence, platform_ndk_pb2.ReqPsuInfoPb(psu_idx=self.index)) nokia_common.channel_shutdown(channel) if ret is False: return status status = response.psu_presence return status
def get_status(self): """ Retrieves the operational status of the PSU Returns: bool: True if PSU is operating properly, False if not """ status = False if self.is_cpm == 0: return status channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_PSU_SERVICE) if not channel or not stub: return status ret, response = nokia_common.try_grpc( stub.GetPsuStatus, platform_ndk_pb2.ReqPsuInfoPb(psu_idx=self.index)) nokia_common.channel_shutdown(channel) if ret is False: return status status = response.psu_status return status
def get_serial(self): """ Retrieves the serial number of the PSU Returns: string: Serial number of PSU """ if self.is_cpm == 0: return 'N/A' if self.serial != 'Unknown': return self.serial channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_PSU_SERVICE) if not channel or not stub: return nokia_common.NOKIA_INVALID_STRING ret, response = nokia_common.try_grpc( stub.GetPsuSerial, platform_ndk_pb2.ReqPsuInfoPb(psu_idx=self.index)) nokia_common.channel_shutdown(channel) if ret is False: return nokia_common.NOKIA_INVALID_STRING self.product = response.fru_info.product_name self.model = response.fru_info.part_number self.serial = response.fru_info.serial_number return self.serial
def is_midplane_reachable(self): channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_CHASSIS_SERVICE) if not channel or not stub: return False ret, response = nokia_common.try_grpc( stub.IsMidplaneReachable, platform_ndk_pb2.ReqModuleInfoPb(hw_slot=self.get_slot())) nokia_common.channel_shutdown(channel) if ret is False: return False return response.midplane_status
def set_status_led(self, color): led_type = platform_ndk_pb2.ReqLedType.LED_TYPE_BOARD_STATUS _led_info = nokia_common.led_color_to_info(color) channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_LED_SERVICE) if not channel or not stub: return False ret, response = nokia_common.try_grpc(stub.SetLed, platform_ndk_pb2.ReqLedInfoPb(led_type=led_type, led_info=_led_info)) nokia_common.channel_shutdown(channel) if ret is False: return False return True
def get_temperature(self): channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_PSU_SERVICE) if not channel or not stub: return self.ambient_temperature ret, response = nokia_common.try_grpc( stub.GetPsuTemperature, platform_ndk_pb2.ReqPsuInfoPb(psu_idx=self.index)) nokia_common.channel_shutdown(channel) if ret is False: return self.ambient_temperature self.ambient_temperature = response.ambient_temp return self.ambient_temperature
def get_voltage(self): channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_PSU_SERVICE) if not channel or not stub: return self.output_voltage ret, response = nokia_common.try_grpc( stub.GetPsuOutputVoltage, platform_ndk_pb2.ReqPsuInfoPb(psu_idx=self.index)) nokia_common.channel_shutdown(channel) if ret is False: return self.output_voltage self.output_voltage = response.output_voltage return self.output_voltage
def get_status_led(self): color = Chassis.STATUS_LED_COLOR_OFF led_type = platform_ndk_pb2.ReqLedType.LED_TYPE_BOARD_STATUS channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_LED_SERVICE) if not channel or not stub: return color ret, response = nokia_common.try_grpc(stub.GetLed, platform_ndk_pb2.ReqLedInfoPb(led_type=led_type)) nokia_common.channel_shutdown(channel) if ret is False: return color color = nokia_common.led_info_to_color(response.led_get.led_info[0]) return color
def get_module_index(self, module_name): if not self.is_modular_chassis(): return -1 # For IMM on chassis, return supervisor-index as 0 and self index as 1 if not self.is_cpm: if module_name.startswith(ModuleBase.MODULE_TYPE_SUPERVISOR): return 0 else: return 1 # For CPM on chassis module_index = -1 channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_CHASSIS_SERVICE) if not channel or not stub: return module_index ret, response = nokia_common.try_grpc(stub.GetChassisProperties, platform_ndk_pb2.ReqModuleInfoPb()) nokia_common.channel_shutdown(channel) if ret is False: return module_index for property_index in range(len(response.chassis_property.hw_property)): hw_property = response.chassis_property.hw_property[property_index] if hw_property.module_type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_CONTROL: # Single CPM is supported in chassis num_control_cards = 1 elif hw_property.module_type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_LINE: num_line_cards = hw_property.max_num # elif hw_property.module_type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_FABRIC: # num_fabric_cards = hw_property.max_num if module_name.startswith(ModuleBase.MODULE_TYPE_SUPERVISOR): module_index = 0 elif module_name.startswith(ModuleBase.MODULE_TYPE_LINE): import re parse_nums = re.findall(r'\d+', module_name) module_number = int(parse_nums[0]) module_index = num_control_cards + int(module_number) elif module_name.startswith(ModuleBase.MODULE_TYPE_FABRIC): import re parse_nums = re.findall(r'\d+', module_name) module_number = int(parse_nums[0]) module_index = num_control_cards + num_line_cards + int(module_number) return module_index
def _get_component_list(self): channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_FIRMWARE_SERVICE) if not channel or not stub: return ret, response = nokia_common.try_grpc(stub.HwFirmwareGetComponents, platform_ndk_pb2.ReqHwFirmwareInfoPb()) nokia_common.channel_shutdown(channel) if ret is False: return for i in range(len(response.firmware_info.component)): hw_dev = response.firmware_info.component[i] component = Component(i, hw_dev.dev_type, hw_dev.dev_name, hw_dev.dev_desc, self.firmware_stub) self._component_list.append(component)
def __init__(self): led_type = platform_ndk_pb2.ReqLedType.LED_TYPE_PORT led_info = nokia_common.led_color_to_info( DeviceBase.STATUS_LED_COLOR_OFF) channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_LED_SERVICE) if not channel or not stub: return port_idx = platform_ndk_pb2.ReqLedIndexPb( start_idx=nokia_common.NOKIA_FP_START_PORTID, end_idx=nokia_common.NOKIA_FP_END_PORTID) ret, response = nokia_common.try_grpc( stub.SetLed, platform_ndk_pb2.ReqLedInfoPb(led_type=led_type, led_idx=port_idx, led_info=led_info)) nokia_common.channel_shutdown(channel)
def get_midplane_ip(self): """ Retrieves the midplane IP-address of the module in a modular chassis """ channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_CHASSIS_SERVICE) if not channel or not stub: return self.midplane_ip ret, response = nokia_common.try_grpc( stub.GetMidplaneIP, platform_ndk_pb2.ReqModuleInfoPb(hw_slot=self.get_slot())) nokia_common.channel_shutdown(channel) if ret is False: return self.midplane_ip self.midplane_ip = response.midplane_ip return response.midplane_ip
def get_firmware_version(self): """ Retrieves the firmware version of the component Returns: A string containing the firmware version of the component """ channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_FIRMWARE_SERVICE) if not channel or not stub: return nokia_common.NOKIA_INVALID_FIRMWARE_VERSION ret, response = nokia_common.try_grpc(stub.ReqHwFirmwareVersion, platform_ndk_pb2.ReqHwFirmwareInfoPb(dev_type=self.dev_type)) nokia_common.channel_shutdown(channel) if ret is False: return nokia_common.NOKIA_INVALID_FIRMWARE_VERSION return response.version
def get_status_master_led(cls): """ Get the PSU master led register with the input color """ color = Psu.STATUS_LED_COLOR_OFF led_type = platform_ndk_pb2.ReqLedType.LED_TYPE_MASTER_PSU_STATUS channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_LED_SERVICE) if not channel or not stub: return color ret, response = nokia_common.try_grpc( stub.GetLed, platform_ndk_pb2.ReqLedInfoPb(led_type=led_type)) nokia_common.channel_shutdown(channel) if ret is False: return color color = nokia_common.led_info_to_color(response.led_get.led_info[0]) return color
def set_status_master_led(cls, color): """ Set the PSU master led register with the input color """ cls.psu_master_led_color = color led_type = platform_ndk_pb2.ReqLedType.LED_TYPE_MASTER_PSU_STATUS _led_info = nokia_common.led_color_to_info(color) channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_LED_SERVICE) if not channel or not stub: return False ret, response = nokia_common.try_grpc( stub.SetLed, platform_ndk_pb2.ReqLedInfoPb(led_type=led_type, led_info=_led_info)) nokia_common.channel_shutdown(channel) return True
def _get_psu_list(self): if not self.is_cpm: return [] channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_PSU_SERVICE) if not channel or not stub: return ret, response = nokia_common.try_grpc(stub.GetPsuNum, platform_ndk_pb2.ReqPsuInfoPb()) nokia_common.channel_shutdown(channel) if ret is False: return self.num_psus = response.num_psus for i in range(self.num_psus): psu = Psu(i, self.psu_stub) self._psu_list.append(psu) return self._psu_list
def get_maximum_supplied_power(self): """ Retrieves the maximum output power in watts of a power supply unit (PSU) """ if self.is_cpm == 0: return 0.0 channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_PSU_SERVICE) if not channel or not stub: return self.max_supplied_power ret, response = nokia_common.try_grpc( stub.GetPsuMaximumPower, platform_ndk_pb2.ReqPsuInfoPb(psu_idx=self.index)) nokia_common.channel_shutdown(channel) if ret is False: return self.max_supplied_power self.max_supplied_power = response.supplied_power return self.max_supplied_power
def get_voltage_low_threshold(self): if self.min_voltage != 0.0: return self.min_voltage channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_PSU_SERVICE) if not channel or not stub: return self.min_voltage ret, response = nokia_common.try_grpc( stub.GetPsuMaxTemperature, platform_ndk_pb2.ReqPsuInfoPb(psu_idx=self.index)) nokia_common.channel_shutdown(channel) if ret is False: return self.min_voltage self.min_voltage = response.fault_info.min_voltage self.max_voltage = response.fault_info.max_voltage self.max_temperature = response.fault_info.max_temperature return self.min_voltage
def show_psu(stub): arg1 = platform_ndk_pb2.ReqPsuInfoPb(psu_idx=0) ret, response = nokia_common.try_grpc(stub.ShowPsuInfo, arg1) if ret is False: print('PSU request unsuccessful on this card') return if len(response.psu_info.psu_device) == 0: print('PSU Output not available on this card') return if format_type == 'json-format': json_response = MessageToJson(response) print(json_response) return field = [] field.append('Index ') field.append('Status ') i = 0 item_list = [] while i < len(response.psu_info.psu_device): psu_device = response.psu_info.psu_device[i] item = [] item.append(str(i + 1)) if psu_device.psu_presence: if psu_device.psu_status: item.append('UP') else: item.append('DOWN') else: item.append('NOT-PRESENT') item_list.append(item) i += 1 print('PSU TABLE') print_table(field, item_list) return
def get_temperature(self): """ Retrieves current temperature reading from thermal Returns: A float number of current temperature in Celsius up to nearest thousandth of one degree Celsius, e.g. 30.125 """ channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_THERMAL_SERVICE) if not channel or not stub: return self.thermal_temperature ret, response = nokia_common.try_grpc( stub.GetThermalCurrTemp, platform_ndk_pb2.ReqTempParamsPb(idx=self.map_index)) nokia_common.channel_shutdown(channel) if ret is False: return self.thermal_temperature self.thermal_temperature = float(response.curr_temp) return float("{:.3f}".format(self.thermal_temperature))
def get_low_threshold(self): """ Retrieves the low threshold temperature of thermal Returns: A float number, the low threshold temperature of thermal in Celsius up to nearest thousandth of one degree Celsius, e.g. 30.125 """ channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_THERMAL_SERVICE) if not channel or not stub: return self.thermal_low_threshold ret, response = nokia_common.try_grpc( stub.GetThermalLowThreshold, platform_ndk_pb2.ReqTempParamsPb(idx=self.map_index)) nokia_common.channel_shutdown(channel) if ret is False: return self.thermal_low_threshold self.thermal_low_threshold = float(response.low_threshold) return float("{:.3f}".format(self.thermal_low_threshold))
def get_thermal_list(self): channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_THERMAL_SERVICE) if not channel or not stub: return ret, response = nokia_common.try_grpc(stub.GetThermalDevicesInfo, platform_ndk_pb2.ReqTempParamsPb()) nokia_common.channel_shutdown(channel) if ret is False: return all_temp_devices = response.temp_devices self.num_thermals = len(all_temp_devices.temp_device) i = 0 # Empty previous list if len(self._thermal_list) != self.num_thermals: del self._thermal_list[:] for i in range(self.num_thermals): temp_device_ = all_temp_devices.temp_device[i] thermal = Thermal(i, temp_device_.device_idx, temp_device_.sensor_name, self.thermal_stub) self._thermal_list.append(thermal)
def get_oper_status(self): """ Retrieves the operational status of the module Returns: string: The status-string of the module """ channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_CHASSIS_SERVICE) if not channel or not stub: return self.oper_status platform_module_type = self.get_platform_type() ret, response = nokia_common.try_grpc( stub.GetModuleStatus, platform_ndk_pb2.ReqModuleInfoPb(module_type=platform_module_type, hw_slot=self.get_slot())) nokia_common.channel_shutdown(channel) if ret is False: return self.oper_status self.oper_status = response.status return response.status
def _get_modules_consumed_power(self): channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_CHASSIS_SERVICE) if not channel or not stub: return ret, response = nokia_common.try_grpc(stub.GetModuleMaxPower, platform_ndk_pb2.ReqModuleInfoPb()) nokia_common.channel_shutdown(channel) if ret is False: return i = 0 while i < len(response.power_info.module_power): module_info = response.power_info.module_power[i] i = i + 1 type = module_info.module_type if type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_CONTROL: self.supervisor_power = module_info.module_maxpower elif type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_LINE: self.line_card_power = module_info.module_maxpower elif type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_FABRIC: self.fabric_card_power = module_info.module_maxpower elif type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_FANTRAY: self.fantray_power = module_info.module_maxpower
def port_link_state_change(self, port, state): intf_prefix = 'Ethernet' if port.startswith(intf_prefix) is False: return else: import re parse_nums = re.findall(r'\d+', port) port_id = int(parse_nums[0]) if state == 'up': port_up = 1 elif state == 'down': port_up = 0 else: return led_type = platform_ndk_pb2.ReqLedType.LED_TYPE_PORT if port_up: led_info = nokia_common.led_color_to_info( DeviceBase.STATUS_LED_COLOR_GREEN) else: led_info = nokia_common.led_color_to_info( DeviceBase.STATUS_LED_COLOR_OFF) channel, stub = nokia_common.channel_setup( nokia_common.NOKIA_GRPC_LED_SERVICE) if not channel or not stub: return port_idx = platform_ndk_pb2.ReqLedIndexPb(start_idx=port_id, end_idx=port_id) ret, response = nokia_common.try_grpc( stub.SetLed, platform_ndk_pb2.ReqLedInfoPb(led_type=led_type, led_idx=port_idx, led_info=led_info)) nokia_common.channel_shutdown(channel)
def get_module_list(self): channel, stub = nokia_common.channel_setup(nokia_common.NOKIA_GRPC_CHASSIS_SERVICE) if not channel or not stub: return ret, response = nokia_common.try_grpc(stub.GetChassisProperties, platform_ndk_pb2.ReqModuleInfoPb()) nokia_common.channel_shutdown(channel) if ret is False: return if self.is_modular_chassis() and not self.is_cpm: index = 0 supervisor = Module(index, ModuleBase.MODULE_TYPE_SUPERVISOR+str(index), ModuleBase.MODULE_TYPE_SUPERVISOR, self.get_supervisor_slot(), self.chassis_stub) supervisor.set_maximum_consumed_power(self.supervisor_power) index = 1 module = Module(index, ModuleBase.MODULE_TYPE_LINE+str(self.get_my_slot()-1), ModuleBase.MODULE_TYPE_LINE, self.get_my_slot(), self.chassis_stub) module.set_maximum_consumed_power(self.line_card_power) self._module_list.append(supervisor) self._module_list.append(module) logger.log_info('Not control card. Adding self into module list') return if self.is_modular_chassis() and self.is_cpm: for property_index in range(len(response.chassis_property.hw_property)): hw_property = response.chassis_property.hw_property[property_index] if hw_property.module_type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_CONTROL: # Single CPM is supported in chassis num_control_cards = 1 for j in range(num_control_cards): module = Module(property_index, ModuleBase.MODULE_TYPE_SUPERVISOR+str(j), ModuleBase.MODULE_TYPE_SUPERVISOR, self.get_supervisor_slot(), self.chassis_stub) module.set_maximum_consumed_power(self.supervisor_power) self._module_list.append(module) elif hw_property.module_type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_LINE: for j in range(hw_property.max_num): module = Module(property_index, ModuleBase.MODULE_TYPE_LINE+str(j), ModuleBase.MODULE_TYPE_LINE, hw_property.slot[j], self.chassis_stub) module.set_maximum_consumed_power(self.line_card_power) self._module_list.append(module) elif hw_property.module_type == platform_ndk_pb2.HwModuleType.HW_MODULE_TYPE_FABRIC: for j in range(hw_property.max_num): module = Module(property_index, ModuleBase.MODULE_TYPE_FABRIC+str(j), ModuleBase.MODULE_TYPE_FABRIC, hw_property.slot[j], self.chassis_stub) module.set_maximum_consumed_power(self.fabric_card_power) self._module_list.append(module)