mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
delete: Add _DiskData class for tracking path delete metadata
Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
57a1f19841
commit
82b75a93b6
@ -110,8 +110,9 @@ class vmmDeleteDialog(vmmGObjectUI):
|
|||||||
self.widget("delete-remove-storage").set_active(True)
|
self.widget("delete-remove-storage").set_active(True)
|
||||||
self.widget("delete-remove-storage").toggled()
|
self.widget("delete-remove-storage").toggled()
|
||||||
|
|
||||||
|
diskdatas = _build_diskdata_for_vm(self.vm)
|
||||||
_populate_storage_list(self.widget("delete-storage-list"),
|
_populate_storage_list(self.widget("delete-storage-list"),
|
||||||
self.vm, self.vm.conn)
|
self.vm, self.vm.conn, diskdatas)
|
||||||
|
|
||||||
|
|
||||||
################
|
################
|
||||||
@ -256,20 +257,58 @@ class vmmDeleteDialog(vmmGObjectUI):
|
|||||||
# UI init helpers #
|
# UI init helpers #
|
||||||
###################
|
###################
|
||||||
|
|
||||||
def _populate_storage_list(storage_list, vm, conn):
|
class _DiskData:
|
||||||
|
"""
|
||||||
|
Helper class to contain all info we need to decide whether we
|
||||||
|
should default to deleting a path
|
||||||
|
"""
|
||||||
|
@staticmethod
|
||||||
|
def from_disk(disk):
|
||||||
|
"""
|
||||||
|
Build _DiskData from a DeviceDisk object
|
||||||
|
"""
|
||||||
|
return _DiskData(
|
||||||
|
disk.target,
|
||||||
|
disk.path,
|
||||||
|
disk.read_only,
|
||||||
|
disk.shareable,
|
||||||
|
disk.device in ["cdrom", "floppy"])
|
||||||
|
|
||||||
|
def __init__(self, label, path, ro, shared, is_media):
|
||||||
|
self.label = label
|
||||||
|
self.path = path
|
||||||
|
self.ro = ro
|
||||||
|
self.shared = shared
|
||||||
|
self.is_media = is_media
|
||||||
|
|
||||||
|
|
||||||
|
def _build_diskdata_for_vm(vm):
|
||||||
|
"""
|
||||||
|
Return a list of _DiskData for all VM resources the app attempts to delete
|
||||||
|
"""
|
||||||
|
diskdatas = []
|
||||||
|
for disk in vm.xmlobj.devices.disk:
|
||||||
|
diskdatas.append(_DiskData.from_disk(disk))
|
||||||
|
|
||||||
|
diskdatas.append(
|
||||||
|
_DiskData("kernel", vm.get_xmlobj().os.kernel, True, False, True))
|
||||||
|
diskdatas.append(
|
||||||
|
_DiskData("initrd", vm.get_xmlobj().os.initrd, True, False, True))
|
||||||
|
diskdatas.append(
|
||||||
|
_DiskData("dtb", vm.get_xmlobj().os.dtb, True, False, True))
|
||||||
|
|
||||||
|
return diskdatas
|
||||||
|
|
||||||
|
|
||||||
|
def _populate_storage_list(storage_list, vm, conn, diskdatas):
|
||||||
|
"""
|
||||||
|
Fill in the storage list UI from the passed list of _DiskData
|
||||||
|
"""
|
||||||
model = storage_list.get_model()
|
model = storage_list.get_model()
|
||||||
model.clear()
|
model.clear()
|
||||||
|
|
||||||
diskdata = [(d.target, d.path, d.read_only, d.shareable,
|
for diskdata in diskdatas:
|
||||||
d.device in ["cdrom", "floppy"]) for
|
if not diskdata.path:
|
||||||
d in vm.xmlobj.devices.disk]
|
|
||||||
|
|
||||||
diskdata.append(("kernel", vm.get_xmlobj().os.kernel, True, False, True))
|
|
||||||
diskdata.append(("initrd", vm.get_xmlobj().os.initrd, True, False, True))
|
|
||||||
diskdata.append(("dtb", vm.get_xmlobj().os.dtb, True, False, True))
|
|
||||||
|
|
||||||
for target, path, ro, shared, is_media in diskdata:
|
|
||||||
if not path:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# There are a few pieces here
|
# There are a few pieces here
|
||||||
@ -284,12 +323,12 @@ def _populate_storage_list(storage_list, vm, conn):
|
|||||||
|
|
||||||
default = False
|
default = False
|
||||||
definfo = None
|
definfo = None
|
||||||
vol = conn.get_vol_by_path(path)
|
vol = conn.get_vol_by_path(diskdata.path)
|
||||||
can_del, delinfo = _can_delete(conn, vol, path)
|
can_del, delinfo = _can_delete(conn, vol, diskdata.path)
|
||||||
|
|
||||||
if can_del:
|
if can_del:
|
||||||
default, definfo = _do_we_default(conn, vm.get_name(), vol,
|
default, definfo = _do_we_default(conn, vm.get_name(), vol,
|
||||||
path, ro, shared, is_media)
|
diskdata)
|
||||||
|
|
||||||
info = None
|
info = None
|
||||||
if not can_del:
|
if not can_del:
|
||||||
@ -300,7 +339,7 @@ def _populate_storage_list(storage_list, vm, conn):
|
|||||||
icon = Gtk.STOCK_DIALOG_WARNING
|
icon = Gtk.STOCK_DIALOG_WARNING
|
||||||
icon_size = Gtk.IconSize.LARGE_TOOLBAR
|
icon_size = Gtk.IconSize.LARGE_TOOLBAR
|
||||||
|
|
||||||
row = [default, not can_del, path, target,
|
row = [default, not can_del, diskdata.path, diskdata.label,
|
||||||
bool(info), icon, icon_size, info]
|
bool(info), icon, icon_size, info]
|
||||||
model.append(row)
|
model.append(row)
|
||||||
|
|
||||||
@ -387,7 +426,7 @@ def _can_delete(conn, vol, path):
|
|||||||
return (ret, msg)
|
return (ret, msg)
|
||||||
|
|
||||||
|
|
||||||
def _do_we_default(conn, vm_name, vol, path, ro, shared, is_media):
|
def _do_we_default(conn, vm_name, vol, diskdata):
|
||||||
""" Returns (do we delete by default?, info string if not)"""
|
""" Returns (do we delete by default?, info string if not)"""
|
||||||
info = ""
|
info = ""
|
||||||
|
|
||||||
@ -399,19 +438,20 @@ def _do_we_default(conn, vm_name, vol, path, ro, shared, is_media):
|
|||||||
str1 += str2
|
str1 += str2
|
||||||
return str1
|
return str1
|
||||||
|
|
||||||
if ro:
|
if diskdata.ro:
|
||||||
info = append_str(info, _("Storage is read-only."))
|
info = append_str(info, _("Storage is read-only."))
|
||||||
elif not vol and not os.access(path, os.W_OK):
|
elif not vol and not os.access(diskdata.path, os.W_OK):
|
||||||
info = append_str(info, _("No write access to path."))
|
info = append_str(info, _("No write access to path."))
|
||||||
|
|
||||||
if shared:
|
if diskdata.shared:
|
||||||
info = append_str(info, _("Storage is marked as shareable."))
|
info = append_str(info, _("Storage is marked as shareable."))
|
||||||
|
|
||||||
if not info and is_media:
|
if not info and diskdata.is_media:
|
||||||
info = append_str(info, _("Storage is a media device."))
|
info = append_str(info, _("Storage is a media device."))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
names = virtinst.DeviceDisk.path_in_use_by(conn.get_backend(), path)
|
names = virtinst.DeviceDisk.path_in_use_by(conn.get_backend(),
|
||||||
|
diskdata.path)
|
||||||
|
|
||||||
if len(names) > 1:
|
if len(names) > 1:
|
||||||
namestr = ""
|
namestr = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user