Commit 895d9a95 by falusi94

Modify snapshot

dashboard, storage, vm: now snapshot handling does not have incorrect logic
parent b1575ee5
Pipeline #625 failed with stage
in 0 seconds
......@@ -1088,10 +1088,6 @@ textarea[name="new_members"] {
vertical-align: middle;
}
.disk-resize-btn {
margin-right: 5px;
}
#vm-migrate-node-list li {
cursor: pointer;
}
......
......@@ -7,12 +7,10 @@
<span class="operation-wrapper pull-right">
<div>
{% if op.create_snapshot %}
<a href="{{ op.create_snapshot.get_url }}?disk={{d.pk}}"
class="btn btn-xs btn-{{ op.create_snapshot.effect }} operation disk-create_snapshot-btn
{% if op.create_snapshot.disabled %}disabled{% endif %}">
<i class="fa fa-{{ op.create_snapshot.icon }} fa-fw-12"></i> {% trans "Snapshot" %}
</a>
{% if perms.view_snapshot and d.list_snapshots %}
<input type="button" class="btn btn-default btn-xs show-snapshot-btn"
data-toggle="collapse" data-target="#snapshots-{{ d.pk }}"
value="{% trans "Show snapshots" %}" />
{% endif %}
{% if d.is_resizable %}
{% if op.resize_disk %}
......@@ -26,10 +24,13 @@
<i class="fa fa-arrows-alt fa-fw-12"></i> {% trans "Request resize" %}
</a>
{% endif %}
{% else %}
<small class="btn-xs">
{% trans "Not resizable" %}
</small>
{% endif %}
{% if op.create_snapshot and not d.is_read_only and d.is_ready %}
<a href="{{ op.create_snapshot.get_url }}?disk={{d.pk}}"
class="btn btn-xs btn-{{ op.create_snapshot.effect }} operation disk-create_snapshot-btn
{% if op.create_snapshot.disabled %}disabled{% endif %}">
<i class="fa fa-{{ op.create_snapshot.icon }} fa-fw-12"></i> {% trans "Snapshot" %}
</a>
{% endif %}
{% if op.remove_disk %}
<a href="{{ op.remove_disk.get_url }}?disk={{d.pk}}"
......@@ -39,13 +40,6 @@
</a>
{% endif %}
</div>
<div class="pull-right">
{% if perms.view_snapshot and d.list_snapshots %}
<input type="button" class="btn btn-default btn-xs show-snapshot-btn"
data-toggle="collapse" data-target="#snapshots-{{ d.pk }}"
value="{% trans "Show snapshots" %}" />
{% endif %}
</div>
</span>
<br />
{% if request.user.is_superuser %}
......@@ -53,7 +47,7 @@
<small>{% trans "Bus" %}: {{ d.device_bus }}</small><br />
{% endif %}
<div style="clear: both;"></div>
{% if perms.storage.view_snapshot %}
{% if perms.storage.view_snapshot and d.list_snapshots %}
<div id="snapshots-{{ d.pk }}" class="collapse out snapshot-list">
<table class="table table-striped info-panel small snapshot-table">
{% for snap in d.list_snapshots %}
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-12-10 01:02
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('storage', '0003_auto_20160826_1619'),
]
operations = [
migrations.AddField(
model_name='disk',
name='did_have_snapshot',
field=models.BooleanField(default=False),
),
]
......@@ -141,6 +141,7 @@ class Disk(TimeStampedModel):
dev_num = CharField(default='a', max_length=1,
verbose_name=_("device number"))
destroyed = DateTimeField(blank=True, default=None, null=True)
did_have_snapshot = BooleanField(default=False)
is_ready = BooleanField(default=False)
......@@ -575,4 +576,9 @@ class Disk(TimeStampedModel):
@property
def is_resizable(self):
return self.type in ('qcow2-norm', 'raw-rw', 'qcow2-snap', )
return (self.type in ('qcow2-norm', 'raw-rw', 'qcow2-snap', ) and
not self.did_have_snapshot)
@property
def is_read_only(self):
return not self.type in ('qcow2-norm', 'raw-rw', )
......@@ -290,6 +290,7 @@ class RemoteSnapshotDiskOperation(InstanceOperation):
def _operation(self, disk, **kwargs):
if disk:
self.disk = disk
if not disk.is_ready:
raise disk.DiskIsNotReady(disk)
disk_desc = disk.get_disk_desc()
......@@ -316,6 +317,10 @@ class CreateSnapshotDiskOperation(RemoteSnapshotDiskOperation):
snap_name = 'new snapshot'
return [snap_name]
def on_commit(self, activity):
self.disk.did_have_snapshot = True
self.disk.save()
def get_activity_name(self, kwargs):
return create_readable(
ugettext_noop('Created snapshot %(snap_name)s'
......@@ -389,6 +394,9 @@ class ResizeDiskOperation(RemoteInstanceOperation):
def _operation(self, disk, size):
if not disk.is_resizable:
if disk.did_have_snapshot:
raise HumanReadableException.create(ugettext_noop(
'Disk already had snapshot, that is why not resizable.'))
raise HumanReadableException.create(ugettext_noop(
'Disk type "%(type)s" is not resizable.'), type=disk.type)
super(ResizeDiskOperation, self)._operation(disk=disk, size=size)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment