PCI: Avoid looping over PCI devices twice

The get_instance_pci_devs() methos is called twice when the libvirt
driver is creating the guest config when xen, qemu or kvm hypervisor is
used.

This also makes the code easier to understand.

Change-Id: Id6d5ee1d46ee0d8cab9432f24af3c1493080545a
This commit is contained in:
Ludovic Beliveau
2016-09-23 09:41:27 -04:00
parent 7fa9785b72
commit ab2653db00

View File

@@ -4408,7 +4408,6 @@ class LibvirtDriver(driver.ComputeDriver):
guest.memory = flavor.memory_mb * units.Ki
guest.vcpus = flavor.vcpus
allowed_cpus = hardware.get_vcpu_pin_set()
pci_devs = pci_manager.get_instance_pci_devs(instance, 'all')
guest_numa_config = self._get_guest_numa_config(
instance.numa_topology, flavor, allowed_cpus, image_meta)
@@ -4524,9 +4523,13 @@ class LibvirtDriver(driver.ComputeDriver):
self._set_qemu_guest_agent(guest, flavor, instance, image_meta)
if virt_type in ('xen', 'qemu', 'kvm'):
# Get all generic PCI devices (non-SR-IOV).
for pci_dev in pci_manager.get_instance_pci_devs(instance):
guest.add_device(self._get_guest_pci_device(pci_dev))
else:
# PCI devices is only supported for hypervisor 'xen', 'qemu' and
# 'kvm'.
pci_devs = pci_manager.get_instance_pci_devs(instance, 'all')
if len(pci_devs) > 0:
raise exception.PciDeviceUnsupportedHypervisor(
type=virt_type)