mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +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:
parent
59db1f5515
commit
383cbe89a6
16 changed files with 192 additions and 247 deletions
|
|
@ -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 %}
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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)},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -40,86 +40,7 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
<div class="col-lg-12">
|
||||
{% if instances %}
|
||||
{# the state filter: table_filter.js counts each state's VMs the search finds #}
|
||||
<input type="hidden" id="state-filter" value="">
|
||||
<nav class="mb-2" aria-label="{% trans "VM states" %}">
|
||||
<div class="nav nav-pills flex-wrap gap-1" id="state-pills">
|
||||
<button type="button" class="nav-link active py-1 px-2" data-pill="" aria-pressed="true">
|
||||
{% trans "All" %} <span class="badge text-bg-light ms-1" data-count-state=""></span>
|
||||
</button>
|
||||
{% for state in states %}
|
||||
<button type="button" class="nav-link py-1 px-2" data-pill="{{ state }}" aria-pressed="false" hidden>
|
||||
{{ state }} <span class="badge text-bg-light ms-1" data-count-state="{{ state }}"></span>
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</nav>
|
||||
{% include 'common/tag_filter.html' %}
|
||||
{% if powerable %}
|
||||
{# the VMs chosen in the list (bulk_power_box.html), a job each (instances.jobs.POWER); bulk_power.js counts those on screen #}
|
||||
{# and shows this bar at the foot of the window while any is chosen #}
|
||||
<form id="bulk-power" class="fixed-bottom bg-body border-top shadow-lg py-2" action="{% url 'instances:bulk_power' %}" method="post"
|
||||
aria-label="{% trans "The chosen VMs" %}" hidden>{% csrf_token %}{% submission_key %}
|
||||
<div class="container d-flex flex-wrap align-items-center gap-2">
|
||||
<span class="fw-semibold me-2" id="bulk-power-count" data-text="{% trans "%(count)s chosen" %}"
|
||||
data-too-many="{% blocktrans with max=bulk_max %}%(count)s chosen: at most {{ max }} at once{% endblocktrans %}" data-max="{{ bulk_max }}" aria-live="polite"></span>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Power the chosen VMs" %}">
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="start">{% trans "Start" %}</button>
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="shutdown"
|
||||
data-confirm="{% trans "Shut down the chosen VMs? Their guests are asked to power off." %}">{% trans "Shut down" %}</button>
|
||||
<button type="submit" class="btn btn-outline-danger" name="action" value="force_off"
|
||||
data-confirm="{% trans "Force off the chosen VMs? They stop at once, as if unplugged, and may lose unsaved data." %}">{% trans "Force off" %}</button>
|
||||
</div>
|
||||
{% if snapshotable %}
|
||||
{# external, without memory and without freezing file systems: the VM's Snapshots tab has those choices #}
|
||||
<div class="dropup">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" data-bs-auto-close="outside"
|
||||
aria-expanded="false">{% trans "Snapshot" %}</button>
|
||||
<div class="dropdown-menu p-3" style="width: 20rem">
|
||||
<label class="form-label" for="bulk-snapshot-name">{% trans "Snapshot name" %}</label>
|
||||
<div class="input-group input-group-sm">
|
||||
<input class="form-control" type="text" name="snapshot_name" id="bulk-snapshot-name" maxlength="64" aria-describedby="bulk-snapshot-help">
|
||||
<button type="submit" class="btn btn-primary" name="action" value="snapshot" formaction="{% url 'instances:bulk_snapshot' %}">{% trans "Take snapshots" %}</button>
|
||||
</div>
|
||||
<div class="form-text" id="bulk-snapshot-help">{% trans "An external snapshot of each chosen VM, without memory and without freezing its file systems" %}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if request.user.is_superuser %}
|
||||
{# tags are a superuser's, as on the VM's Settings tab #}
|
||||
<div class="dropup">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" data-bs-auto-close="outside"
|
||||
aria-expanded="false">{% trans "Tag" %}</button>
|
||||
<div class="dropdown-menu p-3" style="width: 20rem">
|
||||
<label class="form-label" for="bulk-tag">{% trans "Tag" %}</label>
|
||||
<input class="form-control form-control-sm mb-2" type="text" name="tag" id="bulk-tag" list="bulk-tag-names">
|
||||
<datalist id="bulk-tag-names">{% for tag in tag_names %}<option value="{{ tag }}">{% endfor %}</datalist>
|
||||
<button type="submit" class="btn btn-sm btn-primary" name="action" value="tag_add" formaction="{% url 'instances:bulk_tag' %}">{% trans "Add tag" %}</button>
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary" name="action" value="tag_remove" formaction="{% url 'instances:bulk_tag' %}">{% trans "Remove tag" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<button type="button" class="btn btn-sm btn-link ms-auto" id="bulk-power-clear">{% trans "Clear the choice" %}</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
<div id="filter-status" class="visually-hidden" role="status" data-text="{% trans "%(shown)s of %(all)s VMs match" %}"></div>
|
||||
{% endif %}
|
||||
{% if not instances %}
|
||||
<p class="text-center text-body-secondary py-4">{% trans "There are no VMs here yet." %}</p>
|
||||
{% elif app_settings.VIEW_INSTANCES_LIST_STYLE == 'grouped' and request.user.is_superuser %}
|
||||
{% include 'allinstances_index_grouped.html' %}
|
||||
{% else %}
|
||||
{% include 'allinstances_index_nongrouped.html' %}
|
||||
{% endif %}
|
||||
{% if instances %}
|
||||
{# table_filter.js shows it while no row matches #}
|
||||
<div id="no-match" class="text-center text-body-secondary py-4" hidden>
|
||||
{% trans "No VM matches the filters." %}
|
||||
<button type="button" class="btn btn-link" id="clear-filters">{% trans "Clear the filters" %}</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include 'instances/vm_list.html' %}
|
||||
</div>
|
||||
<div class="modal fade" id="find-address" tabindex="-1" aria-labelledby="find-address-title" aria-hidden="true"
|
||||
data-url="{% url 'instances:find_address' %}" data-failed="{% trans "The search did not go through. Try again." %}"
|
||||
|
|
@ -168,15 +89,8 @@
|
|||
</div>
|
||||
{% endblock content %}
|
||||
{% block script %}
|
||||
<script src="{% static 'js/poll.js' %}"></script>
|
||||
{% include "instances/vm_states_poll.html" %}
|
||||
<script src="{% static 'js/table_filter.js' %}"></script>
|
||||
{% include 'instances/vm_list_scripts.html' %}
|
||||
<script src="{% static 'js/find_address.js' %}"></script>
|
||||
{% if app_settings.VIEW_INSTANCES_LIST_STYLE == 'grouped' and request.user.is_superuser %}
|
||||
<script src="{% static 'js/host_groups.js' %}"></script>
|
||||
{% endif %}
|
||||
{# after host_groups.js: the hosts it collapses are off screen #}
|
||||
{% if powerable %}<script src="{% static 'js/bulk_power.js' %}"></script>{% endif %}
|
||||
{% if request.user.is_superuser %}
|
||||
<script src="{% static 'js/new_vm_dialog.js' %}"></script>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<tr>
|
||||
<th scope="col" data-sort-method="none">{% if powerable %}<input class="form-check-input" type="checkbox" id="bulk-power-shown" aria-label="{% trans "Choose the VMs shown" %}">{% else %}<span class="visually-hidden">{% trans "Chosen" %}</span>{% endif %}</th>
|
||||
<th scope="col">{% trans 'Name' %}</th>
|
||||
{% if show_hosts %}
|
||||
{% if show_hosts and not one_host %}
|
||||
<th scope="col">{% trans 'Host' %}</th>
|
||||
{% endif %}
|
||||
<th scope="col">{% trans 'Status' %}</th>
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
<tr data-tags="{% for tag in instance.tags.all %}{{ tag }}{% if not forloop.last %} {% endif %}{% endfor %}" data-search="{{ instance.name }}{% if instance.info %} {{ instance.title }}{% endif %}{% if show_hosts %} {{ instance.compute.name }}{% for owner in instance.userinstance_set.all %} {{ owner.user }}{% endfor %}{% endif %}">
|
||||
<td>{% include 'instances/bulk_power_box.html' %}</td>
|
||||
<td>{% include 'instance_name_cell.html' with owners=show_hosts %}</td>
|
||||
{% if show_hosts %}
|
||||
{% if show_hosts and not one_host %}
|
||||
<td>
|
||||
{# the host pages are a superuser's #}
|
||||
{% if request.user.is_superuser %}<a href="{% url 'overview' instance.compute.id %}">{{ instance.compute.name }}</a>{% else %}{{ instance.compute.name }}{% endif %}
|
||||
|
|
|
|||
84
instances/templates/instances/vm_list.html
Normal file
84
instances/templates/instances/vm_list.html
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
{% load i18n %}{% load operations %}
|
||||
{# the VM list of instances (instances.views.vm_list_context), on the VM list and on a host's Instances page #}
|
||||
{# (one_host: no host column, no host groups); its scripts are vm_list_scripts.html #}
|
||||
{% if instances %}
|
||||
{# the state filter: table_filter.js counts each state's VMs the search finds #}
|
||||
<input type="hidden" id="state-filter" value="">
|
||||
<nav class="mb-2" aria-label="{% trans "VM states" %}">
|
||||
<div class="nav nav-pills flex-wrap gap-1" id="state-pills">
|
||||
<button type="button" class="nav-link active py-1 px-2" data-pill="" aria-pressed="true">
|
||||
{% trans "All" %} <span class="badge text-bg-light ms-1" data-count-state=""></span>
|
||||
</button>
|
||||
{% for state in states %}
|
||||
<button type="button" class="nav-link py-1 px-2" data-pill="{{ state }}" aria-pressed="false" hidden>
|
||||
{{ state }} <span class="badge text-bg-light ms-1" data-count-state="{{ state }}"></span>
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</nav>
|
||||
{% include 'common/tag_filter.html' %}
|
||||
{% if powerable %}
|
||||
{# the VMs chosen in the list (bulk_power_box.html), a job each (instances.jobs.POWER); bulk_power.js counts those on screen #}
|
||||
{# and shows this bar at the foot of the window while any is chosen #}
|
||||
<form id="bulk-power" class="fixed-bottom bg-body border-top shadow-lg py-2" action="{% url 'instances:bulk_power' %}" method="post"
|
||||
aria-label="{% trans "The chosen VMs" %}" hidden>{% csrf_token %}{% submission_key %}
|
||||
<input type="hidden" name="next" value="{{ request.get_full_path }}">
|
||||
<div class="container d-flex flex-wrap align-items-center gap-2">
|
||||
<span class="fw-semibold me-2" id="bulk-power-count" data-text="{% trans "%(count)s chosen" %}"
|
||||
data-too-many="{% blocktrans with max=bulk_max %}%(count)s chosen: at most {{ max }} at once{% endblocktrans %}" data-max="{{ bulk_max }}" aria-live="polite"></span>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Power the chosen VMs" %}">
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="start">{% trans "Start" %}</button>
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="shutdown"
|
||||
data-confirm="{% trans "Shut down the chosen VMs? Their guests are asked to power off." %}">{% trans "Shut down" %}</button>
|
||||
<button type="submit" class="btn btn-outline-danger" name="action" value="force_off"
|
||||
data-confirm="{% trans "Force off the chosen VMs? They stop at once, as if unplugged, and may lose unsaved data." %}">{% trans "Force off" %}</button>
|
||||
</div>
|
||||
{% if snapshotable %}
|
||||
{# external, without memory and without freezing file systems: the VM's Snapshots tab has those choices #}
|
||||
<div class="dropup">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" data-bs-auto-close="outside"
|
||||
aria-expanded="false">{% trans "Snapshot" %}</button>
|
||||
<div class="dropdown-menu p-3" style="width: 20rem">
|
||||
<label class="form-label" for="bulk-snapshot-name">{% trans "Snapshot name" %}</label>
|
||||
<div class="input-group input-group-sm">
|
||||
<input class="form-control" type="text" name="snapshot_name" id="bulk-snapshot-name" maxlength="64" aria-describedby="bulk-snapshot-help">
|
||||
<button type="submit" class="btn btn-primary" name="action" value="snapshot" formaction="{% url 'instances:bulk_snapshot' %}">{% trans "Take snapshots" %}</button>
|
||||
</div>
|
||||
<div class="form-text" id="bulk-snapshot-help">{% trans "An external snapshot of each chosen VM, without memory and without freezing its file systems" %}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if request.user.is_superuser %}
|
||||
{# tags are a superuser's, as on the VM's Settings tab #}
|
||||
<div class="dropup">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" data-bs-auto-close="outside"
|
||||
aria-expanded="false">{% trans "Tag" %}</button>
|
||||
<div class="dropdown-menu p-3" style="width: 20rem">
|
||||
<label class="form-label" for="bulk-tag">{% trans "Tag" %}</label>
|
||||
<input class="form-control form-control-sm mb-2" type="text" name="tag" id="bulk-tag" list="bulk-tag-names">
|
||||
<datalist id="bulk-tag-names">{% for tag in tag_names %}<option value="{{ tag }}">{% endfor %}</datalist>
|
||||
<button type="submit" class="btn btn-sm btn-primary" name="action" value="tag_add" formaction="{% url 'instances:bulk_tag' %}">{% trans "Add tag" %}</button>
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary" name="action" value="tag_remove" formaction="{% url 'instances:bulk_tag' %}">{% trans "Remove tag" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<button type="button" class="btn btn-sm btn-link ms-auto" id="bulk-power-clear">{% trans "Clear the choice" %}</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
<div id="filter-status" class="visually-hidden" role="status" data-text="{% trans "%(shown)s of %(all)s VMs match" %}"></div>
|
||||
{% endif %}
|
||||
{% if not instances %}
|
||||
<p class="text-center text-body-secondary py-4">{% trans "There are no VMs here yet." %}</p>
|
||||
{% elif app_settings.VIEW_INSTANCES_LIST_STYLE == 'grouped' and request.user.is_superuser and not one_host %}
|
||||
{% include 'allinstances_index_grouped.html' %}
|
||||
{% else %}
|
||||
{% include 'allinstances_index_nongrouped.html' %}
|
||||
{% endif %}
|
||||
{% if instances %}
|
||||
{# table_filter.js shows it while no row matches #}
|
||||
<div id="no-match" class="text-center text-body-secondary py-4" hidden>
|
||||
{% trans "No VM matches the filters." %}
|
||||
<button type="button" class="btn btn-link" id="clear-filters">{% trans "Clear the filters" %}</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
9
instances/templates/instances/vm_list_scripts.html
Normal file
9
instances/templates/instances/vm_list_scripts.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{% load static %}{# the scripts of instances/vm_list.html #}
|
||||
<script src="{% static 'js/poll.js' %}"></script>
|
||||
{% include "instances/vm_states_poll.html" %}
|
||||
<script src="{% static 'js/table_filter.js' %}"></script>
|
||||
{% if app_settings.VIEW_INSTANCES_LIST_STYLE == 'grouped' and request.user.is_superuser and not one_host %}
|
||||
<script src="{% static 'js/host_groups.js' %}"></script>
|
||||
{% endif %}
|
||||
{# after host_groups.js: the hosts it collapses are off screen #}
|
||||
{% if powerable %}<script src="{% static 'js/bulk_power.js' %}"></script>{% endif %}
|
||||
|
|
@ -182,6 +182,25 @@ class BulkPowerTestCase(TransactionTestCase):
|
|||
self.assertEqual(said, ["a chosen VM: you may not power it now", "1 VM is queued; the Jobs page follows it."])
|
||||
self.assertEqual(Operation.objects.get().params["instance"], self.vms[0].pk)
|
||||
|
||||
def test_a_refusal_goes_back_to_the_list_it_came_from(self):
|
||||
host_list = reverse("instances", args=[self.vms[0].compute_id])
|
||||
for given, back in ((host_list, host_list), ("?page=2", reverse("instances:index")), ("//example.com/", reverse("instances:index")),
|
||||
("https://example.com/", reverse("instances:index"))):
|
||||
response = self.client.post(reverse("instances:bulk_power"), {"action": "reboot", "vm": [self.vms[0].pk],
|
||||
"submission_key": "key-bulkpow1", "next": given})
|
||||
self.assertRedirects(response, back, fetch_redirect_response=False)
|
||||
|
||||
def test_a_host_s_instances_page_has_the_vm_list_and_its_bar(self):
|
||||
host_list = reverse("instances", args=[self.vms[0].compute_id])
|
||||
with patch("computes.views.vm_states", return_value={}), \
|
||||
patch("computes.views.utils.refresh_instance_database"), patch("computes.views.read_list_rows"):
|
||||
page = html.fromstring(self.client.get(host_list).content)
|
||||
self.assertEqual(sorted(int(box.get("value")) for box in page.xpath("//input[@name='vm']")), [vm.pk for vm in self.vms])
|
||||
(form,) = page.xpath("//form[@id='bulk-power']")
|
||||
self.assertEqual(form.xpath(".//input[@name='next']/@value"), [host_list])
|
||||
self.assertTrue(page.xpath("//*[@id='state-pills']"))
|
||||
self.assertNotIn("Host", page.xpath("//thead//th/text()")) # one host: no host column
|
||||
|
||||
def test_an_unknown_action_or_too_many_vms_is_refused(self):
|
||||
self.submit("reboot", self.vms)
|
||||
response = self.client.post(reverse("instances:bulk_power"), {"action": "start", "vm": [str(n) for n in range(1, 502)],
|
||||
|
|
|
|||
|
|
@ -98,8 +98,9 @@ class VmTagsTests(TestCase):
|
|||
with patch("computes.views.utils.refresh_instance_database"), patch("computes.views.vm_states", return_value={}), \
|
||||
patch("computes.views.read_list_rows"):
|
||||
page = lxml_html.fromstring(self.client.get(reverse("instances", args=[self.vm.compute_id])).content)
|
||||
self.assertEqual(page.xpath("//td//span[contains(@class,'tag-badge')][not(ancestor::*[@hidden])]/text()[last()]"),
|
||||
[" a1", " b2", " c3"])
|
||||
# the VM list's badges: each chooses its tag in the tag filter
|
||||
self.assertEqual(page.xpath("//td//button[@data-tag-filter][not(ancestor::*[@hidden])]/@data-tag-filter"),
|
||||
["a1", "b2", "c3"])
|
||||
self.assertEqual(page.xpath("//button[@data-show-tags]/@title"), ["d4"])
|
||||
# the tags "…" shows take the focus from it (table_filter.js), not buttons here
|
||||
self.assertEqual(page.xpath("//button[@data-show-tags]/following-sibling::span[1]/@tabindex"), ["-1"])
|
||||
|
|
|
|||
|
|
@ -30,13 +30,14 @@ from django.contrib.auth.decorators import permission_required
|
|||
from django.contrib.auth.models import User
|
||||
from django.core import signing
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
from django.http import Http404, HttpResponse, JsonResponse
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect, JsonResponse
|
||||
from django.db import transaction
|
||||
from django.db.models import Prefetch, prefetch_related_objects
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
from django.template.defaultfilters import filesizeformat
|
||||
from django.utils import timezone
|
||||
from django.utils.http import url_has_allowed_host_and_scheme
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy, gettext_noop, ngettext
|
||||
from django.views.decorators.http import require_POST
|
||||
|
|
@ -112,6 +113,22 @@ def index(request):
|
|||
# a host of their own VMs is down
|
||||
own_hosts_down = any(c.status is not True for c in computes)
|
||||
utils.read_list_rows(instances, computes)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"allinstances.html",
|
||||
{"computes": computes, "show_hosts": show_hosts, "own_hosts_down": own_hosts_down,
|
||||
# the hosts a new VM can go to: one that stopped answering since status has no numbers
|
||||
"reachable_computes": [c for c in computes if c.status is True and c.ram_usage is not None],
|
||||
"unreachable_computes": [c for c in computes if c.status is not True],
|
||||
**vm_list_context(request, instances, reverse("instances:states"), vm_states)},
|
||||
)
|
||||
|
||||
|
||||
def vm_list_context(request, instances, states_url, vm_states):
|
||||
"""What the VM list (instances/vm_list.html) shows of instances, read with their info, on the
|
||||
VM list and on a host's Instances page: its filters, its states' poll and its bulk bar; their DRBD
|
||||
states read afresh while the list shows them."""
|
||||
if app_settings.VM_DRBD_STATUS == "True":
|
||||
# read here, once per host and all hosts at once (a list waits DRBD_STATUS_TIMEOUT at most):
|
||||
# the VM page alone left the list showing an old state
|
||||
|
|
@ -123,27 +140,21 @@ def index(request):
|
|||
if state != instance.drbd:
|
||||
instance.drbd = state
|
||||
Instance.objects.filter(pk=instance.pk).update(drbd=state)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"allinstances.html",
|
||||
{"computes": computes, "instances": instances, "show_hosts": show_hosts, "own_hosts_down": own_hosts_down,
|
||||
# the hosts a new VM can go to: one that stopped answering since status has no numbers
|
||||
"reachable_computes": [c for c in computes if c.status is True and c.ram_usage is not None],
|
||||
"unreachable_computes": [c for c in computes if c.status is not True],
|
||||
"states": [label for label, _color in STATES.values()] + [UNKNOWN[0]],
|
||||
"tags": Tag.counts(instances),
|
||||
"states_url": reverse("instances:states"), "vm_states": vm_states,
|
||||
# the VMs this user may power (_power_instance): theirs, or every one for a superuser
|
||||
# a superuser's bulk tag box offers every tag, as the Settings tab's picker
|
||||
"tag_names": list(Tag.objects.order_by("name").values_list("name", flat=True)) if request.user.is_superuser else [],
|
||||
"bulk_max": BULK_MAX,
|
||||
# the bulk snapshot box: for one who may snapshot a listed VM (change rights and the permission)
|
||||
"snapshotable": request.user.is_superuser or (request.user.has_perm("instances.snapshot_instances") and
|
||||
UserInstance.objects.filter(user=request.user, is_change=True).exists()),
|
||||
"powerable": {i.pk for i in instances} if request.user.is_superuser else
|
||||
set(UserInstance.objects.filter(user=request.user).values_list("instance_id", flat=True))},
|
||||
)
|
||||
return {
|
||||
"instances": instances,
|
||||
"states": [label for label, _color in STATES.values()] + [UNKNOWN[0]],
|
||||
"tags": Tag.counts(instances),
|
||||
"states_url": states_url, "vm_states": vm_states,
|
||||
# a superuser's bulk tag box offers every tag, as the Settings tab's picker
|
||||
"tag_names": list(Tag.objects.order_by("name").values_list("name", flat=True)) if request.user.is_superuser else [],
|
||||
"bulk_max": BULK_MAX,
|
||||
# the bulk snapshot box: for one who may snapshot a listed VM (change rights and the permission)
|
||||
"snapshotable": request.user.is_superuser or (request.user.has_perm("instances.snapshot_instances") and
|
||||
UserInstance.objects.filter(user=request.user, is_change=True).exists()),
|
||||
# the VMs this user may power (_power_instance): theirs, or every one for a superuser
|
||||
"powerable": {i.pk for i in instances} if request.user.is_superuser else
|
||||
set(UserInstance.objects.filter(user=request.user).values_list("instance_id", flat=True)),
|
||||
}
|
||||
|
||||
|
||||
def _listed_computes(user, computes):
|
||||
|
|
@ -711,6 +722,15 @@ def _power_instance(user, pk):
|
|||
BULK_MAX = 500
|
||||
|
||||
|
||||
def _back_to_list(request):
|
||||
"""The VM list the bulk form was sent from (its next field): the VM list or a host's Instances page."""
|
||||
url = request.POST.get("next", "")
|
||||
# a path of this site; not "?page=2", which is the bulk view's own address, nor redirect()'s view names
|
||||
if url.startswith("/") and url_has_allowed_host_and_scheme(url, allowed_hosts={request.get_host()}):
|
||||
return HttpResponseRedirect(url)
|
||||
return redirect("instances:index")
|
||||
|
||||
|
||||
def _chosen_vms(request):
|
||||
"""The VMs chosen on the VM list (its bulk form's boxes), as ids, each once."""
|
||||
return list(dict.fromkeys(int(pk) for pk in request.POST.getlist("vm") if pk.isascii() and pk.isdigit() and len(pk) <= 10))
|
||||
|
|
@ -725,10 +745,10 @@ def bulk_tag(request):
|
|||
action, vms = request.POST.get("action"), _chosen_vms(request)
|
||||
if action not in ("tag_add", "tag_remove") or not vms:
|
||||
messages.error(request, _("Choose the VMs and write the tag"))
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
if len(vms) > BULK_MAX:
|
||||
messages.error(request, _("Choose at most %(count)s VMs at once") % {"count": BULK_MAX})
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
remove, changed = action == "tag_remove", 0
|
||||
with transaction.atomic():
|
||||
lock_ownership()
|
||||
|
|
@ -736,12 +756,12 @@ def bulk_tag(request):
|
|||
instances = Instance.objects.filter(pk__in=vms).select_related("compute")
|
||||
if not form.is_valid() or not form.cleaned_data["tags"] or not instances.exists():
|
||||
messages.error(request, " ".join(form.errors.get("tags", [])) or _("Choose the VMs and write the tag"))
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
(name,) = form.cleaned_data["tags"]
|
||||
tag = Tag.objects.filter(name=name).first() if remove else Tag.named([name])[0]
|
||||
if tag is None:
|
||||
messages.error(request, _("There is no tag %(tag)s") % {"tag": name})
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
# those it changes: with the tag to remove it from, without it to add it
|
||||
for instance in instances.filter(tags=tag) if remove else instances.exclude(tags=tag):
|
||||
with audit_vm(request, instance, f"{'untag' if remove else 'tag'} {name}"):
|
||||
|
|
@ -750,7 +770,7 @@ def bulk_tag(request):
|
|||
text = (ngettext("Tag %(tag)s removed from %(count)s VM", "Tag %(tag)s removed from %(count)s VMs", changed) if remove
|
||||
else ngettext("Tag %(tag)s added to %(count)s VM", "Tag %(tag)s added to %(count)s VMs", changed))
|
||||
messages.success(request, text % {"tag": name, "count": changed})
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
|
||||
|
||||
def _queue_each(request, vms, kind, raw, refused):
|
||||
|
|
@ -774,7 +794,7 @@ def _queue_each(request, vms, kind, raw, refused):
|
|||
except (jobs.SubmissionConflict, libvirtError) as err:
|
||||
messages.error(request, f"{name}: {error_text(request, err)}")
|
||||
if not queued:
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
messages.success(request, ngettext("%(count)s VM is queued; the Jobs page follows it.",
|
||||
"%(count)s VMs are queued; the Jobs page follows them.", queued) % {"count": queued})
|
||||
return redirect(reverse("operations:jobs") + f"?kind={kind}")
|
||||
|
|
@ -800,7 +820,7 @@ def bulk_power(request):
|
|||
refusal = _bulk_refused(request, vms, _("Choose the VMs you may power, and Start, Shut down or Force off"))
|
||||
if action not in POWER or refusal:
|
||||
messages.error(request, refusal or _("Choose the VMs you may power, and Start, Shut down or Force off"))
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
return _queue_each(request, vms, POWER[action], {}, _("%(vm)s: you may not power it now"))
|
||||
|
||||
|
||||
|
|
@ -812,18 +832,18 @@ def bulk_snapshot(request):
|
|||
refusal = _bulk_refused(request, vms, _("Choose the VMs and write the snapshot's name"))
|
||||
if not name or refusal:
|
||||
messages.error(request, refusal or _("Choose the VMs and write the snapshot's name"))
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
try:
|
||||
check_snapshot_name(name)
|
||||
except util.OperationError as err:
|
||||
messages.error(request, error_text(request, err))
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
# a template's page has no snapshot controls: none is taken here either
|
||||
templates = set(Instance.objects.filter(pk__in=vms, is_template=True).values_list("pk", flat=True))
|
||||
for pk in templates:
|
||||
messages.error(request, _("%(vm)s: a template's snapshots are not taken here") % {"vm": _visible_name(request, pk)})
|
||||
if templates and not set(vms) - templates:
|
||||
return redirect("instances:index")
|
||||
return _back_to_list(request)
|
||||
return _queue_each(request, [pk for pk in vms if pk not in templates], "snapshot.create",
|
||||
{"name": name, "external": True}, _("%(vm)s: you may not snapshot it"))
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -2888,11 +2888,6 @@ msgstr "Parolalar"
|
|||
msgid "Devices"
|
||||
msgstr "Aygıtlar"
|
||||
|
||||
#: computes/templates/computes/instances.html:13
|
||||
#: computes/templates/computes/instances.html:17
|
||||
msgid "New Instance"
|
||||
msgstr "Yeni sanal makine"
|
||||
|
||||
#: computes/templates/computes/instances.html:38
|
||||
#, python-format
|
||||
msgid "Problem occurred with host %(name)s: %(error)s"
|
||||
|
|
@ -2903,14 +2898,6 @@ msgstr "%(name)s sunucusuyla ilgili bir sorun oluştu: %(error)s"
|
|||
msgid "Warning"
|
||||
msgstr "Uyarı"
|
||||
|
||||
#: computes/templates/computes/instances.html:45
|
||||
msgid "Hypervisor doesn't have any Instances"
|
||||
msgstr "Hipervizör üzerinde hiç sanal makine yok"
|
||||
|
||||
#: computes/templates/computes/instances.html:56
|
||||
msgid "VCPU"
|
||||
msgstr "VCPU"
|
||||
|
||||
#: computes/templates/computes/list.html:20
|
||||
msgid "You don't have any computes"
|
||||
msgstr "Hiç sunucunuz yok"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -2746,11 +2746,6 @@ msgstr "机密"
|
|||
msgid "Devices"
|
||||
msgstr "设备"
|
||||
|
||||
#: computes/templates/computes/instances.html:13
|
||||
#: computes/templates/computes/instances.html:17
|
||||
msgid "New Instance"
|
||||
msgstr "新建虚拟机"
|
||||
|
||||
#: computes/templates/computes/instances.html:38
|
||||
#, python-format
|
||||
msgid "Problem occurred with host %(name)s: %(error)s"
|
||||
|
|
@ -2761,14 +2756,6 @@ msgstr "主机 %(name)s 出现问题:%(error)s"
|
|||
msgid "Warning"
|
||||
msgstr "警告"
|
||||
|
||||
#: computes/templates/computes/instances.html:45
|
||||
msgid "Hypervisor doesn't have any Instances"
|
||||
msgstr "虚拟机管理程序中没有任何虚拟机"
|
||||
|
||||
#: computes/templates/computes/instances.html:56
|
||||
msgid "VCPU"
|
||||
msgstr "VCPU"
|
||||
|
||||
#: computes/templates/computes/list.html:20
|
||||
msgid "You don't have any computes"
|
||||
msgstr "您还没有任何计算节点"
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle-fill" viewBox="0 0 16 16">
|
||||
|
||||
|
||||
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v3h-3a.5.5 0 0 0 0 1h3v3a.5.5 0 0 0 1 0v-3h3a.5.5 0 0 0 0-1h-3v-3z"/>
|
||||
|
||||
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 311 B |
|
|
@ -1,4 +0,0 @@
|
|||
{% load i18n %}
|
||||
<div class="float-end m-1">
|
||||
<input id="filter" class="form-control" type="text" placeholder="{% trans 'Search' %}">
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue