Adding plan parameter view on service configuration tab
Change-Id: I4d1059b17351bfa1fb3739b78373c369406d724f
This commit is contained in:
parent
518ebac8a7
commit
dada6d433e
69
tuskar_ui/infrastructure/parameters/forms.py
Normal file
69
tuskar_ui/infrastructure/parameters/forms.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# -*- coding: utf8 -*-
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import django.forms
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
import horizon.exceptions
|
||||||
|
import horizon.forms
|
||||||
|
import horizon.messages
|
||||||
|
|
||||||
|
from tuskar_ui import api
|
||||||
|
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
VIRT_TYPE_CHOICES = [
|
||||||
|
('kvm', _("Virtualized (kvm)")),
|
||||||
|
('qemu', _("Baremetal (qemu)")),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class EditServiceConfig(horizon.forms.SelfHandlingForm):
|
||||||
|
virt_type = django.forms.ChoiceField(
|
||||||
|
label=_("Deployment Type"),
|
||||||
|
choices=VIRT_TYPE_CHOICES,
|
||||||
|
required=True,
|
||||||
|
)
|
||||||
|
snmp_password = django.forms.CharField(
|
||||||
|
label=_("SNMP Password"),
|
||||||
|
required=False,
|
||||||
|
widget=django.forms.PasswordInput(render_value=True))
|
||||||
|
|
||||||
|
def handle(self, request, data):
|
||||||
|
plan = api.tuskar.Plan.get_the_plan(self.request)
|
||||||
|
compute_prefix = plan.get_role_by_name('compute').parameter_prefix
|
||||||
|
control_prefix = plan.get_role_by_name('controller').parameter_prefix
|
||||||
|
virt_type = data.get('virt_type')
|
||||||
|
snmp_password = data.get('snmp_password')
|
||||||
|
parameters = {
|
||||||
|
compute_prefix + 'NovaComputeLibvirtType': virt_type,
|
||||||
|
compute_prefix + 'SnmpdReadonlyUserPassword': snmp_password,
|
||||||
|
control_prefix + 'SnmpdReadonlyUserPassword': snmp_password,
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
plan.patch(request, plan.uuid, parameters)
|
||||||
|
except Exception as e:
|
||||||
|
horizon.exceptions.handle(
|
||||||
|
request,
|
||||||
|
_("Unable to update the service configuration."))
|
||||||
|
LOG.exception(e)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
horizon.messages.success(
|
||||||
|
request,
|
||||||
|
_("Service configuration updated."))
|
||||||
|
return True
|
@ -21,7 +21,7 @@ class ParametersTable(tables.DataTable):
|
|||||||
label = tables.Column('label',
|
label = tables.Column('label',
|
||||||
verbose_name=_("Parameter Name"))
|
verbose_name=_("Parameter Name"))
|
||||||
value = tables.Column('value',
|
value = tables.Column('value',
|
||||||
verbose_name=_("Default Value"))
|
verbose_name=_("Value"))
|
||||||
description = tables.Column('description',
|
description = tables.Column('description',
|
||||||
verbose_name=("Detailed Description"))
|
verbose_name=("Detailed Description"))
|
||||||
|
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
{% extends "horizon/common/_modal_form.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load url from future %}
|
||||||
|
|
||||||
|
{% block form_id %}configuration_form{% endblock %}
|
||||||
|
{% block form_action %}{% url 'horizon:infrastructure:parameters:service_configuration' %}{% endblock %}
|
||||||
|
|
||||||
|
{% block modal_id %}provision_modal{% endblock %}
|
||||||
|
{% block modal-header %}{% trans "Service Configuration" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block modal-body %}
|
||||||
|
<div class="left">
|
||||||
|
<fieldset>
|
||||||
|
{% include "horizon/common/_form_fields.html" %}
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
<div class="right">
|
||||||
|
<h3>{% trans "Description:" %}</h3>
|
||||||
|
<p>
|
||||||
|
{% trans "Configure values that cannot be defaulted" %}
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
{% trans "These values cannot be defaulted. Please choose values for them and save them before you deploy your overcloud." %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block modal-footer %}
|
||||||
|
<input class="btn btn-primary" type="submit" value="{% trans "Save Configuration" %}" />
|
||||||
|
<a href="{% url 'horizon:infrastructure:parameters:index' %}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||||
|
{% endblock %}
|
||||||
|
{% load form_helpers %}
|
@ -9,6 +9,12 @@
|
|||||||
{% block main %}
|
{% block main %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
|
<div class="actions pull-right">
|
||||||
|
<a href="{% url 'horizon:infrastructure:parameters:service_configuration' %}" class="btn btn-primary ajax-modal">
|
||||||
|
<span class="fa fa-pencil"></span>
|
||||||
|
{% trans 'Edit Configuration' %}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<div class="no-table-title">
|
<div class="no-table-title">
|
||||||
{{ table.render }}
|
{{ table.render }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% block title %}{% trans "Service Configuration" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block page_header %}
|
||||||
|
{% include "horizon/common/_page_header.html" with title=_("Service Configuration") %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
{% include "infrastructure/parameters/_service_config.html" %}
|
||||||
|
{% endblock %}
|
@ -25,6 +25,8 @@ from tuskar_ui.test.test_data import tuskar_data
|
|||||||
|
|
||||||
INDEX_URL = urlresolvers.reverse(
|
INDEX_URL = urlresolvers.reverse(
|
||||||
'horizon:infrastructure:parameters:index')
|
'horizon:infrastructure:parameters:index')
|
||||||
|
SERVICE_CONFIG_URL = urlresolvers.reverse(
|
||||||
|
'horizon:infrastructure:parameters:service_configuration')
|
||||||
|
|
||||||
TEST_DATA = utils.TestDataContainer()
|
TEST_DATA = utils.TestDataContainer()
|
||||||
tuskar_data.data(TEST_DATA)
|
tuskar_data.data(TEST_DATA)
|
||||||
@ -52,10 +54,41 @@ class ParametersTest(test.BaseAdminViewTests):
|
|||||||
|
|
||||||
def test_param_object(self):
|
def test_param_object(self):
|
||||||
param_dict = {'parameter_group': 'Neutron',
|
param_dict = {'parameter_group': 'Neutron',
|
||||||
'default': '1.2.3.4',
|
'value': '1.2.3.4',
|
||||||
'name': 'Ip Address',
|
'name': 'Ip Address',
|
||||||
'description': 'This is an IP Address'}
|
'description': 'This is an IP Address'}
|
||||||
|
|
||||||
p = views.ServiceParameter(param_dict, 5)
|
p = views.ServiceParameter(param_dict, 5)
|
||||||
self.assertEqual(p.id, 5)
|
self.assertEqual(p.id, 5)
|
||||||
self.assertEqual(p.value, '1.2.3.4')
|
self.assertEqual(p.value, '1.2.3.4')
|
||||||
|
|
||||||
|
def test_service_config_get(self):
|
||||||
|
plan = api.tuskar.Plan(self.tuskarclient_plans.first())
|
||||||
|
role = api.tuskar.Role(self.tuskarclient_roles.first())
|
||||||
|
with contextlib.nested(
|
||||||
|
patch('tuskar_ui.api.tuskar.Plan.get_the_plan',
|
||||||
|
return_value=plan),
|
||||||
|
patch('tuskar_ui.api.tuskar.Plan.get_role_by_name',
|
||||||
|
return_value=role),
|
||||||
|
):
|
||||||
|
res = self.client.get(SERVICE_CONFIG_URL)
|
||||||
|
self.assertTemplateUsed(
|
||||||
|
res, 'infrastructure/parameters/service_config.html')
|
||||||
|
|
||||||
|
def test_service_config_post(self):
|
||||||
|
plan = api.tuskar.Plan(self.tuskarclient_plans.first())
|
||||||
|
role = api.tuskar.Role(self.tuskarclient_roles.first())
|
||||||
|
data = {
|
||||||
|
'virt_type': 'qemu',
|
||||||
|
'snmp_password': 'password',
|
||||||
|
}
|
||||||
|
with contextlib.nested(
|
||||||
|
patch('tuskar_ui.api.tuskar.Plan.get_the_plan',
|
||||||
|
return_value=plan),
|
||||||
|
patch('tuskar_ui.api.tuskar.Plan.patch',
|
||||||
|
return_value=plan),
|
||||||
|
patch('tuskar_ui.api.tuskar.Plan.get_role_by_name',
|
||||||
|
return_value=role),
|
||||||
|
):
|
||||||
|
res = self.client.post(SERVICE_CONFIG_URL, data)
|
||||||
|
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||||
|
@ -20,4 +20,7 @@ from tuskar_ui.infrastructure.parameters import views
|
|||||||
urlpatterns = urls.patterns(
|
urlpatterns = urls.patterns(
|
||||||
'',
|
'',
|
||||||
urls.url(r'^$', views.IndexView.as_view(), name='index'),
|
urls.url(r'^$', views.IndexView.as_view(), name='index'),
|
||||||
|
urls.url(r'^service-config$',
|
||||||
|
views.ServiceConfigView.as_view(),
|
||||||
|
name='service_configuration'),
|
||||||
)
|
)
|
||||||
|
@ -12,9 +12,12 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from django.core.urlresolvers import reverse_lazy
|
||||||
|
import horizon.forms
|
||||||
from horizon import tables as horizon_tables
|
from horizon import tables as horizon_tables
|
||||||
|
|
||||||
from tuskar_ui import api
|
from tuskar_ui import api
|
||||||
|
from tuskar_ui.infrastructure.parameters import forms
|
||||||
from tuskar_ui.infrastructure.parameters import tables
|
from tuskar_ui.infrastructure.parameters import tables
|
||||||
|
|
||||||
|
|
||||||
@ -22,11 +25,30 @@ class ServiceParameter:
|
|||||||
def __init__(self, params_dict, id):
|
def __init__(self, params_dict, id):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.label = params_dict.get('name')
|
self.label = params_dict.get('name')
|
||||||
self.value = params_dict.get('default')
|
self.value = params_dict.get('value')
|
||||||
self.category = params_dict.get('parameter_group')
|
self.category = params_dict.get('parameter_group')
|
||||||
self.description = params_dict.get('description')
|
self.description = params_dict.get('description')
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceConfigView(horizon.forms.ModalFormView):
|
||||||
|
template_name = "infrastructure/parameters/service_config.html"
|
||||||
|
form_class = forms.EditServiceConfig
|
||||||
|
success_url = reverse_lazy('horizon:infrastructure:parameters:index')
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
plan = api.tuskar.Plan.get_the_plan(self.request)
|
||||||
|
compute_prefix = plan.get_role_by_name('compute').parameter_prefix
|
||||||
|
|
||||||
|
virt_type = plan.parameter_value(
|
||||||
|
compute_prefix + 'NovaComputeLibvirtType')
|
||||||
|
#TODO(tzumainn): what if compute and control values are different...
|
||||||
|
snmp_password = plan.parameter_value(
|
||||||
|
compute_prefix + 'SnmpdReadonlyUserPassword')
|
||||||
|
|
||||||
|
return {'virt_type': virt_type,
|
||||||
|
'snmp_password': snmp_password}
|
||||||
|
|
||||||
|
|
||||||
class IndexView(horizon_tables.DataTableView):
|
class IndexView(horizon_tables.DataTableView):
|
||||||
table_class = tables.ParametersTable
|
table_class = tables.ParametersTable
|
||||||
template_name = "infrastructure/parameters/index.html"
|
template_name = "infrastructure/parameters/index.html"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user