1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

feat(vmbackups): pages and API for restoring over the VM and one disk

A ready backup's Restore button becomes a menu: as a new VM, over the VM
(offered when the backup has its VM row) and one disk. Restoring over the
VM shows each disk's volume now and the new one before it is confirmed,
and why not when it cannot be done. The API gains restore-over and
restore-disk actions, answered 202 with the job.
This commit is contained in:
catborise 2026-11-17 16:04:00 +03:00
parent e2335be21f
commit 44aa7afe04
17 changed files with 493 additions and 104 deletions

View file

@ -47,6 +47,24 @@ class RestoreForm(forms.Form):
self.fields["name"].initial = f"{backup.vm_name}-restored"
class RestoreDiskForm(forms.Form):
"""One disk of a backup restored as a new volume, attached to no VM."""
dev = forms.ChoiceField(label=_("Disk"))
compute = forms.ModelChoiceField(Compute.objects.none(), label=_("Compute"))
pool = forms.CharField(label=_("Storage pool"), max_length=128, initial="default")
name = forms.CharField(label=_("Volume name"), max_length=255)
def __init__(self, *args, backup, **kwargs):
super().__init__(*args, **kwargs)
disks = list(backup.files.filter(role="disk").order_by("dev"))
self.fields["dev"].choices = [(d.dev, d.dev) for d in disks]
self.fields["compute"].queryset = Compute.objects.filter(backuptargetpool__target=backup.target).order_by("name")
if disks:
first = disks[0]
self.fields["name"].initial = f"{backup.vm_name}-{first.dev}-restored.{'qcow2' if first.format == 'qcow2' else 'raw'}"
class PolicyForm(forms.ModelForm):
"""A backup schedule: a compute's VMs or chosen VMs, all on hosts that
have a pool of its target."""