mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 09:26:03 +00:00
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.
This commit is contained in:
parent
c7d6f90823
commit
022737f143
17 changed files with 821 additions and 54 deletions
43
vrtManager/backup.py
Normal file
43
vrtManager/backup.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"""VM backups: the target pools and what a VM's backup holds (app vmbackups)."""
|
||||
|
||||
import libvirt
|
||||
from django.utils.translation import gettext_noop
|
||||
from lxml import etree
|
||||
|
||||
from vrtManager.util import OperationError
|
||||
|
||||
# pools that keep their volumes as files in one directory
|
||||
TARGET_TYPES = ("dir", "netfs")
|
||||
|
||||
|
||||
def target_pool(conn, name, uuid=None):
|
||||
"""The active dir or netfs pool name of conn's host; with uuid, only the
|
||||
pool a target registered, not another made since under its name."""
|
||||
try:
|
||||
pool = conn.get_storage(name)
|
||||
usable = (
|
||||
pool.isActive()
|
||||
and etree.fromstring(pool.XMLDesc(0)).get("type") in TARGET_TYPES
|
||||
and uuid in (None, pool.UUIDString())
|
||||
)
|
||||
except libvirt.libvirtError as err:
|
||||
if err.get_error_code() != libvirt.VIR_ERR_NO_STORAGE_POOL:
|
||||
raise
|
||||
usable = False
|
||||
if not usable:
|
||||
raise OperationError(
|
||||
gettext_noop(
|
||||
"Storage pool %(pool)s is not an active directory or NFS pool of this host, "
|
||||
"or not the one the backup target registered"
|
||||
),
|
||||
pool=name,
|
||||
)
|
||||
return pool
|
||||
|
||||
|
||||
def pool_space(pool):
|
||||
"""{name, size, free, used_percent} of a pool, as the storage pages show
|
||||
it; refreshed first, as files may have changed outside libvirt."""
|
||||
pool.refresh(0)
|
||||
_state, size, used, free = pool.info()
|
||||
return {"name": pool.name(), "size": size, "free": free, "used_percent": used * 100 / size if size else 0}
|
||||
Loading…
Add table
Add a link
Reference in a new issue