def show_platform(stub): response = stub.GetChassisStatus(platform_ndk_pb2.ReqModuleInfoPb()) if format_type == 'json-format': json_response = MessageToJson(response) print(json_response) return field = [] field.append('Slot ') field.append('Name ') field.append('Status ') field.append('Midplane-IP ') i = 0 item_list = [] while i < len(response.hw_status_info.device_status): hw_device = response.hw_status_info.device_status[i] item = [] item.append(str(hw_device.slot_num)) item.append(hw_device.hw_name) item.append(hw_device.state) m_response = stub.GetMidplaneIP( platform_ndk_pb2.ReqModuleInfoPb(hw_slot=hw_device.slot_num)) item.append(m_response.midplane_ip) item_list.append(item) i += 1 print('PLATFORM INFO TABLE') print_table(field, item_list) return
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 show_power(stub): response = stub.GetModuleMaxPower(platform_ndk_pb2.ReqModuleInfoPb()) if format_type == 'json-format': json_response = MessageToJson(response) print(json_response) return field = [] field.append('ModuleType ') field.append('Power ') i = 0 item_list = [] while i < len(response.power_info.module_power): module_info = response.power_info.module_power[i] item = [] item.append(platform_ndk_pb2.HwModuleType.Name( module_info.module_type)) item.append(str(module_info.module_maxpower)) item_list.append(item) i += 1 print('CHASSIS POWER TABLE') print_table(field, item_list)
def show_chassis(stub): response = stub.GetChassisProperties(platform_ndk_pb2.ReqModuleInfoPb()) if format_type == 'json-format': json_response = MessageToJson(response) print(json_response) return field = [] field.append('ModuleType ') field.append('Num-Modules ') field.append('Valid-Slots ') i = 0 item_list = [] while i < len(response.chassis_property.hw_property): hw_property = response.chassis_property.hw_property[i] item = [] item.append(platform_ndk_pb2.HwModuleType.Name( hw_property.module_type)) item.append(str(hw_property.max_num)) slot_list = [] for j in range(len(hw_property.slot)): slot_list.append(str(hw_property.slot[j])) item.append(', '.join(slot_list)) item_list.append(item) i += 1 print('CHASSIS INFO TABLE') print_table(field, item_list) return
def _get_my_slot(): channel, stub = channel_setup(NOKIA_GRPC_CHASSIS_SERVICE) if not channel or not stub: return NOKIA_INVALID_SLOT_NUMBER response = stub.GetMySlot(platform_ndk_pb2.ReqModuleInfoPb()) channel_shutdown(channel) return response.my_slot
def show_midplane_status(stub, hw_slot): response = stub.IsMidplaneReachable( platform_ndk_pb2.ReqModuleInfoPb(hw_slot=hw_slot)) if format_type == 'json-format': json_response = MessageToJson(response) print(json_response) return print('Reachability to slot {} is {}'.format(hw_slot, response.midplane_status)) return
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 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_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_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 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)
def get_chassis_type(): channel, stub = channel_setup(NOKIA_GRPC_CHASSIS_SERVICE) response = stub.GetChassisType(platform_ndk_pb2.ReqModuleInfoPb()) channel_shutdown(channel) return response.chassis_type