def _detach_pci_devices(self, dom, pci_devs):
    if (not self._has_min_version(MIN_LIBVIRT_DEVICE_CALLBACK_VERSION)):
        if pci_devs:
            reason = (_('Detaching PCI devices with libvirt < %(ver)s is not permitted') % {'ver': MIN_LIBVIRT_DEVICE_CALLBACK_VERSION})
            raise exception.PciDeviceDetachFailed(reason=reason, dev=pci_devs)
    try:
        for dev in pci_devs:
            dom.detachDeviceFlags(self._get_guest_pci_device(dev).to_xml(), libvirt.VIR_DOMAIN_AFFECT_LIVE)
            xml = dom.XMLDesc(0)
            xml_doc = etree.fromstring(xml)
            guest_config = vconfig.LibvirtConfigGuest()
            guest_config.parse_dom(xml_doc)
            for hdev in [d for d in guest_config.devices if isinstance(d, vconfig.LibvirtConfigGuestHostdevPCI)]:
                hdbsf = [hdev.domain, hdev.bus, hdev.slot, hdev.function]
                dbsf = pci_utils.parse_address(dev['address'])
                if ([int(x, 16) for x in hdbsf] == [int(x, 16) for x in dbsf]):
                    raise exception.PciDeviceDetachFailed(reason='timeout', dev=dev)
    except libvirt.libvirtError as ex:
        error_code = ex.get_error_code()
        if (error_code == libvirt.VIR_ERR_NO_DOMAIN):
            LOG.warn(_LW('Instance disappeared while detaching a PCI device from it.'))
        else:
            raise
def _detach_pci_devices(self, dom, pci_devs):
    if (not self._has_min_version(MIN_LIBVIRT_DEVICE_CALLBACK_VERSION)):
        if pci_devs:
            reason = (_('Detaching PCI devices with libvirt < %(ver)s is not permitted') % {'ver': MIN_LIBVIRT_DEVICE_CALLBACK_VERSION})
            raise exception.PciDeviceDetachFailed(reason=reason, dev=pci_devs)
    try:
        for dev in pci_devs:
            dom.detachDeviceFlags(self._get_guest_pci_device(dev).to_xml(), libvirt.VIR_DOMAIN_AFFECT_LIVE)
            xml = dom.XMLDesc(0)
            xml_doc = etree.fromstring(xml)
            guest_config = vconfig.LibvirtConfigGuest()
            guest_config.parse_dom(xml_doc)
            for hdev in [d for d in guest_config.devices if isinstance(d, vconfig.LibvirtConfigGuestHostdevPCI)]:
                hdbsf = [hdev.domain, hdev.bus, hdev.slot, hdev.function]
                dbsf = pci_utils.parse_address(dev['address'])
                if ([int(x, 16) for x in hdbsf] == [int(x, 16) for x in dbsf]):
                    raise exception.PciDeviceDetachFailed(reason='timeout', dev=dev)
    except libvirt.libvirtError as ex:
        error_code = ex.get_error_code()
        if (error_code == libvirt.VIR_ERR_NO_DOMAIN):
            LOG.warn(_LW('Instance disappeared while detaching a PCI device from it.'))
        else:
            raise