mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(computes): the Bulk Migrate page keeps its list and button together
The page showed memory as MiB counts ("16768 MiB"), the destination and
the shut-off switch apart from the list, and a Migrate button below the
whole list that did not say how many VMs it would migrate. Now the list
is one card: "host -> destination" (a choice when there are several) and
the shut-off switch in its header, sizes as on the Computes and Balance
pages, and a footer that stays in sight below a long list with the
number at once and a "Migrate the chosen VMs" button that counts the
ticked VMs and is off while none is.
This commit is contained in:
parent
54487052e5
commit
cf288a54cf
8 changed files with 120 additions and 90 deletions
|
|
@ -2,6 +2,7 @@
|
|||
{% load i18n %}
|
||||
{% load static %}
|
||||
{% load operations %}
|
||||
{% load bootstrap_icons %}
|
||||
{% block title %}{% trans "Bulk Migrate" %} - {{ compute.name }}{% endblock %}
|
||||
{% block page_heading %}{{ compute.name }} - {% trans "Bulk Migrate" %}{% endblock page_heading %}
|
||||
|
||||
|
|
@ -15,65 +16,69 @@
|
|||
<div class="alert alert-warning shadow-sm">{% trans "There is no other host to migrate to." %}</div>
|
||||
{% else %}
|
||||
<p class="text-body-secondary">{% trans "Each chosen VM migrates in a job of its own: a running VM live, a shut-off one offline. A VM that fails stays on this host." %}</p>
|
||||
{% if targets|length > 1 %}
|
||||
{# another destination reloads the list: which VMs can go depends on it #}
|
||||
<form method="get" class="mb-3">
|
||||
<label class="form-label" for="bulk-migrate-target">{% trans "Destination" %}</label>
|
||||
<select name="target" id="bulk-migrate-target" class="form-select w-auto">
|
||||
{% for host in targets %}<option value="{{ host.pk }}"{% if host == target %} selected{% endif %}>{{ host.name }}</option>{% endfor %}
|
||||
</select>
|
||||
</form>
|
||||
{% else %}
|
||||
<p class="mb-3">{% trans "Destination" %}: <strong>{{ target.name }}</strong></p>
|
||||
{% endif %}
|
||||
<form method="get" id="bulk-migrate-choose"></form>
|
||||
{% if not parallel %}
|
||||
<div class="alert alert-warning shadow-sm">{% trans "The worker runs one job at a time: set Worker Concurrency to 2 or more on the Settings page." %}</div>
|
||||
{% elif not instances %}
|
||||
<div class="alert alert-info shadow-sm">{% trans "The host has no VMs." %}</div>
|
||||
{% else %}
|
||||
<form method="post">{% csrf_token %}{% submission_key %}
|
||||
<form method="post" class="card shadow-sm">{% csrf_token %}{% submission_key %}
|
||||
<input type="hidden" name="target" value="{{ target.pk }}">
|
||||
<div class="form-check mb-2">
|
||||
<input class="form-check-input" type="checkbox" id="bulk-migrate-shut-off">
|
||||
<label class="form-check-label" for="bulk-migrate-shut-off">{% trans "Also migrate the shut-off VMs" %}</label>
|
||||
<div class="card-header d-flex flex-wrap align-items-center gap-2">
|
||||
<span class="fw-semibold">{{ compute.name }}</span> {% bs_icon 'arrow-right' %}
|
||||
{% if targets|length > 1 %}
|
||||
<select name="target" id="bulk-migrate-target" form="bulk-migrate-choose" class="form-select form-select-sm w-auto" aria-label="{% trans "Destination" %}">
|
||||
{% for host in targets %}<option value="{{ host.pk }}"{% if host == target %} selected{% endif %}>{{ host.name }}</option>{% endfor %}
|
||||
</select>
|
||||
{% else %}
|
||||
<span class="fw-semibold">{{ target.name }}</span>
|
||||
{% endif %}
|
||||
<div class="form-check form-switch ms-auto mb-0">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="bulk-migrate-shut-off">
|
||||
<label class="form-check-label small" for="bulk-migrate-shut-off">{% trans "Also migrate the shut-off VMs" %}</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><input class="form-check-input" type="checkbox" id="bulk-migrate-all" aria-label="{% trans "Select all" %}" title="{% trans "Select all" %}"></th>
|
||||
<th scope="col" class="ps-3"><input class="form-check-input" type="checkbox" id="bulk-migrate-all" aria-label="{% trans "Select all" %}" title="{% trans "Select all" %}"></th>
|
||||
<th scope="col">{% trans "Name" %}</th>
|
||||
<th scope="col">{% trans "Status" %}</th>
|
||||
<th scope="col">{% trans "VCPU" %}</th>
|
||||
<th scope="col" class="text-end">{% trans "Memory" %}</th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col" class="text-end">vCPU</th>
|
||||
<th scope="col"><span class="visually-hidden">{% trans "Why" %}</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for instance in instances %}
|
||||
<tr>
|
||||
<td>
|
||||
<td class="ps-3">
|
||||
<input class="form-check-input" type="checkbox" name="instance" value="{{ instance.pk }}" id="bulk-migrate-{{ instance.pk }}"
|
||||
{% if instance.info.0 == 5 %} data-shut-off{% elif not instance.refusal %} checked{% endif %}{% if instance.refusal %} disabled{% endif %}>
|
||||
</td>
|
||||
<td><label for="bulk-migrate-{{ instance.pk }}">{{ instance.name }}</label></td>
|
||||
<td>{% include 'instance_state.html' %}</td>
|
||||
<td>{{ instance.info.3 }}</td>
|
||||
<td class="text-end">{% if instance.info %}{% widthratio instance.info.2 1024 1 %} MiB{% endif %}</td>
|
||||
<td class="small text-danger">{{ instance.refusal|default:"" }}</td>
|
||||
<td class="text-end text-nowrap">{% if instance.info %}{% widthratio instance.info.2 1 1024 as bytes %}{{ bytes|filesizeformat }}{% endif %}</td>
|
||||
<td class="text-end">{{ instance.info.3 }}</td>
|
||||
<td class="small text-body-secondary">{{ instance.refusal|default:"" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="bulk-migrate-parallel">{% trans "Migrations at once" %}</label>
|
||||
<select name="parallel" id="bulk-migrate-parallel" class="form-select w-auto">
|
||||
{# kept in sight below a long list #}
|
||||
<div class="card-footer sticky-bottom bg-body-tertiary d-flex flex-wrap align-items-center gap-2">
|
||||
<label class="small text-body-secondary" for="bulk-migrate-parallel">{% trans "Migrations at once" %}</label>
|
||||
<select name="parallel" id="bulk-migrate-parallel" class="form-select form-select-sm w-auto">
|
||||
{% for n in parallel %}<option value="{{ n }}"{% if forloop.last %} selected{% endif %}>{{ n }}</option>{% endfor %}
|
||||
</select>
|
||||
{% blocktrans with source=compute.name dest=target.name asvar question %}Migrate the chosen VMs from {{ source }} to {{ dest }}?{% endblocktrans %}
|
||||
<button type="submit" class="btn btn-primary ms-auto" id="bulk-migrate-submit" data-confirm="{{ question }}">
|
||||
{% trans "Migrate the chosen VMs" %} <span class="badge text-bg-light" id="bulk-migrate-count"></span>
|
||||
</button>
|
||||
</div>
|
||||
{% blocktrans with source=compute.name dest=target.name asvar question %}Migrate the chosen VMs from {{ source }} to {{ dest }}?{% endblocktrans %}
|
||||
<button type="submit" class="btn btn-primary" data-confirm="{{ question }}">{% trans "Migrate" %}</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class BulkMigratePageTests(TestCase):
|
|||
|
||||
def test_one_destination_is_named_and_several_are_a_choice(self):
|
||||
self.assertEqual(self.page().xpath("//select[@name='target']"), [])
|
||||
self.assertIn("ev-other", self.page().xpath("//strong/text()"))
|
||||
self.assertIn("ev-other", self.page().xpath("//div[contains(@class, 'card-header')]/span/text()"))
|
||||
Compute.objects.create(name="ev-third", hostname="198.51.100.32", login="", password="", type=4)
|
||||
self.assertEqual(self.page().xpath("//select[@name='target']/option/text()"), ["ev-other", "ev-third"])
|
||||
|
||||
|
|
|
|||
|
|
@ -20,23 +20,29 @@ const boxes = [
|
|||
];
|
||||
const handlers = {};
|
||||
const box = (id) => ({addEventListener: (name, fn) => { handlers[id] = fn; }});
|
||||
const ids = {"bulk-migrate-all": box("all"), "bulk-migrate-shut-off": box("shut-off"), "bulk-migrate-target": box("target")};
|
||||
const button = {disabled: false}, counter = {textContent: ""};
|
||||
const ids = {"bulk-migrate-all": box("all"), "bulk-migrate-shut-off": box("shut-off"), "bulk-migrate-target": box("target"),
|
||||
"bulk-migrate-submit": button, "bulk-migrate-count": counter};
|
||||
let submitted = 0;
|
||||
const selectors = {
|
||||
"input[name=instance]:not(:disabled)": (b) => !b.disabled,
|
||||
"input[data-shut-off]:not(:disabled)": (b) => b.shutOff && !b.disabled,
|
||||
"input[name=instance]:checked": (b) => b.checked,
|
||||
};
|
||||
vm.runInNewContext(SCRIPT, vm.createContext({document: {
|
||||
getElementById: (id) => ids[id],
|
||||
querySelectorAll: (selector) => boxes.filter(selectors[selector]),
|
||||
addEventListener: (name, fn) => { handlers.document = fn; },
|
||||
}}));
|
||||
const ticked = () => boxes.filter((b) => b.checked).map((b) => b.name);
|
||||
const seen = [];
|
||||
const seen = [], counts = [[counter.textContent, button.disabled]];
|
||||
for (const [id, checked] of STEPS) {
|
||||
handlers[id]({target: {checked, form: {submit: () => { submitted += 1; }}}});
|
||||
handlers.document(); // the change bubbles to the page
|
||||
seen.push(ticked());
|
||||
counts.push([counter.textContent, button.disabled]);
|
||||
}
|
||||
console.log(JSON.stringify({seen, submitted}));
|
||||
console.log(JSON.stringify({seen, submitted, counts}));
|
||||
"""
|
||||
|
||||
|
||||
|
|
@ -54,5 +60,9 @@ class BulkMigrateScriptTests(unittest.TestCase):
|
|||
def test_the_shut_off_box_ticks_only_the_shut_off_vms(self):
|
||||
self.assertEqual(self.run_script([["shut-off", True], ["shut-off", False]])["seen"], [["run", "off"], ["run"]])
|
||||
|
||||
def test_the_button_counts_the_ticked_vms_and_is_off_without_one(self):
|
||||
self.assertEqual(self.run_script([["all", False], ["all", True]])["counts"],
|
||||
[[1, False], [0, True], [2, False]])
|
||||
|
||||
def test_another_destination_reloads_the_list(self):
|
||||
self.assertEqual(self.run_script([["target", False]])["submitted"], 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue