From b553d4bfb193d320f2aa9d999fabef53fccfe6f4 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Wed, 19 Nov 2014 13:22:43 +0100 Subject: [PATCH] Add a scale-out dialog Support for updating the deployed stack. Change-Id: Iefbadba7f5f4c55cb7d1f6fa7b0087b48e7161d5 --- tuskar_ui/api/heat.py | 2 +- tuskar_ui/infrastructure/overview/forms.py | 33 ++++++++++++ tuskar_ui/infrastructure/overview/urls.py | 3 ++ tuskar_ui/infrastructure/overview/views.py | 24 +++++++++ .../infrastructure/scss/_numberpicker.scss | 1 + .../infrastructure/overview/_scale_out.html | 41 +++++++++++++++ .../overview/deployment_live.html | 52 ++++++++++++------- .../infrastructure/overview/scale_out.html | 11 ++++ 8 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 tuskar_ui/infrastructure/templates/infrastructure/overview/_scale_out.html create mode 100644 tuskar_ui/infrastructure/templates/infrastructure/overview/scale_out.html diff --git a/tuskar_ui/api/heat.py b/tuskar_ui/api/heat.py index ae7fc718c..8203a66ba 100644 --- a/tuskar_ui/api/heat.py +++ b/tuskar_ui/api/heat.py @@ -98,7 +98,7 @@ class Stack(base.APIResourceWrapper): 'environment': environment, 'files': provider_resource_templates, } - password = getattr(settings, 'UNDERCLOUD_ADMIN_PASSWORD', None), + password = getattr(settings, 'UNDERCLOUD_ADMIN_PASSWORD', None) # TODO(lsmola) Bug #1394505. Until then we are calling the client # directly. When it's fixed, we should use heat_update from diff --git a/tuskar_ui/infrastructure/overview/forms.py b/tuskar_ui/infrastructure/overview/forms.py index 110d94945..7cd172b9b 100644 --- a/tuskar_ui/infrastructure/overview/forms.py +++ b/tuskar_ui/infrastructure/overview/forms.py @@ -161,6 +161,39 @@ class EditPlan(horizon.forms.SelfHandlingForm): return True +class ScaleOut(EditPlan): + def __init__(self, *args, **kwargs): + super(ScaleOut, self).__init__(*args, **kwargs) + for name, field in self.fields.items(): + if name.endswith('-count'): + field.widget.attrs['min'] = field.initial + + def handle(self, request, data): + if not super(ScaleOut, self).handle(request, data): + return False + plan = self.plan + try: + stack = api.heat.Stack.get_by_plan(self.request, plan) + stack.update(request, plan.name, plan.master_template, + plan.environment, plan.provider_resource_templates) + except Exception as e: + LOG.exception(e) + if hasattr(e, 'error'): + horizon.exceptions.handle( + request, + _( + "Unable to deploy overcloud. Reason: {0}" + ).format(e.error['error']['message']), + ) + return False + else: + raise + else: + msg = _('Deployment in progress.') + horizon.messages.success(request, msg) + return True + + class DeployOvercloud(horizon.forms.SelfHandlingForm): def handle(self, request, data): try: diff --git a/tuskar_ui/infrastructure/overview/urls.py b/tuskar_ui/infrastructure/overview/urls.py index 2c9242709..6e409a6b6 100644 --- a/tuskar_ui/infrastructure/overview/urls.py +++ b/tuskar_ui/infrastructure/overview/urls.py @@ -29,4 +29,7 @@ urlpatterns = urls.patterns( urls.url(r'^post-deploy-init$', views.PostDeployInitView.as_view(), name='post_deploy_init'), + urls.url(r'^scale-out$', + views.ScaleOutView.as_view(), + name='scale_out'), ) diff --git a/tuskar_ui/infrastructure/overview/views.py b/tuskar_ui/infrastructure/overview/views.py index 0eb41fadb..bc06fb686 100644 --- a/tuskar_ui/infrastructure/overview/views.py +++ b/tuskar_ui/infrastructure/overview/views.py @@ -313,3 +313,27 @@ class PostDeployInitView(horizon.forms.ModalFormView, StackMixin): initial = super(PostDeployInitView, self).get_initial(**kwargs) initial['stack_id'] = self.get_stack().id return initial + + +class ScaleOutView(horizon.forms.ModalFormView, StackMixin): + form_class = forms.ScaleOut + template_name = "infrastructure/overview/scale_out.html" + submit_label = _("Deploy Changes") + + def get_success_url(self): + return reverse(INDEX_URL) + + def get_form(self, form_class): + return form_class(self.request, **self.get_form_kwargs()) + + def get_context_data(self, *args, **kwargs): + context = super(ScaleOutView, self).get_context_data(*args, **kwargs) + plan = api.tuskar.Plan.get_the_plan(self.request) + form = context.get('form') + roles = [_get_role_data(plan, None, form, role) + for role in plan.role_list] + context.update({ + 'roles': roles, + 'plan': plan, + }) + return context diff --git a/tuskar_ui/infrastructure/static/infrastructure/scss/_numberpicker.scss b/tuskar_ui/infrastructure/static/infrastructure/scss/_numberpicker.scss index fa7d1a532..d443c41ee 100644 --- a/tuskar_ui/infrastructure/static/infrastructure/scss/_numberpicker.scss +++ b/tuskar_ui/infrastructure/static/infrastructure/scss/_numberpicker.scss @@ -15,6 +15,7 @@ div.number_picker { margin: 8px auto; padding: 0; text-align: center; + outline: 0; } a { display: block; diff --git a/tuskar_ui/infrastructure/templates/infrastructure/overview/_scale_out.html b/tuskar_ui/infrastructure/templates/infrastructure/overview/_scale_out.html new file mode 100644 index 000000000..550aa42dd --- /dev/null +++ b/tuskar_ui/infrastructure/templates/infrastructure/overview/_scale_out.html @@ -0,0 +1,41 @@ +{% extends "horizon/common/_modal_form.html" %} +{% load i18n %} +{% load url from future %} +{% load form_helpers %} + +{% block form_id %}scale_out_form{% endblock %} +{% block form_action %}{% url 'horizon:infrastructure:overview:scale_out' %}{% endblock %} + +{% block modal_id %}scale_out_modal{% endblock %} +{% block modal-header %}{% trans "Scale-out Deployment" %}{% endblock %} + +{% block modal-body %} +
+ {% include 'horizon/common/_form_errors.html' with form=form %} +{% for role in roles %} +
+
+ {{ role.name|capfirst }} + {% for error in role.field.errors %} + + {{ error }} + + {% endfor %} +
+
+ {{ role.planned_node_count }} → +
+
+ {{ role.field|add_bootstrap_class }} +
+
+{% endfor %} +
+ + + +{% endblock %} diff --git a/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_live.html b/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_live.html index a988d9fa8..9d371641d 100644 --- a/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_live.html +++ b/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_live.html @@ -1,7 +1,7 @@ {% extends "infrastructure/overview/deployment_base.html" %} {% load i18n %} -{% load url from future%} +{% load url from future %} {% block deployment-heading %}
@@ -18,27 +18,41 @@
{% for dashboard_url in dashboard_urls %}
-
{% trans "Horizon URL:" %}
- +
{% trans "Horizon URL:" %}
+
{% endfor %}
-
{% trans "User name:" %}
-
admin
+
{% trans "User name:" %}
+
admin
+
+
+
{% trans "Password" %}
+
+ {% trans "Reveal" %} +
-
-
-
-
-
- {% trans "Password" %} -
-
- -
-
-
-
-
+ + +{% endblock %} + +{% block deployment-buttons %} + {{ block.super }} + + {% trans "Scale-out" %} + + {% endblock %} diff --git a/tuskar_ui/infrastructure/templates/infrastructure/overview/scale_out.html b/tuskar_ui/infrastructure/templates/infrastructure/overview/scale_out.html new file mode 100644 index 000000000..4ef31c202 --- /dev/null +++ b/tuskar_ui/infrastructure/templates/infrastructure/overview/scale_out.html @@ -0,0 +1,11 @@ +{% extends 'infrastructure/base.html' %} +{% load i18n %} +{% block title %}{% trans "Scale-out Deployment" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Scale-out Deployment") %} +{% endblock page_header %} + +{% block infrastructure_main %} + {% include "infrastructure/overview/_scale_out.html" %} +{% endblock %}