1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 19:56:48 +00:00
webvirtcloud/instances/templates/instance_actions.html
catborise 4556e70e47 fix(instances): lists show a VM that cannot be read as unknown
The instance lists read each VM from libvirt while rendering. When that
failed, the libvirt error replaced the whole page with the error page:
one VM removed out of band, or a host that is down, took the index or
a compute's instances page with it. To avoid that, both index views
left out every VM of a host that was not connected, so users saw their
VMs disappear.

- Instance.info is None when the VM cannot be read. The row then shows
  the name and owners from the database, the state "Unknown", and no
  title, vCPU, memory or actions.
- Both index views list the VMs of a host that is down. The grouped
  view marks the host "Not Connected" and leaves out its CPU and memory.
- A compute's instances page shows the connection error, and no longer
  says the hypervisor has no instances when it cannot be reached.

Checked against the test hosts with an unreachable compute added: both
index views list its VM as unknown next to the real VMs. The first
load takes 5.5 s (one bounded connection attempt), the next ones
0.1 s. The new tests fail on the previous code (VMs left out, error
pages).
2026-10-05 11:03:32 +03:00

78 lines
4 KiB
HTML

{% load i18n %}
{% load bootstrap_icons %}
{% if instance.info %}
<div class="btn-group" role="group" aria-label="Instance actions">
{% if instance.info.0 == 5 %}
{% if instance.is_template %}
<a href="{% url 'instances:instance' instance.id %}#clone" class="btn btn-sm btn-secondary" title="{% trans "Clone" %}">
{% bs_icon 'copy' %}
</a>
{% else %}
<form action="{% url 'instances:poweron' instance.id %}" method="post" style="display:inline;" onsubmit="showPleaseWaitDialog()">
{% csrf_token %}
<button type="submit" class="btn btn-sm btn-secondary" title="{% trans "Power On" %}">
{% bs_icon 'play-fill' %}
</button>
</form>
{% endif %}
<button class="btn btn-sm btn-secondary disabled" title="{% trans "Suspend" %}" disabled>{% bs_icon 'pause-fill' %}</button>
<button class="btn btn-sm btn-secondary disabled" title="{% trans "Power Off" %}" disabled>{% bs_icon 'power' %}</button>
<button class="btn btn-sm btn-secondary disabled" title="{% trans "Power Cycle" %}" disabled>{% bs_icon 'repeat' %}</button>
<button class="btn btn-sm btn-secondary disabled" title="{% trans "VNC Console" %}" disabled>
<span>{% bs_icon 'eye-fill' %}</span>
</button>
{% endif %}
{% if instance.info.0 == 3 %}
<form action="{% url 'instances:resume' instance.id %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" class="btn btn-sm btn-secondary" title="{% trans "Resume" %}">
{% bs_icon 'play-fill' %}
</button>
</form>
<button class="btn btn-sm btn-secondary disabled" title="{% trans "Suspend" %}" disabled>{% bs_icon 'pause-fill' %}</button>
<form action="{% url 'instances:force_off' instance.id %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" class="btn btn-sm btn-secondary" title="{% trans "Force Off" %}">
{% bs_icon 'power' %}
</button>
</form>
<button class="btn btn-sm btn-secondary disabled" title="{% trans "Power Cycle" %}" disabled>{% bs_icon 'repeat' %}</button>
<button class="btn btn-sm btn-secondary disabled" title="{% trans "VNC Console" %}" disabled>
<span>{% bs_icon 'eye-fill' %}</span>
</button>
{% endif %}
{% if instance.info.0 == 1 %}
<button class="btn btn-sm btn-secondary disabled" title="{% trans "Power On" %}" disabled>{% bs_icon 'play-fill' %}</button>
<form action="{% url 'instances:suspend' instance.id %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" class="btn btn-sm btn-secondary" title="{% trans "Suspend" %}">
{% bs_icon 'pause-fill' %}
</button>
</form>
<form action="{% url 'instances:poweroff' instance.id %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" class="btn btn-sm btn-secondary" title="{% trans "Power Off" %}">
{% bs_icon 'power' %}
</button>
</form>
<form action="{% url 'instances:powercycle' instance.id %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" class="btn btn-sm btn-secondary" title="{% trans "Power Cycle" %}">
{% bs_icon 'repeat' %}
</button>
</form>
<button class="btn btn-sm btn-secondary" type="button" onclick='open_console("{{ instance.compute.id }}-{{ instance.get_uuid }}")'
title="{% trans "Console" %}">
<span>{% bs_icon 'eye-fill' %}</span>
</button>
{% endif %}
</div>
{% block script %}
<script>
function open_console(uuid) {
url = '{% url 'console' %}?token=' + uuid + '';
window.open(url, '', 'width=850,height=650')
}
</script>
{% endblock script %}
{% endif %}