summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kletzander <mkletzan@redhat.com>2013-06-18 16:12:37 +0200
committerCole Robinson <crobinso@redhat.com>2013-06-19 18:18:32 -0400
commit137134650f6a15b2bf36e846e16e77a002d9d758 (patch)
treec9aadea2b9ae7ad356a63339582dc6fda49e642c
parent5fe2d5e97774df164f9af121b65f654d90958bf5 (diff)
downloadvirt-manager-137134650f6a15b2bf36e846e16e77a002d9d758.tar.gz
Allow partial address formatting
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
-rw-r--r--tests/xmlconfig-xml/boot-many-devices.xml1
-rw-r--r--virtinst/VirtualDevice.py13
2 files changed, 9 insertions, 5 deletions
diff --git a/tests/xmlconfig-xml/boot-many-devices.xml b/tests/xmlconfig-xml/boot-many-devices.xml
index bfcc4bde..64c0a5e2 100644
--- a/tests/xmlconfig-xml/boot-many-devices.xml
+++ b/tests/xmlconfig-xml/boot-many-devices.xml
@@ -38,6 +38,7 @@
<driver name='qemu' type='qcow2'/>
<source file='/default-pool/testvol1.img'/>
<target dev='sdb' bus='scsi'/>
+ <address type='spapr-vio'/>
</disk>
<controller type='scsi' index='0'>
<address type='spapr-vio'/>
diff --git a/virtinst/VirtualDevice.py b/virtinst/VirtualDevice.py
index 2fb2b89e..bbc32a61 100644
--- a/virtinst/VirtualDevice.py
+++ b/virtinst/VirtualDevice.py
@@ -1,7 +1,7 @@
#
# Base class for all VM devices
#
-# Copyright 2008 Red Hat, Inc.
+# Copyright 2008, 2013 Red Hat, Inc.
# Cole Robinson <crobinso@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
@@ -267,14 +267,17 @@ class VirtualDeviceAddress(XMLBuilderDomain):
if not self.type:
return
+ def format_props(*args):
+ return "".join([" %s='%s'" % (k, getattr(self, k)) for k in args if getattr(self, k, None) is not None])
+
xml = "<address type='%s'" % self.type
if self.type == self.ADDRESS_TYPE_PCI:
- xml += " domain='%s' bus='%s' slot='%s' function='%s'" % (self.domain, self.bus, self.slot, self.function)
+ xml += format_props("domain", "bus", "slot", "function")
elif self.type == self.ADDRESS_TYPE_DRIVE:
- xml += " controller='%s' bus='%s' unit='%s'" % (self.controller, self.bus, self.unit)
+ xml += format_props("controller", "bus", "unit")
elif self.type == self.ADDRESS_TYPE_VIRTIO_SERIAL:
- xml += " controller='%s' bus='%s' port='%s'" % (self.controller, self.bus, self.port)
+ xml += format_props("controller", "bus", "port")
elif self.type == self.ADDRESS_TYPE_CCID:
- xml += " controller='%s' slot='%s'" % (self.controller, self.slot)
+ xml += format_props("controller", "slot")
xml += "/>"
return xml