Commit 33ff6a60 by Czémán Arnold

dashboard, storage, vm: naming refactorization, hosts --> endpoints,…

dashboard, storage, vm: naming refactorization, hosts --> endpoints, DataStoreHost --> Endpoint, etc...
parent e82593fc
......@@ -20,7 +20,7 @@
"pk": 1,
"model": "storage.datastore",
"fields": {
"hosts": [],
"endpoints": [],
"type": "file",
"ceph_user": null,
"secret_uuid": null,
......
......@@ -54,7 +54,7 @@ from firewall.models import Vlan, Host
from vm.models import (
InstanceTemplate, Lease, InterfaceTemplate, Node, Trait, Instance
)
from storage.models import DataStore, Disk, DataStoreHost
from storage.models import DataStore, Disk, Endpoint
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.contrib.auth.models import Permission
from .models import Profile, GroupProfile, Message
......@@ -1665,12 +1665,12 @@ class CephDataStoreForm(DataStoreForm):
class Meta:
model = DataStore
fields = ("type", "name", "path", "hostname",
"ceph_user", "secret_uuid", "hosts")
widgets = {"hosts": FilteredSelectMultiple(_("Hostnames"),
is_stacked=True)}
"ceph_user", "secret_uuid", "endpoints")
widgets = {"endpoints": FilteredSelectMultiple(_("Endpoints"),
is_stacked=True)}
class DataStoreHostForm(ModelForm):
class EndpointForm(ModelForm):
@property
def helper(self):
......@@ -1689,12 +1689,12 @@ class DataStoreHostForm(ModelForm):
return helper
def __init__(self, *args, **kwargs):
super(DataStoreHostForm, self).__init__(*args, **kwargs)
super(EndpointForm, self).__init__(*args, **kwargs)
self.fields['port'].initial = 6789
class Meta:
model = DataStoreHost
model = Endpoint
fields = ("name", "address", "port")
......
......@@ -87,7 +87,7 @@ $(function () {
return false;
});
$('.data_store_host-create').click(function(e) {
$('.datastore_endpoint-create').click(function(e) {
$.ajax({
type: 'GET',
url: $(this).prop('href'),
......@@ -99,12 +99,12 @@ $(function () {
modal.remove();
});
$("#data_store_host_host-create-btn").click(function(){
var form = $("#data_store_host_form");
$("#datastore_endpoint_host-create-btn").click(function(){
var form = $("#datastore_endpoint_form");
$.post(form.attr("action"), form.serialize(), function(data){
if(data.status===true){
$('#id_hosts_from')
$('#id_endpoints_from')
.append($('<option>')
.text(data.response.text)
.attr('value', data.response.val));
......@@ -114,7 +114,7 @@ $(function () {
$('.modal-backdrop').remove();
}
else{
var error_msg = $("#data_store_host-create-alert");
var error_msg = $("#datastore_endpoint-create-alert");
error_msg.empty();
error_msg.append(data.response);
error_msg.show();
......
......@@ -2,8 +2,8 @@
{% load crispy_forms_tags %}
<form id="data_store_host_form" action="{% url "dashboard.views.storage-host-create" %}" method="POST">
<div class="alert alert-danger" style="display: none;" id="data_store_host-create-alert">
<form id="datastore_endpoint_form" action="{% url "dashboard.views.storage-endpoint-create" %}" method="POST">
<div class="alert alert-danger" style="display: none;" id="datastore_endpoint-create-alert">
</div>
{% with form=form %}
{% include "display-form-errors.html" %}
......@@ -22,7 +22,7 @@
{{ form.port|as_crispy_field }}
</div>
</div>
<input type="submit" value="{% trans "Create new hostname" %}" class="btn btn-success" id="data_store_host_host-create-btn">
<input type="submit" value="{% trans "Create new endpoint" %}" class="btn btn-success" id="datastore_endpoint_host-create-btn">
</form>
......
......@@ -20,17 +20,17 @@
{{ 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">
<legend>{% trans "Select or add new Ceph monitor endpoints(s)" %}</legend>
<a href="{% url "dashboard.views.storage-endpoint-create" %}" class="btn btn-success datastore_endpoint-create">
<i class="fa fa-plus"></i>
{% trans "new hostname" %}
{% trans "new endpoint" %}
</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 }}
{{ form.endpoints }}
</div>
<link rel="stylesheet" type="text/css" href="/static/admin/css/widgets.css" />
</fieldset>
......
......@@ -54,7 +54,7 @@ from .views import (
NodeActivityView,
UserList,
StorageDetail, StorageList, StorageChoose, StorageCreate, DiskDetail,
DataStoreHostCreate,
EndpointCreate,
MessageList, MessageDetail, MessageCreate, MessageDelete,
)
from .views.vm import vm_ops, vm_mass_ops
......@@ -245,8 +245,8 @@ urlpatterns = patterns(
url(r'^storage/choose/$', StorageChoose.as_view(),
name="dashboard.views.storage-choose"),
url(r'^storage/host/create/$', DataStoreHostCreate.as_view(),
name="dashboard.views.storage-host-create"),
url(r'^storage/endpoint/create/$', EndpointCreate.as_view(),
name="dashboard.views.storage-endpoint-create"),
url(r'^disk/(?P<pk>\d+)/$', DiskDetail.as_view(),
name="dashboard.views.disk-detail"),
......
......@@ -33,11 +33,11 @@ from braces.views import SuperuserRequiredMixin
from sizefield.utils import filesizeformat
from common.models import WorkerNotFound
from storage.models import DataStore, Disk, DataStoreHost
from storage.models import DataStore, Disk, Endpoint
from ..tables import DiskListTable, StorageListTable
from ..forms import (
DataStoreForm, CephDataStoreForm, DiskForm, StorageListSearchForm,
DataStoreHostForm
EndpointForm
)
from .util import FilterMixin
import json
......@@ -151,7 +151,7 @@ class StorageList(SuperuserRequiredMixin, FilterMixin, SingleTableView):
'path': "path__icontains",
'poolname': "path__icontains",
'hostname': "hostname__iexact",
'address': "hosts__address__in"
'address': "endpoints__address__in"
}
def get_context_data(self, *args, **kwargs):
......@@ -278,9 +278,9 @@ class DiskDetail(SuperuserRequiredMixin, UpdateView):
pass
class DataStoreHostCreate(SuccessMessageMixin, CreateView):
model = DataStoreHost
form_class = DataStoreHostForm
class EndpointCreate(SuccessMessageMixin, CreateView):
model = Endpoint
form_class = EndpointForm
def get_template_names(self):
if self.request.is_ajax():
......@@ -289,24 +289,24 @@ class DataStoreHostCreate(SuccessMessageMixin, CreateView):
return ['dashboard/nojs-wrapper.html']
def get_context_data(self, *args, **kwargs):
context = super(DataStoreHostCreate, self).get_context_data(
context = super(EndpointCreate, self).get_context_data(
*args, **kwargs)
context.update({
'box_title': _("Create a new hostname"),
'box_title': _("Create a new endpoint"),
'ajax_title': True,
'template': "dashboard/_data_store_host-create.html",
'template': "dashboard/_datastore_endpoint-create.html",
})
return context
def get(self, *args, **kwargs):
if not self.request.user.has_perm('vm.add_datastorehost'):
if not self.request.user.has_perm('storage.add_endpoint'):
raise PermissionDenied()
return super(DataStoreHostCreate, self).get(*args, **kwargs)
return super(EndpointCreate, self).get(*args, **kwargs)
def post(self, request, *args, **kwargs):
if not self.request.user.has_perm('vm.add_datastorehost'):
if not self.request.user.has_perm('storage.add_endpoint'):
raise PermissionDenied()
form = self.form_class(request.POST)
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('storage', '0005_auto_20160331_1823'),
]
operations = [
migrations.CreateModel(
name='Endpoint',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(unique=True, max_length=255, verbose_name='name')),
('address', models.CharField(max_length=1024, verbose_name='address')),
('port', models.IntegerField(null=True, verbose_name='port', blank=True)),
],
),
migrations.RemoveField(
model_name='datastore',
name='hosts',
),
migrations.DeleteModel(
name='DataStoreHost',
),
migrations.AddField(
model_name='datastore',
name='endpoints',
field=models.ManyToManyField(to='storage.Endpoint', verbose_name='endpoints', blank=True),
),
]
......@@ -52,7 +52,7 @@ def validate_ascii(value):
raise ValidationError("%s is not 'ascii' string" % value)
class DataStoreHost(Model):
class Endpoint(Model):
""" Address and port of a data store.
"""
......@@ -79,9 +79,9 @@ class DataStore(Model):
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'))
# endpoints of Ceph monitors
endpoints = ManyToManyField(Endpoint, blank=True,
verbose_name=_('endpoints'))
ceph_user = CharField(max_length=255, null=True, blank=True,
verbose_name=_('Ceph username'))
secret_uuid = CharField(max_length=255, null=True, blank=True,
......@@ -116,9 +116,9 @@ class DataStore(Model):
return [disk.filename for disk in deletables]
def get_hosts(self):
def get_endpoints(self):
return [(host.address, host.port) for host in self.hosts.all()]
return [(ep.address, ep.port) for ep in self.endpoints.all()]
@property
def used_percent(self):
......@@ -458,7 +458,7 @@ class Disk(TimeStampedModel):
def get_vmdisk_desc_for_ceph_block_device(self):
desc = self.get_vmdisk_desc_for_filesystem()
desc["hosts"] = self.datastore.get_hosts()
desc["endpoints"] = self.datastore.get_endpoints()
desc["ceph_user"] = self.datastore.ceph_user
desc["secret_uuid"] = self.datastore.secret_uuid
......
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