Commit f601f261 by Czémán Arnold

dashboard: rework create storage and storage detail pages; clean DataStoreForm…

dashboard: rework create storage and storage detail pages; clean DataStoreForm and CephDataStoreForm; and fix small thins
parent 65c96698
......@@ -1617,9 +1617,6 @@ class DataStoreForm(ModelForm):
'name',
'path',
'hostname',
),
FormActions(
Submit('submit', _('Save')),
)
)
return helper
......@@ -1631,22 +1628,8 @@ class DataStoreForm(ModelForm):
class CephDataStoreForm(DataStoreForm):
hostnames = forms.ModelMultipleChoiceField(
queryset=None, required=False, label=_("Hostnames"))
other_hostnames = forms.MultipleChoiceField(
required=False, label=_("Other hostnames"))
type = forms.CharField(widget=forms.HiddenInput())
def __init__(self, *args, **kwargs):
super(DataStoreForm, self).__init__(*args, **kwargs)
hostnames = self.fields["hosts"].queryset.all()
other_hostnames = set(DataStoreHost.objects.all()) - set(hostnames)
self.fields['hostnames'].queryset = hostnames
self.fields['other_hostnames'].initial = other_hostnames
@property
def helper(self):
helper = FormHelper()
......@@ -1655,9 +1638,6 @@ class CephDataStoreForm(DataStoreForm):
'',
'ceph_user',
'secret_uuid',
),
FormActions(
Submit('submit', _('Save')),
)
)
return helper
......@@ -1666,6 +1646,8 @@ class CephDataStoreForm(DataStoreForm):
model = DataStore
fields = ("type", "name", "path", "hostname",
"ceph_user", "secret_uuid", "hosts")
widgets = {"hosts": FilteredSelectMultiple(_("Hostnames"),
is_stacked=True)}
class DataStoreHostForm(ModelForm):
......
......@@ -104,7 +104,7 @@ $(function () {
$.post(form.attr("action"), form.serialize(), function(data){
if(data.status===true){
$('#id_other_hostnames')
$('#id_hosts_from')
.append($('<option>')
.text(data.response.text)
.attr('value', data.response.val));
......@@ -129,10 +129,6 @@ $(function () {
return false;
});
$('#storage-create-form').submit(function(){
$('#id_hostnames option').prop('selected', true);
});
$('[href=#index-graph-view]').click(function (e) {
var box = $(this).data('index-box');
$("#" + box + "-list-view").hide();
......
......@@ -22,7 +22,7 @@
{{ form.port|as_crispy_field }}
</div>
</div>
<input type="submit" value="{% trans "Create new host" %}" class="btn btn-success" id="data_store_host_host-create-btn">
<input type="submit" value="{% trans "Create new hostname" %}" class="btn btn-success" id="data_store_host_host-create-btn">
</form>
......
{% load i18n %}
{% load crispy_forms_tags %}
<form id="storage-create-form" action="" method="POST">
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% csrf_token %}
{{ form.type }}
<fieldset>
<legend>{% trans "General settings" %}</legend>
{{ form.name|as_crispy_field }}
{{ form.path|as_crispy_field }}
{{ form.hostname|as_crispy_field }}
</fieldset>
{% if form.type.value == "ceph_block" %}
<fieldset>
<legend>{% trans "Ceph block storage authentication settings" %}</legend>
{{ form.ceph_user|as_crispy_field }}
{{ form.secret_uuid|as_crispy_field }}
</fieldset>
<fieldset>
<legend>{% trans "Select or add new Ceph monitor hostname(s)" %}</legend>
{% include 'dashboard/storage/hostname_selector.html' %}
</fieldset>
{% endif %}
<fieldset>
<input type="submit" value="{% trans "Create new data store" %}" class="btn btn-success">
</fieldset>
{% include "dashboard/storage/form_chunk.html" %}
<fieldset>
<input type="submit" value="{% trans "Create new data store" %}" class="btn btn-success">
</fieldset>
</form>
<style>
fieldset {
margin-top: 40px;
}
fieldset legend {
font-weight: bold;
}
</style>
......@@ -2,24 +2,28 @@
{% load staticfiles %}
{% load i18n %}
{% load render_table from django_tables2 %}
{% load crispy_forms_tags %}
{% block title-page %}{% trans "Storage" %}{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-5">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="no-margin"><i class="fa fa-database"></i> {% trans "Datastore" %}</h3>
</div>
<div class="panel-body">
{% crispy form %}
<form id="storage-create-form" action="" method="POST">
{% include "dashboard/storage/form_chunk.html" %}
<fieldset>
<input type="submit" value="{% trans "Save" %}" class="btn btn-primary">
</fieldset>
</form>
</div><!-- .panel-body -->
</div>
</div>
<div class="col-md-7">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="no-margin"><i class="fa fa-bar-chart"></i> {% trans "Statistics" %}</h3>
......@@ -104,5 +108,4 @@
</div>
</div>
</div>
{% endblock %}
{% endblock %}
{% load i18n %}
{% load crispy_forms_tags %}
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% csrf_token %}
{{ form.type }}
<fieldset>
<legend>{% trans "General settings" %}</legend>
{{ form.name|as_crispy_field }}
{{ form.path|as_crispy_field }}
{{ form.hostname|as_crispy_field }}
</fieldset>
{% if form.type.value == "ceph_block" %}
<fieldset>
<legend>{% trans "Ceph block storage authentication settings" %}</legend>
{{ form.ceph_user|as_crispy_field }}
{{ form.secret_uuid|as_crispy_field }}
</fieldset>
<fieldset>
<legend>{% trans "Select or add new Ceph monitor hostname(s)" %}</legend>
<a href="{% url "dashboard.views.storage-host-create" %}" class="btn btn-success data_store_host-create">
<i class="fa fa-plus"></i>
{% trans "new hostname" %}
</a>
<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>
{{ form.media }}
<div id="group-detail-permissions">
{{ form.hosts }}
</div>
<link rel="stylesheet" type="text/css" href="/static/admin/css/widgets.css" />
</fieldset>
{% endif %}
<style>
fieldset{
margin-top: 10px;
margin-bottom: 10px;
}
fieldset legend {
font-weight: bold;
}
#group-detail-permissions {
margin-top: 20px;
}
</style>
<div class="row">
<div class="col-xs-5">
<div class="controls">
<select multiple="multiple" class="selectmultiple form-control" id="id_hostnames" name="hostnames">
{% for hostname in hostnames %}
<option value="{{ hostname.id }}">{{ hostname }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-xs-1">
<div class="row text-center">
<div class="btn" onclick="move('#id_hostnames', '#id_other_hostnames')">
<i class="fa fa-arrow-left fa-2x"></i>
</div>
</div>
<div class="row text-center">
<div class="btn" onclick="move('#id_other_hostnames', '#id_hostnames')">
<i class="fa fa-arrow-right fa-2x"></i>
</div>
</div>
</div>
<div class="col-xs-5">
<div class="controls">
<select multiple="multiple" class="selectmultiple form-control" id="id_other_hostnames" name="other_hostnames">
{% for hostname in other_hostnames %}
<option value="{{ hostname.id }}">{{ hostname }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-xs-1 text-left">
<a href="{% url "dashboard.views.storage-host-create" %}" class="btn btn-success btn-xs data_store_host-create">
<i class="fa fa-plus fa-2x"></i>
</a>
</div>
</div>
<script type="text/javascript">
function move(to, from){
var selected_items = $(from).find(":selected");
$(to).append(selected_items);
}
</script>
......@@ -90,10 +90,6 @@ class StorageCreate(SuccessMessageMixin, CreateView):
def get_context_data(self, *args, **kwargs):
context = super(StorageCreate, self).get_context_data(*args, **kwargs)
other_hostnames = DataStoreHost.objects.all()
context["hostnames_of_datastore"] = []
context["other_hostnames"] = other_hostnames
context.update({
'box_title': _("Create a new data store"),
'template': "dashboard/_storage-create.html",
......@@ -191,7 +187,6 @@ class StorageDetail(SuperuserRequiredMixin, UpdateView):
def get_context_data(self, **kwargs):
context = super(StorageDetail, self).get_context_data(**kwargs)
try:
ds = self.get_object()
context['stats'] = self._get_stats()
......@@ -203,7 +198,7 @@ class StorageDetail(SuperuserRequiredMixin, UpdateView):
messages.error(self.request, _("Operation timed out, "
"some data may insufficient."))
except Exception as e:
messages.error(self.request, _("Error occured: %s, "
messages.error(self.request, _("Error occured: %s, "
"some data may insufficient."
% unicode(e)))
......@@ -262,8 +257,16 @@ class StorageDetail(SuperuserRequiredMixin, UpdateView):
'total_space': filesizeformat(total_space),
}
def get_form_class(self):
ds = self.get_object()
if ds.type == "ceph_block":
return CephDataStoreForm
else:
return DataStoreForm
def get_success_url(self):
return reverse("dashboard.views.storage")
ds = self.get_object()
return reverse("dashboard.views.storage-detail", kwargs={"pk": ds.id})
class DiskDetail(SuperuserRequiredMixin, UpdateView):
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import storage.models
class Migration(migrations.Migration):
dependencies = [
('storage', '0004_auto_20151212_0402'),
]
operations = [
migrations.AlterField(
model_name='datastore',
name='path',
field=models.CharField(unique=True, max_length=200, verbose_name='path or poolname', validators=[storage.models.validate_ascii]),
),
migrations.AlterField(
model_name='datastore',
name='secret_uuid',
field=models.CharField(max_length=255, null=True, verbose_name='uuid of secret key', blank=True),
),
]
......@@ -72,16 +72,19 @@ class DataStore(Model):
type = CharField(max_length=10, verbose_name=_('type'),
default='file', choices=TYPES)
name = CharField(max_length=100, unique=True, verbose_name=_('name'))
path = CharField(max_length=200, unique=True, verbose_name=_('path'),
validators=[validate_ascii])
# path or pool name when use ceph block device storage
path = CharField(max_length=200, unique=True,
verbose_name=_('path or poolname'),
validators=[validate_ascii])
# hostname of storage driver
hostname = CharField(max_length=40, verbose_name=_('hostname'))
# hostnames of Ceph monitors
hosts = ManyToManyField('DataStoreHost', blank=True,
verbose_name=_('hosts'))
ceph_user = CharField(max_length=255, null=True, blank=True,
verbose_name=_('Ceph username'))
secret_uuid = CharField(max_length=255, null=True, blank=True,
verbose_name=_('uuid of secret'))
verbose_name=_('uuid of secret key'))
class Meta:
ordering = ['name']
......
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