Exemplo n.º 1
0
 def __init__(self, type):
     self.__cores = []
     # Type can be "ESXi" or "RiOS"
     self.__type = type
     if self.__type == 'RiOS':
         self.__get_cores_information()
     elif self.__type == 'ESXi':
         self.__get_esxi_cores_information()
     else:
         rlog_warning('Unknown platform type for CPU information')
         exit(1)
Exemplo n.º 2
0
    def __get_cores_information(self):
        """Use the output of /proc/cpuinfo to figure out CPU information
        """
        (pid, speed, vendor, model, cache, coreid) = (0, 0, '', '', '', -1)
        cpuinfo = cat("/proc/cpuinfo")
        for i in range(0, len(cpuinfo)):
            line = cpuinfo[i]
            if line[:9] == 'processor':
                # The output starts with 'processor' so nothing to add there
                # if speed value has changed 
                # and a processor line is encountered, 
                # it means we have parsed the first core
                # DO NOT USE COREID VALUE AS ITS NOT DISPLAYED ON ESXI GUESTS
                if speed > 0:
                    cpu = CPU(pid, speed, vendor, model, cache, coreid)
                    self.__cores.append(cpu)
                    (pid, speed, vendor, model, cache, coreid) = (0, 0, '', '', '', -1)
                (key, value) = line.split(': ')
                pid = int(value.strip())
            elif line[:7] == 'cpu MHz':
                try:
                    (key, value) = line.split(': ')
                    speed = int(float(value.strip()))
                except ValueError:
                    speed = 0
                    rlog_warning("Cannot get the CPU speed")
            elif line[:9] == 'vendor_id':
                (key, value) = line.split(': ')
                vendor = value.strip()
            elif line[:10] == 'cache size':
                (key, value) = line.split(': ')
                cache = value.strip()
            elif line[:7] == 'core id':
                (key, value) = line.split(': ')
                coreid = int(value.strip())
            elif line[:10] == 'model name':
                (key, value) = line.split(': ')
                model = value.strip()

        # Add the last core to the list
        cpu = CPU(pid, speed, vendor, model, cache, coreid)
        self.__cores.append(cpu)
        return True
Exemplo n.º 3
0
    def __read_config(self):
        config_file = self.__config_path
        if config_file == '':
            config_file = "/opt/tms/lib/hwtool/config/config.xml"

        mfg_config_file = "/etc/config.xml"

        try:
            stat(config_file)
            name = config_file
        except OSError:
            try:
                stat(mfg_config_file)
                name = mfg_config_file
            except OSError:
                print 'Unable to find specs.xml'
                exit (1)

        rlog_debug('Using spec file :' + name)
        dom = parse(name)
        mobos = dom.getElementsByTagName('motherboard')
        for mb in mobos:
            mobo = Motherboard()
            mobo.dname = mb.getAttribute('display_name')
            mobo.part_num = mb.getAttribute('part_number')
            mobo.name_keys = mb.getAttribute('name_keys').split(',')
            mobo.use_gpio = mb.getAttribute('use_gpio')
            if mb.getAttribute('gpio_mask'):
                (mobo.gpio_mask, mobo.gpio_res) = mb.getAttribute('gpio_mask').split(',')
            mobo.type = mb.getAttribute('type')
            mobo.kernel_opts = mb.getAttribute('kernel_opts')
            mobo.virtual = mb.getAttribute('is_virtual') # *** USED ONLY FOR BOB, NOT SH ***
            mobo.is_vm = mb.getAttribute('is_vm') # *** USED FOR SH ***
            mobo.isbob = mb.getAttribute('is_bob')
            if mb.getAttribute('backplane_keys'):
                mobo.backplane_keys = mb.getAttribute('backplane_keys').split(',')
            if mb.getAttribute('redfin_keys'):
                mobo.redfin_keys = mb.getAttribute('redfin_keys').split(',')
            else:
                mobo.redfin_keys = []
            if mb.hasAttribute('yt_model_type'):
                mobo.yt_model_type = mb.getAttribute('yt_model_type')

            if mb.getAttribute('usb_based'):
                if mb.getAttribute('usb_based') == 'true':
                    mobo.usb_based = True
		else:
		    mobo.usb_based = False

            # mobo passthru inpath indicates whether or not we are configuring 
            # the inpath devices for passthrough on this system
            if mb.hasAttribute('passthru_inpath'):
                mobo.passthru_inpath = mb.getAttribute('passthru_inpath') == 'true'
            else:
                mobo.passthru_inpath = False

            integrated_pci_cfg_list = mb.getElementsByTagName('integrated_pci')
            if integrated_pci_cfg_list != None and \
                integrated_pci_cfg_list != []:
                for node in integrated_pci_cfg_list:
                    pattern      = node.getAttribute('bus_number_pattern')
                    name         = node.getAttribute('name')
                    passthru_str = node.getAttribute('passthru')

                    if passthru_str == 'true':
                        passthru = True
                    else:
                        passthru = False

                    idev = IntegratedPciDevice(name, pattern, passthru)
                    if pattern != None and pattern != '' and name != None and \
                        name != '':
                        mobo.integrated_pci.append(idev)
                    else:
                        rlog_warning('invalid integrated device node %s' % \
                                     mobo.dname)

            # Cant run a loop for the elements and reply on the IndexError exception
            # cause the XML file does not have all the entries set and replies on 
            # missing values to assume the value
            # eg: if ipmi_support missing, it means 'false'
            try:
                hal = mb.getElementsByTagName('hal')[0]
                mobo.hal_path = hal.getAttribute('path')
            except IndexError:
                rlog_debug('hal path missing for mobo %s' % mobo.dname)
                mobo.hal_path = ''
                pass

            try:
                branding = mb.getElementsByTagName('branding')[0]
                mobo.branding = branding.getAttribute('supported')
                if branding.getAttribute('who_checks_disk') == 'host':
                    mobo.disk_brand_checker = 'host'
                else:
                    # anything else is 'rios'
                    mobo.disk_brand_checker = 'rios'

                if branding.getAttribute('mem_lic_check') == 'false':
                    mobo.mem_lic_check = 'false'
                else:
                    # anything else is 'true'
                    mobo.mem_lic_check = 'true'

            except IndexError:
                rlog_debug('branding info missing for mobo %s' % mobo.dname)
                mobo.branding = 'false'
                mobo.disk_brand_checker = 'rios'
                mobo.mem_lic_check = 'true'
                pass

            try:
                flexl = mb.getElementsByTagName('flexlicence')[0]
                mobo.flexl = flexl.getAttribute('supported')
            except IndexError:
                rlog_debug('flexible licensing info missing for mobo %s' % mobo.dname)
                mobo.flexl = 'false'
                pass

            try:
                rev = mb.getElementsByTagName('revision')[0]
                mobo.revision = rev.getAttribute('id')
            except IndexError:
                rlog_debug('revision info missing for mobo %s' % mobo.dname)
                mobo.revision = ''
                pass

            try:
                hwalarm = mb.getElementsByTagName('hwalarm')[0]
                mobo.hwalarm = hwalarm.getAttribute('supported')
            except IndexError:
                rlog_debug('hwalarm info missing for mobo %s' % mobo.dname)
                mobo.hwalarm = 'none'
                pass

            try:
                ipmi = mb.getElementsByTagName('ipmi')[0]
                mobo.ipmi_support = True
            except IndexError:
                mobo.ipmi_support = False
                pass

            try:
                onboard_nics_list = mb.getElementsByTagName('onboard_nics')
                for onboard_nics in onboard_nics_list:
                    update_mobo = False
                    # update the mobo in 2 situations
                    # we havent matched the onboard pattern name specified by 
                    # our product OR this is the first time we're seeing a pattern
                    if onboard_nics.getAttribute('name'):
                        if onboard_nics.getAttribute('name') == get_onboard_nic_pattern_name():
                            # we found the spec for this product
                            update_mobo = True
                    elif mobo.onboard_pattern == '':
                        update_mobo = True

                    if update_mobo:
                        mobo.onboard_pattern = onboard_nics.getAttribute('bus_number_pattern')
                        if onboard_nics.getAttribute('primary_first') == "true":
                            mobo.primary_first = True
                        else:
                            mobo.primary_first = False

                        try:
                            if onboard_nics.getAttribute('num_ifs') == '1':
                                mobo.num_ifs = 1
                            else:
                                mobo.num_ifs = 2
                                dev_id = onboard_nics.getAttribute('search_devid')
                                if get_devid_cnt(dev_id) == '1':
                                    # Primary only case
                                    mobo.num_ifs = 1
                                
                        except Exception:
                            mobo.num_ifs = 2
                            try:
                                dev_id = onboard_nics.getAttribute('search_devid')
                                if get_devid_cnt(dev_id) == '1':
                                    # Primary only case
                                    mobo.num_ifs = 1
                            except Exception:
                                mobo.num_ifs = 2
                                pass

            except IndexError:
                rlog_info('No onboard NIC cards for motherboard %s' % mobo.dname)
                pass

            try:
                slots = mb.getElementsByTagName('slot')
                for sl in slots:
                    pattern = (sl.getAttribute('number'), sl.getAttribute('bus_number_pattern'))
                    mobo.slot_patterns.append(pattern)
            except IOError:
                rlog_info('Something incorrect while parsing slots for motherboard %s' % mobo.dname)
                pass

            try:
                disks = mb.getElementsByTagName('disk')
                for di in disks:
                    # start_offset is set to 0 for disk elements, as they identify only
                    # a single disk.
                    pattern = (di.getAttribute('number'), di.getAttribute('pattern'), 
                               di.getAttribute('bus'), di.getAttribute('prefix'), 0)
                    mobo.disk_patterns.append(pattern)
            except IOError:
                rlog_warning('Something incorrect while parsing disk for motherboard %s' % mobo.dname)
                pass

            try:
                diskarrays = mb.getElementsByTagName('disk-array')
                for da in diskarrays:
		    start_offset_str = da.getAttribute('start_offset')
                    if start_offset_str == '' or start_offset_str == None:
                        start_offset = 0
                    else:
                        start_offset = int(start_offset_str)
                        
                    # we don't use a pattern for disk arrays, since we assume we
                    # have a unique port id somewhere exposed for disk-arrays
                    # only supports MPT at the moment
                    pattern = (da.getAttribute('number'), da.getAttribute('pattern'), 
                               da.getAttribute('bus'), da.getAttribute('prefix'), 
                               start_offset)
                    #
                    # disk arrays are handled in a special way, they
                    mobo.disk_patterns.append(pattern)
            except IOError:
                rlog_warning('Something incorrect while parsing disk arrays for motherboard %s' % mobo.dname)
                pass
        
            self.__mobos.append(mobo)

        cards = dom.getElementsByTagName('card')
        for c in cards:
            card = Card()
            try:
                card.dname = c.getAttribute('display_name')
                card.part_num = c.getAttribute('part_number')
                card.name_keys = c.getAttribute('name_keys').split(',')
            except IOError:
                rlog_warning('Something incorrect while parsing card %s' % card.dname)
                pass

            self.__cards.append(card)

        nics = dom.getElementsByTagName('nic')
        for n in nics:
            nic = Nic()
            try:
                nic.dname = n.getAttribute('display_name')
                nic.part_num = n.getAttribute('part_number')

                if n.hasAttribute('vendor_name_keys'):
                    nic.vendor_name_keys = n.getAttribute('vendor_name_keys')
                else:
                    nic.vendor_name_keys = ''

                nic.name_keys = n.getAttribute('name_keys').split(',')
                nic.num_ifaces = int(n.getAttribute('num_interfaces'))
                nic.utility = n.getAttribute('utility')
                nic.block = n.getAttribute('wdt_capab_block')
                nic.wdt_type = n.getAttribute('wdt_type')
                nic.ordering = n.getAttribute('ordering')
                nic.ethtool_offset = n.getAttribute('ethtool_offset')
                nic.guest_order = n.getAttribute('guest_order')
                nic.if_naming = n.getAttribute('if_naming')
            except IOError:
                rlog_warning('Something incorrect while parsing NIC %s' % nic.dname)
                pass

            self.__nics.append(nic)

        return True
Exemplo n.º 4
0
    def __get_esxi_cores_information(self):
        """Use the output of smbiosDump as ESXi does not support /proc/cpuinfo
        """
        dmi = smbiosDump()
        # cache and model will always remain empty for ESXi
        # coreid will be an incremental counter
        (pid, speed, vendor, model, cache, coreid) = (0, 0, '', '', '', 0)
        processor_pat = recompile("^\s*Processor Info:")
        manu_pat = recompile("^Manufacturer:")
        speed_pat = recompile("^Max. Speed:")
        core_pat = recompile("^Core Count:")
        cache_pat = recompile("^Cache Info:")
        pid_pat = recompile("^Socket:")

        core = 0 # Number of cores per CPU
        in_processor = False
        for line in dmi:
            # Get rid of all start and end white spaces
            line = line.strip()
            if in_processor:
                if pid_pat.match(line):
                    pid = line[7:]
                    if pid: 
                        try:
                            pid = int(pid.strip().replace('"', '').replace('CPU', ''))
                        except ValueError:
                            rlog_warning("Cannot get the processor ID for the CPU")
                            return False
                if manu_pat.match(line):
                    vendor = line[13:]
                    if vendor:
                        vendor = vendor.strip().replace('"', '')
                elif speed_pat.match(line):
                    speed = line[11:]
                    if speed:
                        try:
                            speed = int(speed.strip().replace('MHz', ''))
                        except ValueError:
                            rlog_warning("Cannot get the Speed info for the CPU")
                            return False
                elif core_pat.match(line):
                    core = line[11:]
                    if core:
                        try:
                            core = int(core.strip().replace('#', ''))
                        except ValueError:
                            rlog_warning("Cannot get the number of cores for the CPU")
                            return False

            elif processor_pat.match(line):
                in_processor = True
            if in_processor and cache_pat.match(line):
                # Done with the processor section, time to create the core objects
                in_processor = False
                for i in range(core):
                    coreid += 1
                    cpu = CPU(pid, speed, vendor, model, cache, coreid)
                    self.__cores.append(cpu)

                (pid, speed, vendor, model, cache) = (0, 0, '', '', '')

        return True