**** CubicPower OpenStack Study ****
def pci_device_prop_match(pci_dev, specs):
"""Check if the pci_dev meet spec requirement
Specs is a list of PCI device property requirements.
An example of device requirement that the PCI should be either:
a) Device with vendor_id as 0x8086 and product_id as 0x8259, or
b) Device with vendor_id as 0x10de and product_id as 0x10d8:
[{"vendor_id":"8086", "product_id":"8259"},
{"vendor_id":"10de", "product_id":"10d8"}]
"""
def _matching_devices(spec):
return all(pci_dev.get(k) == v for k, v in spec.iteritems())
return any(_matching_devices(spec) for spec in specs)
**** CubicPower OpenStack Study ****
def parse_address(address):
"""Returns (domain, bus, slot, function) from PCI address that is stored in
PciDevice DB table.
"""
m = _PCI_ADDRESS_REGEX.match(address)
if not m:
raise exception.PciDeviceWrongAddressFormat(address=address)
return m.groups()