From 70fae1463547835746426939b49012b21db278e2 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Mon, 2 Sep 2013 16:56:53 +0200 Subject: [PATCH] Automatically add multifunction address parameter when needed Also check for use of duplicate addresses before passing such XML to libvirt. And fix tests (of course). --- tests/cli-test-xml/compare/many-devices.xml | 4 ++-- virtinst/guest.py | 23 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/cli-test-xml/compare/many-devices.xml b/tests/cli-test-xml/compare/many-devices.xml index 390c22e9..b5254729 100644 --- a/tests/cli-test-xml/compare/many-devices.xml +++ b/tests/cli-test-xml/compare/many-devices.xml @@ -46,7 +46,7 @@ -
+
@@ -134,7 +134,7 @@ -
+
diff --git a/virtinst/guest.py b/virtinst/guest.py index db981fe0..06b06ccb 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -612,6 +612,7 @@ class Guest(XMLBuilder): for dev in self.get_all_devices(): dev.set_defaults() self._add_implied_controllers() + self._check_address_multi() self._set_disk_defaults() self._set_net_defaults() self._set_input_defaults() @@ -697,6 +698,28 @@ class Guest(XMLBuilder): ctrl.address.set_addrstr("spapr-vio") self.add_device(ctrl) + def _check_address_multi(self): + addresses = {} + for d in self._devices: + if d.address.type != d.address.ADDRESS_TYPE_PCI: + continue + + addr = d.address + addrstr = "%d%d%d" % (d.address.domain, + d.address.bus, + d.address.slot) + + if addrstr not in addresses: + addresses[addrstr] = {} + if addr.function in addresses[addrstr]: + raise ValueError(_("Duplicate address for devices %s and %s") % + (str(d), str(addresses[addrstr][addr.function]))) + addresses[addrstr][addr.function] = d + + for devs in addresses.values(): + if len(devs) > 1 and 0 in devs: + devs[0].address.multifunction = True + def _can_virtio(self, key): if not self.conn.is_qemu(): return False