mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
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
This commit is contained in:
parent
8d4e58c501
commit
5398282e12
@ -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>
|
||||
|
@ -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 \
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user