mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(vmbackups): clearer backup pages; a deletion stays on its page
Deleting a backup took the user to the generic job page, which named neither the backup nor a way back. The deletion now stays on the page it was asked from, says which backup is being deleted, shows the row as being deleted and reads the page again until it is gone. The confirm dialog is 'Delete backup' and names the target and that it cannot be undone; the job's label names the VM and the backup's time. The lists keep a VM's and a target's name and a row's actions on one line, link a backup's job only when it is being made (Progress) or failed (Why?), and say 'While shut off' for an offline backup. The schedule form puts the full-backup setting on a row of its own and the schedule list shows it; the restore form starts on the VM's host.
This commit is contained in:
parent
43d25a2759
commit
fc87a3034e
18 changed files with 276 additions and 182 deletions
|
|
@ -45,6 +45,8 @@ class RestoreForm(forms.Form):
|
|||
super().__init__(*args, **kwargs)
|
||||
self.fields["compute"].queryset = Compute.objects.filter(backuptargetpool__target=backup.target).order_by("name")
|
||||
self.fields["name"].initial = f"{backup.vm_name}-restored"
|
||||
if backup.instance_id: # the VM's host, when it has the target's pool
|
||||
self.fields["compute"].initial = self.fields["compute"].queryset.filter(instance=backup.instance_id).first()
|
||||
if place: # a VM owner's: the VM's compute and pool, shown on the page
|
||||
del self.fields["compute"], self.fields["pool"]
|
||||
|
||||
|
|
@ -75,7 +77,7 @@ class PolicyForm(forms.ModelForm):
|
|||
model = BackupPolicy
|
||||
fields = ["name", "target", "compute", "instances", "time", "keep", "full_every", "frozen", "enabled"]
|
||||
labels = {"name": _("Name"), "target": _("Backup target"), "compute": _("Every VM of a compute"),
|
||||
"instances": _("Or these VMs"), "time": _("Daily at"), "keep": _("Backups to keep of each VM"),
|
||||
"instances": _("Or these VMs"), "time": _("Daily at"), "keep": _("Backups kept per VM"),
|
||||
"full_every": _("A full backup every N backups"),
|
||||
"frozen": _("Require frozen file systems"), "enabled": _("Enabled")}
|
||||
widgets = {"time": forms.TimeInput(attrs={"type": "time"}, format="%H:%M"),
|
||||
|
|
|
|||
|
|
@ -624,7 +624,7 @@ class DeleteBackup(Kind):
|
|||
return Plan(
|
||||
claims={claims.backup_key(backup.uuid): Claim.EXCLUSIVE, **_target_claims(backup.target)},
|
||||
resource=claims.backup_key(backup.uuid),
|
||||
label=f"{backup.target.name}/{backup.vm_name}",
|
||||
label=f"{backup.vm_name} {timezone.localtime(backup.created_at):%Y-%m-%d %H:%M}",
|
||||
intent={"compute": backup.compute_name, "vm": backup.vm_name, "uuid": backup.vm_uuid,
|
||||
"time": timezone.localtime(backup.created_at).strftime("%Y-%m-%d %H:%M")},
|
||||
)
|
||||
|
|
|
|||
17
vmbackups/static/vmbackups/pending.js
Normal file
17
vmbackups/static/vmbackups/pending.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// A backup being made or deleted: the page reads it again until it is done,
|
||||
// while the backups are in view (the VM page's Backups tab, the Backups page)
|
||||
// and nothing is open on them (a menu, a dialog).
|
||||
(function () {
|
||||
if (!document.querySelector("[data-backup-pending]")) return;
|
||||
var check = function () {
|
||||
var pane = document.getElementById("backups");
|
||||
var hidden = pane && pane.classList.contains("tab-pane") && !pane.classList.contains("active");
|
||||
var busy = document.querySelector(".dropdown-menu.show, .modal.show");
|
||||
if (hidden || busy || document.hidden) {
|
||||
setTimeout(check, 4000);
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
};
|
||||
setTimeout(check, 4000);
|
||||
})();
|
||||
|
|
@ -1 +1 @@
|
|||
{% load i18n %}{% if backup.consistency == "offline" %}{% trans "Shut off" %}{% elif backup.consistency == "frozen" %}{% trans "Frozen" %}{% elif backup.consistency == "crash" %}{% trans "Crash-consistent" %}{% else %}–{% endif %}{% if backup.parent_id %} <span class="badge text-bg-light border" title="{% trans 'Copies only what changed since the backup it builds on' %}">{% trans "Incremental" %}</span>{% endif %}
|
||||
{% load i18n %}{% if backup.consistency == "offline" %}{% trans "While shut off" %}{% elif backup.consistency == "frozen" %}{% trans "Frozen" %}{% elif backup.consistency == "crash" %}{% trans "Crash-consistent" %}{% else %}–{% endif %}{% if backup.parent_id %} <span class="badge text-bg-light border" title="{% trans 'Copies only what changed since the backup it builds on' %}">{% trans "Incremental" %}</span>{% endif %}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% load i18n %}{% load operations %}{% load bootstrap_icons %}{% if backup.state == "ready" %}<div class="btn-group me-1">
|
||||
{% load i18n %}{% load operations %}{% load bootstrap_icons %}{% if backup.state != "deleting" and backup.uuid|stringformat:"s" not in pending_deletes %}<div class="d-inline-flex gap-1 justify-content-end">{% if backup.state == "ready" %}<div class="btn-group">
|
||||
{# fixed: the menu would be cut off by the table's scrolling box #}
|
||||
<button class="btn btn-sm btn-outline-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"
|
||||
data-bs-popper-config='{"strategy": "fixed"}'>{% trans "Restore" %}</button>
|
||||
|
|
@ -8,5 +8,5 @@
|
|||
{% if user.is_superuser %}<li><a class="dropdown-item" href="{% url 'vmbackups:restore_disk' backup.uuid %}">{% trans "One disk" %}</a></li>{% endif %}
|
||||
</ul>
|
||||
</div>{% endif %}{% if backup.state != "creating" %}{% if user.is_superuser or backup.taken_by_id == user.id and not backup.policy_id %}<form method="post" action="{% url 'vmbackups:delete' backup.uuid %}" class="d-inline">{% csrf_token %}{% submission_key %}
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger" aria-label="{% trans "Delete" %}" title="{% trans "Delete" %}"
|
||||
data-confirm="{% blocktrans with time=backup.created_at|date:"Y-m-d H:i" vm=backup.vm_name %}Delete the backup of {{ vm }} taken {{ time }}? Its files are removed from the target.{% endblocktrans %}">{% bs_icon 'trash' %}</button></form>{% endif %}{% endif %}
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger" aria-label="{% trans "Delete backup" %}" title="{% trans "Delete backup" %}"
|
||||
data-confirm="{% blocktrans with time=backup.created_at|date:"Y-m-d H:i" vm=backup.vm_name target=backup.target.name %}Delete the backup of {{ vm }} taken {{ time }}? Its files are removed from {{ target }}; this cannot be undone.{% endblocktrans %}">{% bs_icon 'trash' %}</button></form>{% endif %}{% endif %}</div>{% endif %}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{% extends "base.html" %}
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
{% load bootstrap_icons %}
|
||||
{% load operations %}
|
||||
|
||||
|
|
@ -50,17 +51,17 @@
|
|||
{% for backup in rows %}
|
||||
<tr>
|
||||
<td class="text-nowrap">{{ backup.created_at|date:"Y-m-d H:i" }}</td>
|
||||
<td>
|
||||
<td class="text-nowrap">
|
||||
{% if backup.instance %}<a href="{% url 'instances:instance' backup.instance.id %}">{{ backup.vm_name }}</a>
|
||||
{% else %}{{ backup.vm_name }} <span class="badge text-bg-secondary">{% trans "removed" %}</span>{% endif %}
|
||||
<div class="small text-body-secondary">{{ backup.compute_name }}</div>
|
||||
</td>
|
||||
<td>{{ backup.target.name }}</td>
|
||||
<td class="text-nowrap">{{ backup.target.name }}</td>
|
||||
<td>{% include "vmbackups/consistency.html" %}</td>
|
||||
<td>{% if backup.policy %}<a href="{% url 'vmbackups:policy' backup.policy_id %}">{{ backup.policy.name }}</a>{% else %}<span class="text-body-secondary">{% trans "By hand" %}</span>{% endif %}</td>
|
||||
<td class="text-end text-nowrap">{% if backup.size %}{{ backup.size|filesizeformat }}{% else %}–{% endif %}</td>
|
||||
<td>{% include "vmbackups/state.html" %}</td>
|
||||
<td class="text-end">{% include "vmbackups/delete_form.html" %}</td>
|
||||
<td class="text-end text-nowrap">{% include "vmbackups/delete_form.html" %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
@ -72,3 +73,5 @@
|
|||
<div class="alert alert-info">{% trans "No backup yet. Back a VM up from its Backups tab." %}</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}<script src="{% static 'vmbackups/pending.js' %}"></script>{% endblock %}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
<table class="table table-hover align-middle">
|
||||
<thead>
|
||||
<tr><th>{% trans "Name" %}</th><th>{% trans "VMs" %}</th><th>{% trans "Target" %}</th><th>{% trans "Daily at" %}</th>
|
||||
<th class="text-end">{% trans "Backups kept" %}</th><th>{% trans "State" %}</th></tr>
|
||||
<th class="text-end">{% trans "Backups kept" %}</th><th>{% trans "Full backup" %}</th><th>{% trans "State" %}</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for policy in policies %}
|
||||
|
|
@ -24,6 +24,7 @@
|
|||
<td>{{ policy.target.name }}</td>
|
||||
<td>{{ policy.time|time:"H:i" }}</td>
|
||||
<td class="text-end">{{ policy.keep }}</td>
|
||||
<td>{% if policy.full_every == 1 %}{% trans "Every backup" %}{% else %}{% blocktrans with n=policy.full_every %}Every {{ n }} backups{% endblocktrans %}{% endif %}</td>
|
||||
<td>{% if policy.enabled %}<span class="badge text-bg-success">{% trans "Enabled" %}</span>{% else %}<span class="badge text-bg-secondary">{% trans "Disabled" %}</span>{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@
|
|||
<div class="col-md-7">{% bootstrap_field form.instances %}</div>
|
||||
</div>
|
||||
<div class="row g-2">
|
||||
<div class="col-md-4">{% blocktrans asvar zone_help %}Time zone: {{ time_zone }}{% endblocktrans %}{% bootstrap_field form.time help_text=zone_help %}</div>
|
||||
<div class="col-md-4">{% bootstrap_field form.keep %}</div>
|
||||
<div class="col-md-4">{% bootstrap_field form.full_every %}</div>
|
||||
<div class="col-sm-6">{% blocktrans asvar zone_help %}Time zone: {{ time_zone }}{% endblocktrans %}{% bootstrap_field form.time help_text=zone_help %}</div>
|
||||
<div class="col-sm-6">{% bootstrap_field form.keep %}</div>
|
||||
</div>
|
||||
<div class="row g-2">
|
||||
<div class="col-sm-6">{% bootstrap_field form.full_every %}</div>
|
||||
</div>
|
||||
{% bootstrap_field form.frozen %}
|
||||
{% bootstrap_field form.enabled %}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{% load i18n %}{% if backup.state == "ready" %}<span class="badge text-bg-success">{% trans "Ready" %}</span>{% elif backup.state == "creating" %}<span class="badge text-bg-info">{% trans "Creating" %}</span>{% elif backup.state == "deleting" %}<span class="badge text-bg-warning">{% trans "Deleting" %}</span>{% elif backup.state == "missing" %}<span class="badge text-bg-danger" title="{% trans "Files of the backup are missing from the target" %}">{% trans "Missing" %}</span>{% else %}<span class="badge text-bg-danger">{% trans "Failed" %}</span>{% endif %}{% if backup.operation_id %} <a class="small" href="{% url 'operations:job' backup.operation_id %}">{% trans "Job" %}</a>{% endif %}
|
||||
{% load i18n %}{% if backup.state == "deleting" or backup.uuid|stringformat:"s" in pending_deletes %}<span class="badge text-bg-warning" data-backup-pending>{% trans "Deleting" %}</span>{% elif backup.state == "ready" %}<span class="badge text-bg-success">{% trans "Ready" %}</span>{% elif backup.state == "creating" %}<span class="badge text-bg-info" data-backup-pending>{% trans "Creating" %}</span>{% if backup.operation_id %} <a class="small" href="{% url 'operations:job' backup.operation_id %}">{% trans "Progress" %}</a>{% endif %}{% elif backup.state == "missing" %}<span class="badge text-bg-danger" title="{% trans "Files of the backup are missing from the target" %}">{% trans "Missing" %}</span>{% else %}<span class="badge text-bg-danger">{% trans "Failed" %}</span>{% if backup.operation_id %} <a class="small" href="{% url 'operations:job' backup.operation_id %}">{% trans "Why?" %}</a>{% endif %}{% endif %}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{% load i18n %}
|
||||
{% load operations %}
|
||||
{% load bootstrap_icons %}
|
||||
{% load static %}
|
||||
<div class="tab-pane" id="backups" role="tabpanel">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
|
@ -47,8 +48,8 @@
|
|||
<td>{{ backup.target.name }}</td>
|
||||
<td>{% include "vmbackups/consistency.html" %}</td>
|
||||
<td class="text-end text-nowrap">{% if backup.size %}{{ backup.size|filesizeformat }}{% else %}–{% endif %}</td>
|
||||
<td>{% include "vmbackups/state.html" %}</td>
|
||||
<td class="text-end">{% include "vmbackups/delete_form.html" %}</td>
|
||||
<td>{% include "vmbackups/state.html" with pending_deletes=backups.pending_deletes %}</td>
|
||||
<td class="text-end text-nowrap">{% include "vmbackups/delete_form.html" with pending_deletes=backups.pending_deletes %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
@ -60,3 +61,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="{% static 'vmbackups/pending.js' %}"></script>
|
||||
|
|
|
|||
|
|
@ -133,11 +133,16 @@ class DeleteBackupTests(TransactionTestCase):
|
|||
def test_the_page_deletes_and_goes_back(self):
|
||||
self.client.force_login(self.admin)
|
||||
url = reverse("vmbackups:delete", args=[self.backup.uuid])
|
||||
response = self.client.post(url, {"submission_key": "key-page-del1"}, HTTP_REFERER="http://testserver/backups/")
|
||||
op = Operation.objects.get()
|
||||
self.assertEqual(op.kind, "backup.delete")
|
||||
# the job's own page: neither the Backups page nor the VM page shows a backup's job
|
||||
self.assertRedirects(response, reverse("operations:job", args=[op.pk]), fetch_redirect_response=False)
|
||||
response = self.client.post(url, {"submission_key": "key-page-del1"}, HTTP_REFERER="http://testserver/backups/",
|
||||
follow=True)
|
||||
self.assertEqual(Operation.objects.get().kind, "backup.delete")
|
||||
# the page it was asked from, saying which backup goes, and the row as being deleted
|
||||
self.assertEqual(response.redirect_chain[0][0], "http://testserver/backups/")
|
||||
self.assertContains(response, f"The backup of vm1 taken {self.backup.created_at:%Y-%m-%d} ")
|
||||
page = lxml_html.fromstring(response.content)
|
||||
row = page.xpath("//table[@id='backups']/tbody/tr")[0]
|
||||
self.assertTrue(row.xpath(".//*[@data-backup-pending]"))
|
||||
self.assertFalse(row.xpath(".//button[@data-confirm]")) # nothing more to ask of it
|
||||
|
||||
|
||||
class IndexTests(TransactionTestCase):
|
||||
|
|
|
|||
|
|
@ -283,6 +283,14 @@ class RestoreTests(TransactionTestCase):
|
|||
with self.assertRaisesMessage(OperationError, "builds on a backup that is gone"):
|
||||
self.run_job(self.submit())
|
||||
|
||||
def test_the_restore_form_starts_on_the_vms_host(self):
|
||||
from vmbackups.forms import RestoreForm
|
||||
|
||||
vm = Instance.objects.create(compute=self.compute, name="vm1", uuid=self.backup.vm_uuid)
|
||||
Backup.objects.filter(pk=self.backup.pk).update(instance=vm)
|
||||
self.backup.refresh_from_db()
|
||||
self.assertEqual(RestoreForm(backup=self.backup).fields["compute"].initial, self.compute)
|
||||
|
||||
def test_the_nvram_file_is_qemus(self):
|
||||
self.run_job(self.submit())
|
||||
self.assertEqual(self.conn.upload_volume.call_args.kwargs, {"owner": _owner(), "mode": "0600"})
|
||||
|
|
|
|||
|
|
@ -41,6 +41,15 @@ def refuse_target_pool(compute, pool):
|
|||
)
|
||||
|
||||
|
||||
def pending_deletes():
|
||||
"""The UUIDs of the backups a deletion job was asked for and has not
|
||||
finished: shown as being deleted before the job marks them."""
|
||||
from operations.models import Operation
|
||||
|
||||
ops = Operation.objects.filter(kind="backup.delete", state__in=Operation.ACTIVE).values_list("params", flat=True)
|
||||
return {params["backup"] for params in ops}
|
||||
|
||||
|
||||
def vm_tab(instance, user):
|
||||
"""The VM page's Backups tab: the VM's backups, the targets of its host,
|
||||
and why it cannot be backed up, if it cannot. A VM owner sees only
|
||||
|
|
@ -63,4 +72,5 @@ def vm_tab(instance, user):
|
|||
problem = str(err)
|
||||
schedules = [] if owner else BackupPolicy.objects.filter(
|
||||
Q(instances=instance) | Q(compute=instance.compute_id)).distinct().order_by("name")
|
||||
return {"rows": rows, "targets": targets, "problem": problem, "schedules": schedules}
|
||||
return {"rows": rows, "targets": targets, "problem": problem, "schedules": schedules,
|
||||
"pending_deletes": pending_deletes()}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from django.conf import settings
|
|||
from django.db.models import Count
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.http import require_POST
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
|
@ -25,7 +26,7 @@ from vrtManager.util import OperationError
|
|||
from .forms import PolicyForm, RestoreDiskForm, RestoreForm, TargetForm, TargetPoolForm
|
||||
from .jobs import _over_plan, _proxy, _vm_pool
|
||||
from .models import Backup, BackupPolicy, BackupTarget
|
||||
from .utils import inside_vm_pool
|
||||
from .utils import inside_vm_pool, pending_deletes
|
||||
|
||||
|
||||
def _may_restore(user, backup):
|
||||
|
|
@ -177,24 +178,25 @@ def index(request):
|
|||
rows = rows.filter(state=state)
|
||||
return render(request, "vmbackups/index.html", {
|
||||
"rows": rows, "targets": BackupTarget.objects.order_by("name"),
|
||||
"vm": vm, "target": target, "state": state,
|
||||
"vm": vm, "target": target, "state": state, "pending_deletes": pending_deletes(),
|
||||
})
|
||||
|
||||
|
||||
@require_POST
|
||||
@login_required
|
||||
def delete(request, uuid):
|
||||
"""Delete a backup: a backup.delete job. The page it was asked from shows
|
||||
the backup as being deleted until it is gone."""
|
||||
backup = get_object_or_404(Backup, uuid=uuid)
|
||||
try:
|
||||
op = jobs.submit("backup.delete", request.user, {"backup": str(backup.uuid)},
|
||||
request.POST.get("submission_key", ""))
|
||||
jobs.submit("backup.delete", request.user, {"backup": str(backup.uuid)}, request.POST.get("submission_key", ""))
|
||||
except claims.Busy as busy:
|
||||
messages.error(request, busy_message(busy, request.user))
|
||||
except (jobs.SubmissionConflict, libvirtError) as err:
|
||||
messages.error(request, error_text(request, err))
|
||||
else:
|
||||
# the job's page follows it: the pages listing backups show no backup's job
|
||||
return redirect("operations:job", op.pk)
|
||||
messages.success(request, _("The backup of %(vm)s taken %(time)s is being deleted.") % {
|
||||
"vm": backup.vm_name, "time": timezone.localtime(backup.created_at).strftime("%Y-%m-%d %H:%M")})
|
||||
return redirect(same_origin_referer(request, reverse("vmbackups:index")))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue