1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 00:46:05 +00:00

fix(instances): a failed power cycle says the VM stays off; templates have no autostart

Power Cycle forced the VM off and, when the start failed, showed only
libvirt's error: the page now also says the VM was forced off and stays
off, and the audit row says so. A template kept the autostart it had as a
VM, so the host started it although the panel refuses to: marking a
template turns autostart off, and autostart is refused on a template. The
autostart switch is disabled, with the reason, on a template and on a VM
that exists only while it runs (libvirt refuses autostart there).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-11 14:28:35 +03:00
parent 0ce1139c9d
commit 7dd68aaca4
10 changed files with 259 additions and 196 deletions

View file

@ -825,9 +825,14 @@ def powercycle(request, pk):
if instance.is_template:
messages.warning(request, _("Templates cannot be started."))
else:
with audit_vm(request, instance, "power cycle"):
with audit_vm(request, instance, "power cycle") as entry:
instance.proxy.force_shutdown()
instance.proxy.start()
try:
instance.proxy.start()
except Exception:
entry.action = "power cycle: forced off, the start failed"
messages.warning(request, _("The VM was forced off but did not start again: it stays off."))
raise
return get_safe_redirect(
request, default=reverse("instances:instance", args=[instance.id])
)
@ -1786,6 +1791,9 @@ def set_vcpu_hotplug(request, pk):
@serialize_instance_mutation
def set_autostart(request, pk):
instance = get_instance(request.user, pk)
if instance.is_template:
messages.error(request, _("Templates cannot be started."))
return _back(request, pk, "boot_opt")
with audit_vm(request, instance, "enable autostart"):
instance.proxy.set_autostart(1)
return _back(request, pk, "boot_opt")
@ -2406,6 +2414,8 @@ def set_template(request, pk):
instance_name=instance.name))
return _back(request, pk, "options")
with audit_vm(request, instance, "mark as template" if is_template else "unmark as template"):
if is_template and instance.autostart: # the host would start it
instance.proxy.set_autostart(0)
instance.is_template = is_template
instance.save(update_fields=["is_template"])
return _back(request, pk, "options")