mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
feat(instances): the VM lists follow changes by themselves
A VM list showed what it read when it was loaded: a VM stopped from inside its guest or with virsh, or made or removed elsewhere, showed only after a reload, unlike the VM page, which reloads when its VM's state changes. The lists of all VMs and of one host's VMs now poll the states of their VMs, at once and then every 5 s as the VM page does, and reload when an answer differs from the one before. The states come from one libvirt call per host; a user who does not see hosts gets only their own VMs. The page in use (a dialog, a field, an unsaved XML edit, a job outcome shown) holds the reload until it is free; that check is shared with the job panel.
This commit is contained in:
parent
f88deb22c1
commit
eb6e6ca626
15 changed files with 276 additions and 11 deletions
|
|
@ -338,6 +338,25 @@ def record_migration(instance, new_compute):
|
|||
instance.save()
|
||||
|
||||
|
||||
def vm_states(user, computes):
|
||||
"""{compute pk: {"ok": True, "vms": {uuid: [name, state]}}, or {"ok": False}
|
||||
for a host that cannot be read}: what the VM lists poll, read from libvirt;
|
||||
for a user who does not see hosts only their own VMs (a VM is its host and
|
||||
UUID: one UUID may be defined on two hosts)."""
|
||||
show_hosts = user.is_superuser or user.has_perm("instances.view_instances")
|
||||
own = None if show_hosts else set(
|
||||
Instance.objects.filter(userinstance__user=user).values_list("compute_id", "uuid"))
|
||||
result = {}
|
||||
for compute in computes:
|
||||
try:
|
||||
vms = compute.proxy.get_domain_states() if compute.status is True else None
|
||||
except libvirtError:
|
||||
vms = None
|
||||
result[str(compute.pk)] = {"ok": False} if vms is None else {
|
||||
"ok": True, "vms": {u: s for u, s in vms.items() if own is None or (compute.pk, u) in own}}
|
||||
return result
|
||||
|
||||
|
||||
def migration_target(compute):
|
||||
"""The destination for the log: its host name, and the migration address
|
||||
when one is set and differs (else the migration goes to the host name)."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue