mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(computes): putting a host in maintenance migrates its VMs; ready once none runs
A host was put in maintenance with its VMs still on it, and emptying it was a separate step. "Put in maintenance" on a host with VMs that run now opens Bulk Migrate, whose button migrates the chosen VMs and puts the host in maintenance in one transaction: with the job admitted, or not at all; a form sent again finds its job and does not put back a host taken out of maintenance since. The page also puts it in maintenance without migrating, for VMs that cannot move or when no host can take them. Maintenance is not refused while VMs run: it must be on before they move, or a new VM or Balance could take their place. The host shows instead whether it is ready: "Maintenance requested" while VMs other than shut-off ones remain on it (or it cannot be read), with its bulk migration's state; "In maintenance" once none does. None of its VMs starts or resumes there meanwhile. Ending maintenance during the bulk migration lets it go on.
This commit is contained in:
parent
22362de068
commit
d96fe940e9
14 changed files with 962 additions and 537 deletions
|
|
@ -239,6 +239,7 @@ def _finish_clone(op, clone, warning):
|
|||
if clone.get("memory"):
|
||||
proxy.resize_mem(clone["memory"], clone["memory"])
|
||||
if clone.get("start"):
|
||||
c.refuse_start() # put in maintenance while the disks were copied: the clone stays off
|
||||
proxy.start()
|
||||
except libvirtError as err:
|
||||
notes += say(_("The clone is made, but not as asked: %(error)s"), error=err)
|
||||
|
|
@ -494,6 +495,18 @@ def _revert_quota(user, instance, proxy, params):
|
|||
quota=utils.quota_message(quota), name=params["name"])
|
||||
|
||||
|
||||
def _revert_start(instance, proxy, params):
|
||||
"""A revert to a snapshot of the VM running or paused (with its memory)
|
||||
starts a shut-off VM, and one of it running resumes a paused VM: not on
|
||||
a host in maintenance (Compute.refuse_start). A disk-only one
|
||||
("disk-snapshot") keeps the VM as it is."""
|
||||
snapshot = proxy._snapshot(params["name"], params["external"])
|
||||
state = util.get_xml_path(snapshot.getXMLDesc(0), "/domainsnapshot/state")
|
||||
status = proxy.get_status()
|
||||
if status == 5 and state in ("running", "paused") or status == 3 and state == "running":
|
||||
instance.compute.refuse_start()
|
||||
|
||||
|
||||
@register
|
||||
class RevertSnapshot(Kind):
|
||||
name = "snapshot.revert"
|
||||
|
|
@ -507,7 +520,7 @@ class RevertSnapshot(Kind):
|
|||
def validate(self, user, params):
|
||||
instance = _authorized(user, params["instance"])
|
||||
proxy = _proxy(instance)
|
||||
proxy._snapshot(params["name"], params["external"])
|
||||
_revert_start(instance, proxy, params)
|
||||
_revert_quota(user, instance, proxy, params)
|
||||
|
||||
def plan(self, user, params):
|
||||
|
|
@ -528,8 +541,10 @@ class RevertSnapshot(Kind):
|
|||
proxy.check_external_revert(op.params["name"])
|
||||
else:
|
||||
proxy.check_internal_revert()
|
||||
instance = _instance(op.params["instance"])
|
||||
_revert_start(instance, proxy, op.params) # put in maintenance meanwhile, or the VM shut off
|
||||
# again: a resize while it was queued may have used the quota
|
||||
_revert_quota(op.user, _instance(op.params["instance"]), proxy, op.params)
|
||||
_revert_quota(op.user, instance, proxy, op.params)
|
||||
# a revert gives the VM the host devices it had then: not one given since to another VM
|
||||
has_hostdevs, definitions = _snapshot_definitions(proxy, op.params)
|
||||
if has_hostdevs:
|
||||
|
|
|
|||
|
|
@ -853,10 +853,12 @@ def poweron(request, pk):
|
|||
messages.warning(request, _("Templates cannot be started."))
|
||||
elif options.validated_data["fresh"]: # the saved state is discarded: the VM boots anew
|
||||
with audit_vm(request, instance, "power on without the saved state"):
|
||||
instance.compute.refuse_start()
|
||||
instance.proxy.check_start_hostdevs(restore=False)
|
||||
instance.proxy.start(VIR_DOMAIN_START_FORCE_BOOT)
|
||||
else:
|
||||
with audit_vm(request, instance, "power on"):
|
||||
instance.compute.refuse_start()
|
||||
instance.proxy.check_start_hostdevs()
|
||||
instance.proxy.start()
|
||||
|
||||
|
|
@ -873,6 +875,7 @@ def powercycle(request, pk):
|
|||
messages.warning(request, _("Templates cannot be started."))
|
||||
else:
|
||||
with audit_vm(request, instance, "power cycle") as entry:
|
||||
instance.compute.refuse_start() # before it stops: it would not start again
|
||||
instance.proxy.check_start_hostdevs(restore=False) # before it stops
|
||||
instance.proxy.force_shutdown()
|
||||
try:
|
||||
|
|
@ -916,6 +919,7 @@ def suspend(request, pk):
|
|||
def resume(request, pk):
|
||||
instance = get_instance(request.user, pk)
|
||||
with audit_vm(request, instance, "resume"):
|
||||
instance.compute.refuse_start()
|
||||
instance.proxy.resume()
|
||||
return get_safe_redirect(
|
||||
request, default=reverse("instances:instance", args=[instance.id])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue