def _init_address_fields(self, pci_addr): if self.is_physical_function: (self.domain, self.bus, self.slot, self.func) = utils.get_pci_address_fields(pci_addr) return dbs, sep, func = pci_addr.partition('.') if func: fstr = func.strip() if fstr != ANY: try: f = get_value(fstr) except SyntaxError: raise exception.PciDeviceWrongAddressFormat( address=pci_addr) if f > MAX_FUNC: raise exception.PciDeviceInvalidAddressField( address=pci_addr, field="function") self.func = "%1x" % f if dbs: dbs_fields = dbs.split(':') if len(dbs_fields) > 3: raise exception.PciDeviceWrongAddressFormat(address=pci_addr) # If we got a partial address like ":00.", we need to turn this # into a domain of ANY, a bus of ANY, and a slot of 00. This code # allows the address bus and/or domain to be left off dbs_all = [ANY for x in range(3 - len(dbs_fields))] dbs_all.extend(dbs_fields) dbs_checked = [s.strip() or ANY for s in dbs_all] self.domain, self.bus, self.slot = dbs_checked get_pci_dev_info(self, 'domain', MAX_DOMAIN, '%04x') get_pci_dev_info(self, 'bus', MAX_BUS, '%02x') get_pci_dev_info(self, 'slot', MAX_SLOT, '%02x') self._check_physical_function()
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()
def _init_address_fields(self, pci_addr): if not self.is_physical_function: if isinstance(pci_addr, six.string_types): self.pci_address_spec = PciAddressGlobSpec(pci_addr) elif isinstance(pci_addr, dict): self.pci_address_spec = PciAddressRegexSpec(pci_addr) else: raise exception.PciDeviceWrongAddressFormat(address=pci_addr) self._check_physical_function() else: self.pci_address_spec = PhysicalPciAddress(pci_addr)
def __init__(self, pci_addr): try: self.domain = pci_addr.get('domain', REGEX_ANY) self.bus = pci_addr.get('bus', REGEX_ANY) self.slot = pci_addr.get('slot', REGEX_ANY) self.func = pci_addr.get('function', REGEX_ANY) self.domain_regex = re.compile(self.domain) self.bus_regex = re.compile(self.bus) self.slot_regex = re.compile(self.slot) self.func_regex = re.compile(self.func) except re.error: raise exception.PciDeviceWrongAddressFormat(address=pci_addr)
def __init__(self, pci_addr): try: if isinstance(pci_addr, dict): self.domain = pci_addr['domain'] self.bus = pci_addr['bus'] self.slot = pci_addr['slot'] self.func = pci_addr['function'] else: self.domain, self.bus, self.slot, self.func = ( utils.get_pci_address_fields(pci_addr)) get_pci_dev_info(self, 'func', MAX_FUNC, '%1x') get_pci_dev_info(self, 'domain', MAX_DOMAIN, '%04x') get_pci_dev_info(self, 'bus', MAX_BUS, '%02x') get_pci_dev_info(self, 'slot', MAX_SLOT, '%02x') except (KeyError, ValueError): raise exception.PciDeviceWrongAddressFormat(address=pci_addr)
def __init__(self, pci_addr: PCISpecAddressType) -> None: try: # TODO(stephenfin): Is this ever actually a string? if isinstance(pci_addr, dict): self.domain = pci_addr['domain'] self.bus = pci_addr['bus'] self.slot = pci_addr['slot'] self.func = pci_addr['function'] else: self.domain, self.bus, self.slot, self.func = ( utils.get_pci_address_fields(pci_addr)) self._set_pci_dev_info('func', MAX_FUNC, '%1x') self._set_pci_dev_info('domain', MAX_DOMAIN, '%04x') self._set_pci_dev_info('bus', MAX_BUS, '%02x') self._set_pci_dev_info('slot', MAX_SLOT, '%02x') except (KeyError, ValueError): raise exception.PciDeviceWrongAddressFormat(address=pci_addr)
def __init__(self, pci_addr): self.domain = ANY self.bus = ANY self.slot = ANY self.func = ANY dbs, sep, func = pci_addr.partition('.') if func: self.func = func.strip() get_pci_dev_info(self, 'func', MAX_FUNC, '%01x') if dbs: dbs_fields = dbs.split(':') if len(dbs_fields) > 3: raise exception.PciDeviceWrongAddressFormat(address=pci_addr) # If we got a partial address like ":00.", we need to turn this # into a domain of ANY, a bus of ANY, and a slot of 00. This code # allows the address bus and/or domain to be left off dbs_all = [ANY] * (3 - len(dbs_fields)) dbs_all.extend(dbs_fields) dbs_checked = [s.strip() or ANY for s in dbs_all] self.domain, self.bus, self.slot = dbs_checked get_pci_dev_info(self, 'domain', MAX_DOMAIN, '%04x') get_pci_dev_info(self, 'bus', MAX_BUS, '%02x') get_pci_dev_info(self, 'slot', MAX_SLOT, '%02x')