1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

add description to snapshots. Stress out live snapshot risks

This commit is contained in:
catborise 2022-09-19 15:44:57 +03:00
parent 2ff188da45
commit c9f1a7d7c5
3 changed files with 29 additions and 11 deletions

View file

@ -17,16 +17,20 @@
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="takesnapshot">
<p>{% 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.." %}</p>
{% if instance.status != 5 %}
<p>{% 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." %} </p>
<p class="text-danger">{% trans "Live snapshot could cause server timeout and instance might be paused!!!" %}</p>
{% else %}
<p>{% trans "Create an internal snapshot" %}</p>
{% endif %}
<form action="{% url 'instances:snapshot' instance.id %}" method="post" role="form" aria-label="Create snapshot form">
{% csrf_token %}
<div class="input-group mb-3">
<input type="text" class="form-control form-control-lg" name="name" placeholder="{% trans "Enter Snapshot Name" %}" maxlength="14">
<input type="text" class="form-control form-control-lg" name="name" placeholder="{% trans "Snapshot Name" %}" maxlength="14">
<span class="input-group-text">|</span>
<input type="text" class="form-control form-control-lg" name="description" placeholder="{% trans "Snapshot Description" %}" maxlength="45">
<input type="submit" class="btn btn-lg btn-success float-end" name="snapshot" value="{% trans "Take Snapshot" %}" onclick="showPleaseWaitDialog();">
</div>
</form>
<div class="clearfix"></div>
</div>
@ -36,15 +40,17 @@
<div class="table-responsive">
<table class="table">
<thead>
<th scope="col">{% trans "Name" %}</th>
<th scope="col">{% trans "Date" %}</th>
<th scope="col">{% trans "Name" %}</th>
<th scope="col">{% trans "Description" %}</th>
<th scope="colgroup" colspan="2">{% trans "Action" %}</th>
</thead>
<tbody>
{% for snap in instance.snapshots %}
<tr>
<td><strong>{{ snap.name }}</strong></td>
<td>{{ snap.date|date:"M d H:i:s" }}</td>
<td><strong>{{ snap.name }}</strong></td>
<td>{{ snap.description }}</td>
<td style="width:30px;">
<form action="{% url 'instances:revert_snapshot' instance.id %}" method="post" role="form" aria-label="Restore snapshot form">
{% csrf_token %}

View file

@ -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")

View file

@ -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 = """<domainsnapshot>
<name>%s</name>
<state>shutoff</state>
<description>%s</description>
<state>%s</state>
<creationTime>%d</creationTime>""" % (
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):