Commit f211db99 by Bach Dániel

Merge branch 'datastore-bugs' into 'master'

Fix datastore bugs 

Closes #387

See merge request !304
parents a1392d3a 47d1eca5
......@@ -1607,11 +1607,16 @@ class DataStoreForm(ModelForm):
class DiskForm(ModelForm):
created = forms.DateTimeField()
modified = forms.DateTimeField()
def __init__(self, *args, **kwargs):
super(DiskForm, self).__init__(*args, **kwargs)
for k, v in self.fields.iteritems():
v.widget.attrs['readonly'] = True
self.fields['created'].initial = self.instance.created
self.fields['modified'].initial = self.instance.modified
class Meta:
model = Disk
......@@ -1271,3 +1271,9 @@ textarea[name="new_members"] {
background: #f9f9f9;
margin-top: 20px;
}
#disk-list-table {
td:last-child {
text-align: center;
}
}
......@@ -350,4 +350,5 @@ class DiskListTable(Table):
fields = ("pk", "appliance", "filename", "size", "is_ready")
prefix = "disk-"
order_by = ("-pk", )
per_page = 65536
per_page = 15
empty_text = _("No disk found.")
......@@ -52,7 +52,9 @@
<small>{% trans "image files without disk object in the database" %}</small>
</h3>
{% for o in orphan_disks %}
<p>
{{ o }}
</p>
{% empty %}
{% trans "None" %}
{% endfor %}
......@@ -68,6 +70,33 @@
<h3 class="no-margin"><i class="fa fa-file"></i> {% trans "Disks" %}</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-9">
<ul class="nav nav-pills" style="margin: 5px 0 20px 0;">
<li class="disabled"><a href="#">{% trans "Filter by type" %}</a></li>
<li {% if not request.GET.filter %} class="active"{% endif %}>
<a href="{{ request.path }}?s={{ request.GET.s }}">{% trans "ALL" %}</a>
</li>
{% for f in filter_names %}
<li{% if request.GET.filter == f.0 %} class="active"{% endif %}>
<a href="?filter={{ f.0 }}&s={{ request.GET.s }}">{{ f.1|capfirst }}</a>
</li>
{% endfor %}
</ul>
</div>
<div class="col-md-3">
<form action="" method="GET" id="network-host-list-form">
<div class="input-group">
<input type="text" name="s" class="form-control"
value="{{ request.GET.s }}" placeholder="{% trans "Search..." %}"/>
<span class="input-group-btn">
<button class="btn btn-primary"><i class="fa fa-search"></i></button>
</span>
<input type="hidden" name="filter" value="{{ request.GET.filter }}"/>
</div>
</form>
</div>
</div><!-- .row -->
<div class="table-responsive">
{% render_table disk_table %}
</div>
......
......@@ -16,13 +16,16 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals, absolute_import
from django.views.generic import UpdateView
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.utils.translation import ugettext_lazy as _
from django.views.generic import UpdateView
from sizefield.utils import filesizeformat
from braces.views import SuperuserRequiredMixin
from sizefield.utils import filesizeformat
from common.models import WorkerNotFound
from storage.models import DataStore, Disk
from ..tables import DiskListTable
from ..forms import DataStoreForm, DiskForm
......@@ -40,15 +43,53 @@ class StorageDetail(SuperuserRequiredMixin, UpdateView):
context = super(StorageDetail, self).get_context_data(**kwargs)
ds = self.get_object()
try:
context['stats'] = self._get_stats()
context['missing_disks'] = ds.get_missing_disks()
context['orphan_disks'] = ds.get_orphan_disks()
qs = Disk.objects.filter(datastore=ds, destroyed=None)
except WorkerNotFound:
messages.error(self.request, _("The DataStore is offline."))
context['disk_table'] = DiskListTable(
qs, request=self.request,
template="django_tables2/table_no_page.html")
self.get_table_data(), request=self.request,
template="django_tables2/with_pagination.html")
context['filter_names'] = (
('vm', _("virtual machine")),
('template', _("template")),
('none', _("none")),
)
return context
def get_table_data(self):
ds = self.get_object()
qs = Disk.objects.filter(datastore=ds, destroyed=None)
filter_name = self.request.GET.get("filter")
search = self.request.GET.get("s")
filter_queries = {
'vm': {
'instance_set__isnull': False,
},
'template': {
'template_set__isnull': False,
},
'none': {
'template_set__isnull': True,
'instance_set__isnull': True,
}
}
if filter_name:
qs = qs.filter(**filter_queries.get(filter_name, {}))
if search:
search = search.strip()
qs = qs.filter(Q(name__icontains=search) |
Q(filename__icontains=search))
return qs
def _get_stats(self):
stats = self.object.get_statistics()
free_space = int(stats['free_space'])
......@@ -72,3 +113,6 @@ class DiskDetail(SuperuserRequiredMixin, UpdateView):
model = Disk
form_class = DiskForm
template_name = "dashboard/storage/disk.html"
def form_valid(self, form):
pass
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