1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 08:56:07 +00:00
webvirtcloud/vmbackups/utils.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

38 lines
1.4 KiB
Python

from django.utils.translation import gettext_noop
from lxml import etree
from storages.forms import inside
from vrtManager.util import InUse
from .models import Backup, BackupTargetPool
def inside_vm_pool(conn, pool):
"""The name of another pool of the host whose directory holds the target
pool's: its backups would share that storage's failures."""
path = etree.fromstring(pool.XMLDesc(0)).findtext("target/path").rstrip("/")
for name, (_pool, directory) in conn.file_pools().items():
if name != pool.name() and inside(path, directory):
return name
return None
def refuse_backup_volume(compute, pool, volume):
"""A volume of a backup is deleted with its backup, on the Backups pages."""
for backup in Backup.objects.filter(target__pools__compute=compute, target__pools__pool=pool):
if volume.startswith(backup.prefix + "-"):
raise InUse(
gettext_noop("Volume %(volume)s belongs to a backup of %(vm)s; delete the backup on the Backups page"),
volume=volume,
vm=backup.vm_name,
)
def refuse_target_pool(compute, pool):
row = BackupTargetPool.objects.filter(compute=compute, pool=pool).select_related("target").first()
if row:
raise InUse(
gettext_noop("Storage pool %(pool)s is backup target %(target)s; remove it from the target first"),
pool=pool,
target=row.target.name,
)