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