1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 19:26:48 +00:00
webvirtcloud/instances/templates/instance_actions.html
catborise 7e08224330 perf(instances): instance lists read a VM's info once per row
The VM rows of the instance lists used instance.proxy.instance.info in
every state check, the vCPU column and the action buttons. A template
calls the method on each lookup, so every row made 7 virDomainGetInfo
RPCs (8 on a compute's instances page), and the memory column read the
domain XML once more.

- Instance.info reads virDomainGetInfo once per request; the lists and
  instance_actions.html use it.
- The memory column of both index views comes from the same info
  (current memory) instead of the domain XML. The value is the same:
  checked against currentMemory for every running and shut-off VM of
  the test hosts.

A row now makes one info call and one XML read (the title). The new
test counts the calls in the grouped and non-grouped index and on the
compute instances page; it fails on the previous code with 7 and 8
calls.
2026-10-05 10:17:47 +03:00

76 lines
No EOL
4 KiB
HTML

{% load i18n %}
{% load bootstrap_icons %}
<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 %}