Beispiel #1
0
def check_for_virt_iommu():

    virt_iommu = 0
    cpu_info = smolt.read_cpuinfo()
    cpu_info_pat = re.compile("x86")

    if not cpu_info_pat.search(cpu_info['platform']):
        #only x86 boxes support virt iommu
        return 0

    #test what type of system we are on
    if os.path.exists("/sys/firmware/acpi/tables/DMAR"):
        # alright we are on an Intel vt-d box
        hwu = False
        ba = False

        # iasl can't read directly from /sys
        shutil.copyfile('/sys/firmware/acpi/tables/DMAR', 'DMAR.dat')

        # create ascii file
        os.system("iasl -d DMAR.dat > /dev/null 2>&1")
        if os.path.exists("DMAR.dsl"):
            f = open("DMAR.dsl", 'r')

            #look for keywords to validate ascii file
            hwu_pat = re.compile ('Hardware Unit')
            ba_pat = re.compile ('Base Address')
            ba_inv_pat = re.compile ('0000000000000000|FFFFFFFFFFFFFFFF')

            for line in f.readlines():
                if hwu_pat.search(line):
                    hwu = True
                if ba_pat.search(line):
                    if ba_inv_pat.search(line):
                        print "VIRT_IOMMU: Invalid Base address: 0's or F's"
                    else:
                        ba = True
            if not hwu:
                print "VIRT_IOMMU: No Hardware Unit"
            elif not ba:
                print "VIRT_IOMMU: No Base Address"
            else:
                virt_iommu = 1
        else:
            print "VIRT_IOMMU: Failed to create DMAR.dsl"

    elif os.path.exists("/sys/firmware/acpi/tables/IVRS"):
        # alright we are on an AMD iommu box
        #  we don't have a good way to validate this
        virt_iommu = 1

    return virt_iommu
Beispiel #2
0
def read_inventory():
    # get the data from SMOLT but modify it for how RHTS expects to see it
    # Eventually we'll switch over to SMOLT properly.
    data = {}
    flags = []
    data['Devices'] = []

    procCpu  = procfs.cpuinfo()
    smoltCpu = smolt.read_cpuinfo()
    memory   = smolt.read_memory()
    profile  = smolt.Hardware()

    arch = smoltCpu['platform']

    if arch in ["i386", "x86_64"]:
        for cpuflag in procCpu.tags['flags'].split(" "):
            flags.append(cpuflag)
        cpu = dict(vendor     = smoltCpu['type'],
                   model      = int(procCpu.tags['model']),
                   modelName  = smoltCpu['model'],
                   speed      = float(procCpu.tags['cpu mhz']),
                   processors = int(procCpu.nr_cpus),
                   cores      = int(procCpu.nr_cores),
                   sockets    = int(procCpu.nr_sockets),
                   CpuFlags   = flags,
                   family     = int(smoltCpu['model_number']),
                   stepping   = int(procCpu.tags['stepping']),
                  )
    elif arch in ["ppc", "ppc64"]:
        cpu = dict(vendor     = "IBM",
                   model      = 0,
                   modelName  = str(procCpu.tags['cpu']),
                   speed      = float(re.findall('\d+.+\d+', procCpu.tags['clock'])[0]),
                   processors = int(procCpu.nr_cpus),
                   cores      = 0,
                   sockets    = 0,
                   CpuFlags   = flags,
                   family     = 0,
                   stepping   = 0,
                 )
    elif arch in ["s390", "s390x"]:
        for cpuflag in procCpu.tags['features'].split(" "):
            flags.append(cpuflag)
        proc = dict([tuple(s.strip() for s in kv.split('=')) for kv in procCpu.tags['processor 0'].split(',')])
        cpu = dict(vendor     = str(procCpu.tags['vendor_id']),
                   model      = 0,
                   modelName  = str(proc['machine']),
                   processors = int(procCpu.tags['# processors']),
                   cores      = 0,
                   sockets    = 0,
                   CpuFlags   = flags,
                   family     = 0,
                   speed      = 0,
                   stepping   = 0,
                  )
    elif arch == "ia64":
        for cpuflag in procCpu.tags['features'].split(","):
            flags.append(cpuflag.strip())
        cpu = dict(vendor     = smoltCpu['type'],
                   model      = int(procCpu.tags['model']),
                   modelName  = smoltCpu['model'],
                   speed      = float(procCpu.tags['cpu mhz']),
                   processors = int(procCpu.nr_cpus),
                   cores      = int(procCpu.nr_cores),
                   sockets    = int(procCpu.nr_sockets),
                   CpuFlags   = flags,
                   family     = int(smoltCpu['model_rev']),
                   stepping   = 0,
                  )

    data['Cpu'] = cpu
    data['Arch'] = [arch]
    data['vendor'] = "%s" % profile.host.systemVendor
    data['model'] = "%s" % profile.host.systemModel
    data['formfactor'] = "%s" % profile.host.formfactor
    data['memory'] = int(memory['ram'])

    disklist = []
    diskdata = {}
    disks = Disks()
    for disk in Disks():
        disklist.append(disk.to_dict())
    diskdata['Disks'] = disklist

    data['Disk'] = diskdata

    if hasattr(profile.host, 'numaNodes'):
        data['Numa'] = {'nodes': profile.host.numaNodes}
    else:
        data['Numa'] = {
            'nodes': len(glob.glob('/sys/devices/system/node/node*')), #: number of NUMA nodes in the system, or 0 if not supported
        }

    if os.path.exists('./hvm_detect'):
        hypervisor = Popen(['./hvm_detect'], stdout=PIPE).communicate()[0]
        hvm_map = {"No KVM or Xen HVM\n"    : None,
                   "KVM guest.\n"           : u'KVM',
                   "Xen HVM guest.\n"       : u'Xen',
                   "Microsoft Hv guest.\n"  : u'HyperV',
                   "VMWare guest.\n"        : u'VMWare',
                  }
        data['Hypervisor'] = hvm_map[hypervisor]

    for VendorID, DeviceID, SubsysVendorID, SubsysDeviceID, Bus, Driver, Type, Description in profile.deviceIter():
        device = dict ( vendorID = "%04x" % (VendorID and VendorID or 0),
                        deviceID = "%04x" % (DeviceID and DeviceID or 0),
                        subsysVendorID = "%04x" % (SubsysVendorID and SubsysVendorID or 0),
                        subsysDeviceID = "%04x" % (SubsysDeviceID and SubsysDeviceID or 0),
                        bus = str(Bus),
                        driver = str(Driver),
                        type = str(Type),
                        description = str(Description))
        data['Devices'].append(device)

    return data