def get_dmidecode_pci_slots()

in pci_lib/pci_lib.py [0:0]


def get_dmidecode_pci_slots():
    slotmap = {}
    try:
        dmiout = subprocess.check_output(['/sbin/dmidecode', '-t', 'slot'])
        dmiout = dmiout.decode('utf-8')
        slots = []
        slot = None
        for line in dmiout.splitlines():
            line = line.strip()
            if line == 'System Slot Information':
                slot = {}
            if ': ' in line:
                k, v = line.split(': ', 1)
                slot[k] = v
            if slot and not line:
                slots.append(slot)
                slot = {}
        if slot and not line:
            slots.append(slot)
        for slot in slots:
            try:
                addr = slot['Bus Address'].lower()
                slotmap[addr] = {
                    'designation': slot['Designation'],
                    'type': slot['Type'],
                }
            except KeyError:
                # skip
                pass
    except Exception:
        pass
    return slotmap