Commit 895d9a95 by falusi94

Modify snapshot

dashboard, storage, vm: now snapshot handling does not have incorrect logic
parent b1575ee5
...@@ -1088,10 +1088,6 @@ textarea[name="new_members"] { ...@@ -1088,10 +1088,6 @@ textarea[name="new_members"] {
vertical-align: middle; vertical-align: middle;
} }
.disk-resize-btn {
margin-right: 5px;
}
#vm-migrate-node-list li { #vm-migrate-node-list li {
cursor: pointer; cursor: pointer;
} }
......
...@@ -7,12 +7,10 @@ ...@@ -7,12 +7,10 @@
<span class="operation-wrapper pull-right"> <span class="operation-wrapper pull-right">
<div> <div>
{% if op.create_snapshot %} {% if perms.view_snapshot and d.list_snapshots %}
<a href="{{ op.create_snapshot.get_url }}?disk={{d.pk}}" <input type="button" class="btn btn-default btn-xs show-snapshot-btn"
class="btn btn-xs btn-{{ op.create_snapshot.effect }} operation disk-create_snapshot-btn data-toggle="collapse" data-target="#snapshots-{{ d.pk }}"
{% if op.create_snapshot.disabled %}disabled{% endif %}"> value="{% trans "Show snapshots" %}" />
<i class="fa fa-{{ op.create_snapshot.icon }} fa-fw-12"></i> {% trans "Snapshot" %}
</a>
{% endif %} {% endif %}
{% if d.is_resizable %} {% if d.is_resizable %}
{% if op.resize_disk %} {% if op.resize_disk %}
...@@ -26,10 +24,13 @@ ...@@ -26,10 +24,13 @@
<i class="fa fa-arrows-alt fa-fw-12"></i> {% trans "Request resize" %} <i class="fa fa-arrows-alt fa-fw-12"></i> {% trans "Request resize" %}
</a> </a>
{% endif %} {% endif %}
{% else %} {% endif %}
<small class="btn-xs"> {% if op.create_snapshot and not d.is_read_only and d.is_ready %}
{% trans "Not resizable" %} <a href="{{ op.create_snapshot.get_url }}?disk={{d.pk}}"
</small> 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 %} {% endif %}
{% if op.remove_disk %} {% if op.remove_disk %}
<a href="{{ op.remove_disk.get_url }}?disk={{d.pk}}" <a href="{{ op.remove_disk.get_url }}?disk={{d.pk}}"
...@@ -39,13 +40,6 @@ ...@@ -39,13 +40,6 @@
</a> </a>
{% endif %} {% endif %}
</div> </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> </span>
<br /> <br />
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
...@@ -53,7 +47,7 @@ ...@@ -53,7 +47,7 @@
<small>{% trans "Bus" %}: {{ d.device_bus }}</small><br /> <small>{% trans "Bus" %}: {{ d.device_bus }}</small><br />
{% endif %} {% endif %}
<div style="clear: both;"></div> <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"> <div id="snapshots-{{ d.pk }}" class="collapse out snapshot-list">
<table class="table table-striped info-panel small snapshot-table"> <table class="table table-striped info-panel small snapshot-table">
{% for snap in d.list_snapshots %} {% 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): ...@@ -141,6 +141,7 @@ class Disk(TimeStampedModel):
dev_num = CharField(default='a', max_length=1, dev_num = CharField(default='a', max_length=1,
verbose_name=_("device number")) verbose_name=_("device number"))
destroyed = DateTimeField(blank=True, default=None, null=True) destroyed = DateTimeField(blank=True, default=None, null=True)
did_have_snapshot = BooleanField(default=False)
is_ready = BooleanField(default=False) is_ready = BooleanField(default=False)
...@@ -575,4 +576,9 @@ class Disk(TimeStampedModel): ...@@ -575,4 +576,9 @@ class Disk(TimeStampedModel):
@property @property
def is_resizable(self): 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): ...@@ -290,6 +290,7 @@ class RemoteSnapshotDiskOperation(InstanceOperation):
def _operation(self, disk, **kwargs): def _operation(self, disk, **kwargs):
if disk: if disk:
self.disk = disk
if not disk.is_ready: if not disk.is_ready:
raise disk.DiskIsNotReady(disk) raise disk.DiskIsNotReady(disk)
disk_desc = disk.get_disk_desc() disk_desc = disk.get_disk_desc()
...@@ -316,6 +317,10 @@ class CreateSnapshotDiskOperation(RemoteSnapshotDiskOperation): ...@@ -316,6 +317,10 @@ class CreateSnapshotDiskOperation(RemoteSnapshotDiskOperation):
snap_name = 'new snapshot' snap_name = 'new snapshot'
return [snap_name] return [snap_name]
def on_commit(self, activity):
self.disk.did_have_snapshot = True
self.disk.save()
def get_activity_name(self, kwargs): def get_activity_name(self, kwargs):
return create_readable( return create_readable(
ugettext_noop('Created snapshot %(snap_name)s' ugettext_noop('Created snapshot %(snap_name)s'
...@@ -389,6 +394,9 @@ class ResizeDiskOperation(RemoteInstanceOperation): ...@@ -389,6 +394,9 @@ class ResizeDiskOperation(RemoteInstanceOperation):
def _operation(self, disk, size): def _operation(self, disk, size):
if not disk.is_resizable: 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( raise HumanReadableException.create(ugettext_noop(
'Disk type "%(type)s" is not resizable.'), type=disk.type) 'Disk type "%(type)s" is not resizable.'), type=disk.type)
super(ResizeDiskOperation, self)._operation(disk=disk, size=size) 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