mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(vmbackups): delete a backup; the Backups page
Backups in the menu now opens a page of every backup, newest first, filtered by VM name, target and state; a removed VM's backups are marked. Each backup, there and on the VM's Backups tab, has a Delete button (also DELETE /api/v1/backups/<uuid>/, 202 with the job). The backup.delete job holds the backup and its target. Through the first of the target's computes that reaches its pool, it marks the backup deleting, removes the manifest first, so the target no longer holds a complete backup, then every other file named from the backup's UUID (also those a failed backup left), then the row. Recovery runs the same steps again. A backup being made is refused: its job is cancelled instead. States and consistency are shown in the reader's language.
This commit is contained in:
parent
f4559acbc7
commit
7227867d78
17 changed files with 607 additions and 117 deletions
|
|
@ -9,11 +9,17 @@ from operations.api.serializers import OperationSerializer
|
|||
from webvirtcloud.serializers import ErrorSerializer
|
||||
|
||||
from .models import Backup
|
||||
from .serializers import BackupSerializer, CreateBackupSerializer
|
||||
from .serializers import BackupSerializer, CreateBackupSerializer, SubmissionSerializer
|
||||
|
||||
|
||||
def _accepted(request, op):
|
||||
return Response(OperationSerializer(op, context={"request": request}).data, status=status.HTTP_202_ACCEPTED,
|
||||
headers={"Location": reverse("operation-detail", args=[op.pk])})
|
||||
|
||||
|
||||
class BackupViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
|
||||
"""VM backups: list, read, and back a VM up (a job, answered 202)."""
|
||||
"""VM backups: list, read, back a VM up and delete a backup (jobs,
|
||||
answered 202)."""
|
||||
|
||||
permission_classes = [IsSuperUser]
|
||||
serializer_class = BackupSerializer
|
||||
|
|
@ -27,6 +33,12 @@ class BackupViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.G
|
|||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
data = serializer.validated_data
|
||||
raw = {"instance": data["instance"].pk, "target": data["target"].pk, "frozen": data["frozen"]}
|
||||
op = jobs.submit("backup.create", request.user, raw, data["submission_key"])
|
||||
return Response(OperationSerializer(op, context={"request": request}).data, status=status.HTTP_202_ACCEPTED,
|
||||
headers={"Location": reverse("operation-detail", args=[op.pk])})
|
||||
return _accepted(request, jobs.submit("backup.create", request.user, raw, data["submission_key"]))
|
||||
|
||||
@extend_schema(request=SubmissionSerializer, responses={202: OperationSerializer, 409: ErrorSerializer})
|
||||
def destroy(self, request, uuid=None):
|
||||
backup = self.get_object()
|
||||
serializer = SubmissionSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
key = serializer.validated_data["submission_key"]
|
||||
return _accepted(request, jobs.submit("backup.delete", request.user, {"backup": str(backup.uuid)}, key))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue