summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2016-06-16 20:36:30 -0400
committerCole Robinson <crobinso@redhat.com>2016-06-16 20:36:30 -0400
commit5398282e12e12ac48dd10becea33456a483b7f5e (patch)
tree308d374c2ccf31d24ede8376642dfe7a4f077a4b
parent8d4e58c50163023a22fbba150cbd165048d3c97b (diff)
downloadvirt-manager-5398282e12e12ac48dd10becea33456a483b7f5e.tar.gz
storage: Detect backing_store format automatically
By attempting to manage/import the passed path. This makes it work via both virt-install and virt-manager https://bugzilla.redhat.com/show_bug.cgi?id=1235406
-rw-r--r--tests/cli-test-xml/compare/virt-install-many-devices.xml5
-rw-r--r--tests/clitest.py1
-rw-r--r--virtinst/storage.py50
3 files changed, 53 insertions, 3 deletions
diff --git a/tests/cli-test-xml/compare/virt-install-many-devices.xml b/tests/cli-test-xml/compare/virt-install-many-devices.xml
index 94774b05..50859f34 100644
--- a/tests/cli-test-xml/compare/virt-install-many-devices.xml
+++ b/tests/cli-test-xml/compare/virt-install-many-devices.xml
@@ -145,6 +145,11 @@
<source file="/dev/default-pool/new2.img"/>
<target dev="vdm" bus="virtio"/>
</disk>
+ <disk type="file" device="disk">
+ <driver name="qemu" type="qcow2"/>
+ <source file="/tmp/brand-new.img"/>
+ <target dev="vdn" bus="virtio"/>
+ </disk>
<controller type="usb" index="0" model="ich9-ehci1">
<address type="pci" domain="0" bus="0" slot="4" function="7"/>
</controller>
diff --git a/tests/clitest.py b/tests/clitest.py
index 51c948b4..91ff94e7 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -466,6 +466,7 @@ c.add_compare(""" \
--disk vol=gluster-pool/test-gluster.raw,startup_policy=optional \
--disk %(DIR)s,device=floppy,address.type=ccw,address.cssid=0xfe,address.ssid=0,address.devno=01 \
--disk %(NEWIMG2)s,size=1,backing_store=/tmp/foo.img,backing_format=vmdk \
+--disk /tmp/brand-new.img,size=1,backing_store=/dev/default-pool/iso-vol \
\
--network user,mac=12:34:56:78:11:22,portgroup=foo,link_state=down,rom_bar=on,rom_file=/tmp/foo \
--network bridge=foobar,model=virtio,driver_name=qemu,driver_queues=3 \
diff --git a/virtinst/storage.py b/virtinst/storage.py
index ebab016c..2a42ecaa 100644
--- a/virtinst/storage.py
+++ b/virtinst/storage.py
@@ -230,6 +230,17 @@ class StoragePool(_StorageObject):
_("Couldn't create default storage pool '%s': %s") %
(path, str(e)))
+ @staticmethod
+ def manage_path(conn, path):
+ """
+ If the passed path is managed, lookup its storage objects.
+ If the passed path isn't managed, attempt to manage it if
+ we can.
+
+ :returns: (vol, parent pool) tuple
+ """
+ from . import diskbackend
+ return diskbackend.manage_path(conn, path)
@staticmethod
def get_default_dir(conn, build=False):
@@ -678,7 +689,14 @@ class StorageVolume(_StorageObject):
def _get_vol_type(self):
if self.type:
- return self.type
+ if self.type == "file":
+ return self.TYPE_FILE
+ elif self.type == "block":
+ return self.TYPE_BLOCK
+ elif self.type == "dir":
+ return self.TYPE_DIR
+ elif self.type == "network":
+ return self.TYPE_NETWORK
if (self._pool_xml.type == StoragePool.TYPE_DISK or
self._pool_xml.type == StoragePool.TYPE_LOGICAL):
return self.TYPE_BLOCK
@@ -718,6 +736,31 @@ class StorageVolume(_StorageObject):
is_bool=True, default_cb=_lazy_refcounts_default_cb)
+ def _detect_backing_store_format(self):
+ logging.debug("Attempting to detect format for backing_store=%s",
+ self.backing_store)
+ vol, pool = StoragePool.manage_path(self.conn, self.backing_store)
+
+ if not vol:
+ logging.debug("Didn't find any volume for backing_store")
+ return None
+
+ # Only set backing format for volumes that support
+ # the 'format' parameter as we know it, like qcow2 etc.
+ volxml = StorageVolume(self.conn, vol.XMLDesc(0))
+ volxml.pool = pool
+ logging.debug("Found backing store volume XML:\n%s",
+ volxml.get_xml_config())
+
+ if volxml.supports_property("format"):
+ logging.debug("Returning format=%s", volxml.format)
+ return volxml.format
+
+ logging.debug("backing_store volume doesn't appear to have "
+ "a file format we can specify, returning None")
+ return None
+
+
######################
# Public API helpers #
######################
@@ -729,7 +772,6 @@ class StorageVolume(_StorageObject):
return True
return False
-
def supports_property(self, propname):
if propname == "format":
return self._supports_format()
@@ -761,6 +803,9 @@ class StorageVolume(_StorageObject):
"""
Build and install storage volume from xml
"""
+ if self.backing_store and not self.backing_format:
+ self.backing_format = self._detect_backing_store_format()
+
xml = self.get_xml_config()
logging.debug("Creating storage volume '%s' with xml:\n%s",
self.name, xml)
@@ -785,7 +830,6 @@ class StorageVolume(_StorageObject):
cloneflags |= getattr(libvirt,
"VIR_STORAGE_VOL_CREATE_REFLINK", 1)
-
try:
self._install_finished = False
t.start()