mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(computes): a host evacuates its chosen VMs to another host
The host's Instances page gets an Evacuate button. Its page lists the
host's VMs for a chosen destination: running ones ticked, shut-off ones
left to choose ("Also migrate the shut-off VMs"), and a VM with a disk
file the two hosts do not share refused with the reason, since it needs
a copy chosen on its own Migrate tab.
One "Evacuate host" job migrates them: a migrate job each (live with
auto converge; a shut-off VM offline), at most the chosen number at
once, so a VM that fails stays on the host and the rest go on. The
choice goes up to half the worker's slots, which a host's jobs may take,
less the evacuation's own. Cancelling it cancels the migrations that
run and starts no more. One evacuation runs at a time: it waits in a
worker slot, and several could leave none for their migrations. A VM
that left the host meanwhile is skipped (a migrate job takes the host it
is to leave from the evacuation and refuses another); a host whose record points
elsewhere since, or a worker lowered to one slot, stops it before the
next VM. A busy VM lets the others go first; one an uncertain job holds is
not waited for.
Migrations now hold the hosts' VM sets shared, so several migrate at
once; creates, clones, deletes and the VM list reconcile still wait for
them. A destination gone since the form was shown is refused, not
replaced by another. The uses of the NVRAM directory's pool take turns
(NVRAM_LOCK): two UEFI migrations at once would share a transient pool
that the first destroys under the second.
This commit is contained in:
parent
c9fef349d5
commit
d20254f757
18 changed files with 861 additions and 106 deletions
|
|
@ -16,13 +16,16 @@ from django.urls import reverse
|
|||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.decorators.debug import sensitive_post_parameters
|
||||
from webvirtcloud.middleware import error_text
|
||||
from instances.models import Instance
|
||||
from instances.utils import read_list_rows, vm_states
|
||||
from libvirt import libvirtError
|
||||
from libvirt import VIR_DOMAIN_XML_INACTIVE, libvirtError
|
||||
from logs.audit import audit, changed_fields, snapshot
|
||||
from operations import claims
|
||||
from operations import claims, jobs
|
||||
from operations.utils import busy_message
|
||||
from vrtManager.connection import CONN_SOCKET, CONN_SSH, CONN_TCP, CONN_TLS
|
||||
from vrtManager.hostdetails import wvmHostDetails
|
||||
from vrtManager.instance import wvmInstances
|
||||
from vrtManager.storage import wvmStorages
|
||||
|
||||
from computes.forms import (
|
||||
|
|
@ -226,6 +229,56 @@ def instances(request, compute_id):
|
|||
)
|
||||
|
||||
|
||||
@superuser_only
|
||||
def evacuate(request, compute_id):
|
||||
"""Migrates the chosen VMs of the host to another in one job, for the
|
||||
host's maintenance: a migrate job each, the chosen number at once; a
|
||||
running VM live, a shut-off one offline. A VM with a disk file the two
|
||||
hosts do not share is not offered: it takes a copy, chosen on its own
|
||||
Migrate tab."""
|
||||
from computes.jobs import parallel_limit
|
||||
from instances.jobs import migration_target
|
||||
|
||||
compute = get_object_or_404(Compute, pk=compute_id)
|
||||
targets = list(Compute.objects.exclude(pk=compute.pk).order_by("name"))
|
||||
if request.method == "POST":
|
||||
# the destination the form showed, not another one taken in its place
|
||||
target = get_object_or_404(Compute.objects.exclude(pk=compute.pk), pk=request.POST.get("target", "") or None)
|
||||
raw = {"compute": compute.pk, "target": target.pk, "parallel": request.POST.get("parallel", ""),
|
||||
"instances": [pk for pk in request.POST.getlist("instance") if pk.isdigit()]}
|
||||
try:
|
||||
op = jobs.submit("host.evacuate", request.user, raw, request.POST.get("submission_key", ""))
|
||||
except claims.Busy as busy:
|
||||
messages.error(request, busy_message(busy, request.user))
|
||||
except (ValueError, jobs.SubmissionConflict, libvirtError) as err:
|
||||
messages.error(request, error_text(request, err))
|
||||
else:
|
||||
jobs.remember_job(request, op)
|
||||
return redirect("instances", compute.pk)
|
||||
return redirect(reverse("evacuate", args=[compute.pk]) + f"?target={target.pk}")
|
||||
|
||||
chosen = request.GET.get("target")
|
||||
target = next((t for t in targets if str(t.pk) == chosen), targets[0] if targets else None)
|
||||
utils.refresh_instance_database(compute)
|
||||
instances = list(Instance.objects.filter(compute=compute).order_by("name"))
|
||||
read_list_rows(instances, [compute])
|
||||
dest = None
|
||||
for instance in instances if target else ():
|
||||
instance.refusal = None
|
||||
try:
|
||||
migration_target(instance, target.pk)
|
||||
dest = dest or wvmInstances(target.hostname, target.login, target.password, target.type)
|
||||
domain = instance.proxy.instance
|
||||
for xml in (domain.XMLDesc(0), domain.XMLDesc(VIR_DOMAIN_XML_INACTIVE)):
|
||||
if not all(disk["shared"] for disk in dest.disk_plan(instance.proxy, xml)):
|
||||
instance.refusal = _("A disk file is not on storage both hosts share: migrate it from its page")
|
||||
except libvirtError as err:
|
||||
instance.refusal = error_text(request, err)
|
||||
return render(request, "computes/evacuate.html",
|
||||
{"compute": compute, "targets": targets, "target": target, "instances": instances,
|
||||
"parallel": range(1, parallel_limit() + 1)})
|
||||
|
||||
|
||||
# the form of each kind of compute, by Compute.type
|
||||
FORMS = {form.conn_type: form for form in (TcpComputeForm, SshComputeForm, TlsComputeForm, SocketComputeForm)}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue