mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(vmbackups): restore a backup as a new VM
A ready backup has a Restore button (Backups page and the VM's tab) and POST /api/v1/backups/<uuid>/restore/. The form takes the new VM's name (default <vm>-restored), a compute that has the target's pool, the pool for its disks, Connect the network (off by default: the restored guest keeps the VM's addresses and host name) and Start after restore. The job page follows the restore. The backup.restore job holds what a new VM's job holds, the backup (shared) and the target. Before anything is made it checks again: the host is not in maintenance; the name is free in the panel and on the host (a VM made with virsh too); the backup's files are in the target, the disks at their size and the small files with their SHA-256; the host offers the definition's emulator, machine type and firmware, its networks, bridges and network filters; the destination pool has room and none of the copies' names. The new VM's UUID, MACs, volume names and NVRAM path are recorded first. Then the disks are copied from the target, the NVRAM file uploaded, maintenance checked once more, and the VM defined last and given to the superuser who restored it. The definition is the kept one rewritten as a clone's (rewrite_for_new_vm, taken out of _clone_definition for both): new name, UUID and SMBIOS UUID, MACs and filter parameters, a VNC password, no cloud-init seed of the VM's; with a new generation ID, each disk's source the restored file without the old chain, the NVRAM path, and links down unless connected. Recovery records a VM defined by the recorded UUID; otherwise it removes the copies and the NVRAM file by their recorded names.
This commit is contained in:
parent
7227867d78
commit
823d34cc18
16 changed files with 1280 additions and 305 deletions
|
|
@ -18,7 +18,7 @@ from vrtManager.backup import pool_space, target_pool
|
|||
from vrtManager.connection import wvmConnect
|
||||
from vrtManager.util import OperationError
|
||||
|
||||
from .forms import TargetForm, TargetPoolForm
|
||||
from .forms import RestoreForm, TargetForm, TargetPoolForm
|
||||
from .models import Backup, BackupTarget
|
||||
from .utils import inside_vm_pool
|
||||
|
||||
|
|
@ -159,3 +159,23 @@ def delete(request, uuid):
|
|||
# the job's page follows it: the pages listing backups show no backup's job
|
||||
return redirect("operations:job", op.pk)
|
||||
return redirect(same_origin_referer(request, reverse("vmbackups:index")))
|
||||
|
||||
|
||||
@superuser_only
|
||||
def restore(request, uuid):
|
||||
"""Restore a ready backup as a new VM: a backup.restore job, followed on its page."""
|
||||
backup = get_object_or_404(Backup.objects.select_related("target"), uuid=uuid, state=Backup.READY)
|
||||
form = RestoreForm(request.POST or None, backup=backup)
|
||||
if form.is_valid():
|
||||
data = form.cleaned_data
|
||||
raw = {"backup": str(backup.uuid), "compute": data["compute"].pk, "pool": data["pool"], "name": data["name"],
|
||||
"connect": data["connect"], "start": data["start"]}
|
||||
try:
|
||||
op = jobs.submit("backup.restore", request.user, raw, request.POST.get("submission_key", ""))
|
||||
except claims.Busy as busy:
|
||||
form.add_error(None, busy_message(busy, request.user))
|
||||
except (jobs.SubmissionConflict, libvirtError) as err:
|
||||
form.add_error(None, error_text(request, err))
|
||||
else:
|
||||
return redirect("operations:job", op.pk)
|
||||
return render(request, "vmbackups/restore.html", {"backup": backup, "form": form})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue