virtManager: clone: check which storage pools supports volume cloning

When cloning a guest in virt-manager the GUI shows a list of disks and
select default cloning policy for every disk.  For storage pools where
we know that cloning is not possible we should not select that option
as default one.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1463066

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2019-02-28 11:47:40 +01:00
parent be15a01bb2
commit 26a433fc42
3 changed files with 26 additions and 13 deletions

View File

@ -64,6 +64,11 @@ def can_we_clone(conn, vol, path):
elif not os.path.exists(path):
msg = _("Path does not exist.")
else:
pool = vol.get_parent_pool()
if not pool.supports_volume_creation(clone=True):
msg = _("Cannot clone %s storage pool.") % pool.get_type()
if msg:
ret = False
@ -94,12 +99,8 @@ def do_we_default(conn, vol, path, ro, shared, devtype):
if vol:
pool_type = vol.get_parent_pool().get_type()
if pool_type == virtinst.StoragePool.TYPE_SCSI:
info = append_str(info, _("SCSI device"))
elif pool_type == virtinst.StoragePool.TYPE_DISK:
if pool_type == virtinst.StoragePool.TYPE_DISK:
info = append_str(info, _("Disk device"))
elif pool_type == virtinst.StoragePool.TYPE_ISCSI:
info = append_str(info, _("iSCSI share"))
if shared:
info = append_str(info, _("Shareable"))

View File

@ -238,8 +238,8 @@ class vmmStoragePool(vmmLibvirtObject):
def can_change_alloc(self):
typ = self.get_type()
return (typ in [StoragePool.TYPE_LOGICAL, StoragePool.TYPE_ZFS])
def supports_volume_creation(self):
return self.get_xmlobj().supports_volume_creation()
def supports_volume_creation(self, clone=False):
return self.get_xmlobj().supports_volume_creation(clone=clone)
def get_type(self):
return self.get_xmlobj().type

View File

@ -395,13 +395,25 @@ class StoragePool(_StorageObject):
return self.type in users[propname]
return hasattr(self, propname)
def supports_volume_creation(self):
return self.type in [
StoragePool.TYPE_DIR, StoragePool.TYPE_FS,
StoragePool.TYPE_NETFS, StoragePool.TYPE_LOGICAL,
def supports_volume_creation(self, clone=False):
"""
Returns if pool supports volume creation. If @clone is set to True
returns if pool supports volume cloning (virVolCreateXMLFrom).
"""
supported = [
StoragePool.TYPE_DIR,
StoragePool.TYPE_FS,
StoragePool.TYPE_NETFS,
StoragePool.TYPE_DISK,
StoragePool.TYPE_RBD, StoragePool.TYPE_SHEEPDOG,
StoragePool.TYPE_ZFS]
StoragePool.TYPE_LOGICAL,
StoragePool.TYPE_RBD,
]
if not clone:
supported.extend([
StoragePool.TYPE_SHEEPDOG,
StoragePool.TYPE_ZFS,
])
return self.type in supported
def get_disk_type(self):
if (self.type == StoragePool.TYPE_DISK or