From c9f1a7d7c562c536558168acc0cb0f32c4ad90c8 Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 19 Sep 2022 15:44:57 +0300 Subject: [PATCH] add description to snapshots. Stress out live snapshot risks --- .../templates/instances/snapshots_tab.html | 20 ++++++++++++------- instances/views.py | 3 ++- vrtManager/instance.py | 17 +++++++++++++--- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/instances/templates/instances/snapshots_tab.html b/instances/templates/instances/snapshots_tab.html index 803fac3..d6eb88e 100644 --- a/instances/templates/instances/snapshots_tab.html +++ b/instances/templates/instances/snapshots_tab.html @@ -17,16 +17,20 @@
-

{% trans "This may take more than an hour, depending on how much content is on your instance and how large the disk is. It could cause web server timeout.." %}

+ {% if instance.status != 5 %} +

{% trans "With running machine, internal snapshots may take more than an hour, depending on how much memory has on your instance and how large the disk is." %}

+

{% trans "Live snapshot could cause server timeout and instance might be paused!!!" %}

+ {% else %} +

{% trans "Create an internal snapshot" %}

+ {% endif %}
{% csrf_token %} -
- + + | +
- -
@@ -36,15 +40,17 @@
- + + {% for snap in instance.snapshots %} - + +
{% trans "Name" %} {% trans "Date" %}{% trans "Name" %}{% trans "Description" %} {% trans "Action" %}
{{ snap.name }} {{ snap.date|date:"M d H:i:s" }}{{ snap.name }}{{ snap.description }}
{% csrf_token %} diff --git a/instances/views.py b/instances/views.py index c308b39..6bc9837 100644 --- a/instances/views.py +++ b/instances/views.py @@ -816,7 +816,8 @@ def snapshot(request, pk): if allow_admin_or_not_template and request.user.has_perm("instances.snapshot_instances"): name = request.POST.get("name", "") - instance.proxy.create_snapshot(name) + desc = request.POST.get("description", "") + instance.proxy.create_snapshot(name, desc) msg = _("Create snapshot: %(snap)s") % {"snap": name} addlogmsg(request.user.username, instance.compute.name, instance.name, msg) return redirect(request.META.get("HTTP_REFERER") + "#managesnapshot") diff --git a/vrtManager/instance.py b/vrtManager/instance.py index f392402..0931a98 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -1207,12 +1207,16 @@ class wvmInstance(wvmConnect): def _snapshotCreateXML(self, xml, flag): self.instance.snapshotCreateXML(xml, flag) - def create_snapshot(self, name): + def create_snapshot(self, name, desc=None): + state = 'shutoff' if self.get_status()==5 else 'running' xml = """ %s - shutoff + %s + %s %d""" % ( name, + desc, + state, time.time(), ) self.change_snapshot_xml() @@ -1235,8 +1239,15 @@ class wvmInstance(wvmConnect): snapshot_list = self.instance.snapshotListNames(0) for snapshot in snapshot_list: snap = self.instance.snapshotLookupByName(snapshot, 0) + snap_description = util.get_xml_path(snap.getXMLDesc(0), "/domainsnapshot/description") snap_time_create = util.get_xml_path(snap.getXMLDesc(0), "/domainsnapshot/creationTime") - snapshots.append({"date": datetime.fromtimestamp(int(snap_time_create)), "name": snapshot}) + snapshots.append( + { + "date": datetime.fromtimestamp(int(snap_time_create)), + "name": snapshot, + "description": snap_description, + } + ) return snapshots def snapshot_delete(self, snapshot):