mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(instances): a VM's destruction says what goes, and keeps what a kept file needs
The Destroy tab was a sub-tab with one sentence and a link; its confirmation page said only "This action is irreversible!" over a "Remove Instance's data" switch. The tab now shows the state and "Review destruction". The owner chose the confirmation layout from three rendered options: the VM and its host, that its definition, saved state and snapshot records go and that a running VM is forced off, two plans for the files (delete the disk files, or keep them), the VM's disks, what is always kept, the NVRAM choice, and Cancel. Codex reviewed destroying; this is fixed: - A disk file that cannot be deleted keeps the files below it, which it needs: they were deleted after it, leaving it broken. The files are deleted overlays first (split_disk_paths_by_use orders them by how many files each grows from), and if the files a kept one needs cannot be read, none of the rest goes. A message names each file kept so, and a failed deletion says the VM is removed.
This commit is contained in:
parent
43c9845ef8
commit
2793c74dfd
7 changed files with 128 additions and 61 deletions
|
|
@ -822,13 +822,25 @@ def destroy(request, pk):
|
|||
proxy.delete(flags)
|
||||
instance.delete()
|
||||
|
||||
# each disk has its own row: the VM is gone even if one is kept
|
||||
# each disk has its own row: the VM is gone even if one is kept; a
|
||||
# file that stays keeps the files below it, which it needs
|
||||
kept = set()
|
||||
for path in to_delete:
|
||||
if path in kept:
|
||||
messages.warning(request, _("Disk %(path)s was kept: a disk file that stays needs it") % {"path": path})
|
||||
continue
|
||||
try:
|
||||
with audit_vm(request, instance, f"delete volume {path}"):
|
||||
proxy.get_volume_by_path(path).delete(0)
|
||||
except libvirtError as err:
|
||||
messages.error(request, _("Disk %(path)s was not deleted: %(err)s") % {"path": path, "err": error_text(request, err)})
|
||||
messages.error(request, _("The VM is removed, but disk %(path)s was not deleted: %(err)s") % {
|
||||
"path": path, "err": error_text(request, err)})
|
||||
try:
|
||||
while (path := proxy.backing_path(path)) and path not in kept:
|
||||
kept.add(path)
|
||||
except libvirtError:
|
||||
# the files it needs are unknown: none of the rest goes
|
||||
kept.update(to_delete)
|
||||
for path in shared:
|
||||
messages.warning(request, _("Disk %(path)s is used by another VM and was kept") % {"path": path})
|
||||
return redirect(reverse("instances:index"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue