1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +00:00

feat(computes): a host's Instances page is the VM list of its VMs

A host's Instances page had a table of its own, older than the VM list:
no state filter, no tag filter, no bulk bar, a two-line Name/Description
head and a round green button for a new VM. It now shows the VM list
itself, of that host's VMs and without a host column, beside the host's
tabs, Bulk Migrate and New VM. The bulk bar sends back to the list it
was used on.
This commit is contained in:
catborise 2026-11-21 20:17:07 +03:00
parent 59db1f5515
commit 383cbe89a6
16 changed files with 192 additions and 247 deletions

View file

@ -7,96 +7,31 @@
{% block page_heading %}{{ compute.name }} - {% trans "Instances" %}{% endblock page_heading %}
{% block page_heading_extra %}
<input id="filter" class="form-control w-auto" type="text" placeholder="{% trans 'Search' %}" aria-label="{% trans 'Search' %}">
{% if instances %}
<a href="{% url 'bulk_migrate' compute.id %}" class="btn btn-outline-primary">{% trans "Bulk Migrate" %}</a>
{% endif %}
{% if compute.maintenance %}
{# a disabled button shows no title: its wrapper says why #}
<span class="d-inline-block mt-1 float-end" tabindex="0" title="{% blocktrans with compute=compute.name %}{{ compute }} is in maintenance: no new VM or migration comes to it{% endblocktrans %}">
<button type="button" class="btn btn-success" disabled aria-label="{% trans "New Instance" %}">{% bs_icon 'plus-circle-fill' %}</button>
<span class="d-inline-block" tabindex="0" title="{% blocktrans with compute=compute.name %}{{ compute }} is in maintenance: no new VM or migration comes to it{% endblocktrans %}">
<button type="button" class="btn btn-primary" disabled>{% bs_icon 'plus-lg' %} {% trans "New VM" %}</button>
</span>
{% else %}
<a href="{% url 'instances:create_instance_select_type' compute.id %}"
class="btn btn-success mt-1 float-end" title="{% trans "New Instance" %}">
{% bs_icon 'plus-circle-fill' %}
</a>
{% endif %}
{% if instances %}
<a href="{% url 'bulk_migrate' compute.id %}" class="btn btn-outline-primary mt-1 me-1 float-end">{% trans "Bulk Migrate" %}</a>
{% include 'search_block.html' %}
<a href="{% url 'instances:create_instance_select_type' compute.id %}" class="btn btn-primary">{% bs_icon 'plus-lg' %} {% trans "New VM" %}</a>
{% endif %}
{% endblock page_heading_extra %}
{% block content %}
<div id="job-panel" aria-live="polite"></div>
<div class="row">
<div class="col-lg-12">
{% include "computes/host_nav.html" with section="instances" %}
{% include "computes/host_nav.html" with section="instances" %}
{% if compute.status is not True %}
<div class="alert alert-danger shadow-sm">
{% blocktrans with name=compute.name error=compute.connection_error %}Problem occurred with host {{ name }}: {{ error }}{% endblocktrans %}
</div>
</div>
<div class="row">
<div class="col-lg-12">
{% if compute.status is not True %}
<div class="alert alert-danger shadow-sm">
{% blocktrans with name=compute.name error=compute.connection_error %}Problem occurred with host {{ name }}: {{ error }}{% endblocktrans %}
</div>
{% endif %}
{% if not instances %}
{% if compute.status is True %}
<div class="alert alert-warning shadow-sm fade show">
{% bs_icon 'exclamation-triangle' %} <strong>{% trans "Warning" %}:</strong>
{% trans "Hypervisor doesn't have any Instances" %}
</div>
{% endif %}
{% else %}
<div class="table-responsive">
<table class="table table-hover align-middle" data-sortable>
<thead>
<tr>
<th scope="col">{% trans 'Name' %}<br>{% trans 'Description' %}</th>
<th scope="col">{% trans 'User' %}</th>
<th scope="col">{% trans 'Status' %}</th>
<th scope="col" data-sort-method="number">{% trans 'VCPU' %}</th>
<th scope="col" class="text-end" data-sort-method="number">{% trans 'Memory' %}</th>
<th scope="col" data-sort-method="none">{% trans 'Actions' %}</th>
</tr>
</thead>
<tbody class="searchable">
{% for instance in instances %}
<tr>
<td>
<a class="link-primary" href="{% url 'instances:instance' instance.id %}">{{ instance.name }}</a>
<br>
{% if instance.info %}<p class="m-0 small fst-italic">{{ instance.title }}</p>{% endif %}
{% with tags=instance.tags.all %}{% include 'common/tag_badges.html' with tags=tags|slice:":3" more=tags|slice:"3:" %}{% endwith %}
</td>
<td>
<em>
{% if instance.userinstance_set.all.count > 0 %}
{{ instance.userinstance_set.all.0.user }}
{% if instance.userinstance_set.all.count > 1 %}
(+{{ instance.userinstance_set.all.count|add:"-1" }})
{% endif %}
{% endif %}
</em>
</td>
<td>
{% include 'instance_state.html' %}
</td>
<td data-sort="{{ instance.info.3 }}">{{ instance.info.3 }}</td>
<td data-sort="{{ instance.info.2 }}"><p class="text-end">{% if instance.info %}{% widthratio instance.info.2 1024 1 %} MiB{% endif %}</p></td>
<td class="text-nowrap">
{% include 'instance_actions.html' %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
</div>
</div>
{% endif %}
{% include 'instances/vm_list.html' %}
{% endblock %}
{% block script %}
<script src="{% static 'js/poll.js' %}"></script>
{% include 'instances/vm_list_scripts.html' %}
{% job_panel_script job_resource %}
{% include "instances/vm_states_poll.html" %}
<script src="{% static 'js/table_filter.js' %}"></script>
{% endblock %}
{% endblock %}

View file

@ -74,7 +74,7 @@ class MaintenanceSwitchTests(TestCase):
self.compute.maintenance_since = timezone.now()
self.compute.save()
self.assertFalse(page().xpath("//a[@href=$u]", u=create))
self.assertTrue(page().xpath("//button[@disabled][contains(@aria-label, 'New Instance')]"))
self.assertTrue(page().xpath("//button[@disabled][contains(., 'New VM')]"))
class MaintenanceGuardTests(TestCase):

View file

@ -24,6 +24,7 @@ from django.views.decorators.http import require_POST
from webvirtcloud.middleware import error_text
from instances.models import Instance
from instances.utils import read_list_rows, vm_states
from instances.views import vm_list_context
from libvirt import libvirtError
from logs.audit import audit, changed_fields, snapshot
from operations import claims, jobs
@ -367,13 +368,13 @@ def instances(request, compute_id):
# read first: the poll's first answer then tells a change made while the page was read
states = vm_states(request.user, [compute])
utils.refresh_instance_database(compute)
instances = list(Instance.objects.filter(compute=compute).order_by("name").prefetch_related("userinstance_set", "tags"))
instances = list(Instance.objects.filter(compute=compute).order_by("name").prefetch_related("userinstance_set__user", "tags"))
read_list_rows(instances, [compute])
# the VM list's own list, of this host's VMs
return render(
request, "computes/instances.html",
{"compute": compute, "instances": instances, "job_resource": claims.compute_key(compute.id),
"states_url": reverse("instances:states") + f"?compute={compute.id}", "vm_states": states},
{"compute": compute, "one_host": compute, "show_hosts": True, "job_resource": claims.compute_key(compute.id),
**vm_list_context(request, instances, reverse("instances:states") + f"?compute={compute.id}", states)},
)