Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
    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
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
    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
Exemplo n.º 19
0
    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
Exemplo n.º 20
0
    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
Exemplo n.º 21
0
    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
Exemplo n.º 22
0
    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
Exemplo n.º 23
0
    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))
Exemplo n.º 24
0
    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))
Exemplo n.º 25
0
    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)
Exemplo n.º 26
0
    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
Exemplo n.º 27
0
    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
Exemplo n.º 28
0
    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)
Exemplo n.º 29
0
    def __init__(self):
        cache_file = os.path.join(CACHE_ROOT, CACHE_FILE)
        if not os.path.exists(CACHE_ROOT):
            try:
                os.makedirs(CACHE_ROOT)
            except Exception as e:
                pass
        cache_file = os.path.join(CACHE_ROOT, CACHE_FILE)
        if not os.path.exists(cache_file):
            channel, stub = nokia_common.channel_setup(
                nokia_common.NOKIA_GRPC_EEPROM_SERVICE)
            if not channel or not stub:
                raise RuntimeError(
                    str(e) + "Unable to fetch eeprom info from platform-ndk")
                return
            response = stub.GetCardEepromAllTlvs(
                platform_ndk_pb2.ReqEepromInfoPb())
            nokia_common.channel_shutdown(channel)

            eeprom_filearray = bytearray(response.data)
            eeprom_file = open(cache_file, "wb")
            eeprom_file.write(eeprom_filearray)
            eeprom_file.close()

        if not os.path.exists(cache_file):
            logger.log_error(
                "Nowhere to read syseeprom from! File not exists or cache file found"
            )
            return

        self.eeprom_path = cache_file
        super(Eeprom, self).__init__(self.eeprom_path, 0, '', True)

        try:
            self.eeprom_data = self.read_eeprom()
        except Exception as e:
            self.eeprom_data = "N/A"
            raise RuntimeError(str(e) + "Eeprom is not Programmed")
        else:
            eeprom = self.eeprom_data

            if not self.is_valid_tlvinfo_header(eeprom):
                return

            self._eeprom_tlv_dict = dict()
            total_length = (eeprom[9] << 8) | eeprom[10]
            tlv_index = self._TLV_INFO_HDR_LEN
            tlv_end = self._TLV_INFO_HDR_LEN + total_length

            while (tlv_index + 2) < len(eeprom) and tlv_index < tlv_end:
                if not self.is_valid_tlv(eeprom[tlv_index:]):
                    break

                tlv = eeprom[tlv_index:tlv_index + 2 + eeprom[tlv_index + 1]]
                code = "0x%02X" % tlv[0]

                if tlv[0] == self._TLV_CODE_VENDOR_EXT:
                    value = str((tlv[2] << 24) | (tlv[3] << 16) | (tlv[4] << 8)
                                | tlv[5])
                    value += tlv[6:6 + tlv[1]].decode('ascii')
                else:
                    name, value = self.decoder(None, tlv)

                self._eeprom_tlv_dict[code] = value
                if eeprom[tlv_index] == self._TLV_CODE_CRC_32:
                    break

                tlv_index += eeprom[tlv_index + 1] + 2
Exemplo n.º 30
0
    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)