1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00
webvirtcloud/vmbackups/forms.py
catborise 022737f143 feat(vmbackups): backup targets: a storage pool per host, checked to be one directory
A backup target is a dir or NFS storage pool the administrator makes on
the hosts and registers on the new Backup targets page (Backups in the
menu, superusers only). Each compute's pool is kept with its UUID, so a
pool replaced by another of the same name is refused. A second compute's
pool is accepted only when it is the same directory as the target's
first (the exclusive-create check migrations use). The target page shows
each pool's space and warns when the target is inside another pool's
directory, as its backups would share that storage's failures.

The storage pages refuse to delete a target's pool, and a volume of a
backup (page and API): backups are deleted from the Backups pages.
2026-11-17 07:40:08 +03:00

29 lines
1 KiB
Python

from django import forms
from django.utils.translation import gettext_lazy as _
from computes.models import Compute
from .models import BackupTarget
class TargetPoolForm(forms.Form):
"""A compute's storage pool for a target; computes that have one already are not offered."""
compute = forms.ModelChoiceField(Compute.objects.all(), label=_("Compute"))
pool = forms.CharField(label=_("Storage pool"), max_length=128)
def __init__(self, *args, target=None, **kwargs):
super().__init__(*args, **kwargs)
if target is not None:
self.fields["compute"].queryset = Compute.objects.exclude(backuptargetpool__target=target)
class TargetForm(TargetPoolForm):
name = forms.CharField(label=_("Name"), max_length=64)
field_order = ["name", "compute", "pool"]
def clean_name(self):
name = self.cleaned_data["name"]
if BackupTarget.objects.filter(name=name).exists():
raise forms.ValidationError(_("A backup target with this name exists"))
return name