From b3a0d54a617026cc317141d36afb7d7989269e51 Mon Sep 17 00:00:00 2001 From: "Brad P. Crochet" Date: Thu, 6 Aug 2015 15:48:34 -0400 Subject: Add a display and download of overcloudrc No overcloudrc was created when deployed via the UI. This adds the ability to view the values and to download an appropriate rc file. Change-Id: I2ee7cc4b10559a3542a6d22b01179b764c857d6b --- tuskar_ui/infrastructure/overview/urls.py | 3 ++ tuskar_ui/infrastructure/overview/views.py | 44 +++++++++++++++++ .../infrastructure/js/tuskar.deployment_live.js | 17 +++++++ .../templates/infrastructure/_scripts.html | 1 + .../infrastructure/overview/deployment_base.html | 2 + .../infrastructure/overview/deployment_live.html | 55 ++++++++++++++++++++++ .../overview/overcloudrc.sh.template | 9 ++++ 7 files changed, 131 insertions(+) create mode 100644 tuskar_ui/infrastructure/static/infrastructure/js/tuskar.deployment_live.js create mode 100644 tuskar_ui/infrastructure/templates/infrastructure/overview/overcloudrc.sh.template diff --git a/tuskar_ui/infrastructure/overview/urls.py b/tuskar_ui/infrastructure/overview/urls.py index 6e409a6b..35410d5d 100644 --- a/tuskar_ui/infrastructure/overview/urls.py +++ b/tuskar_ui/infrastructure/overview/urls.py @@ -32,4 +32,7 @@ urlpatterns = urls.patterns( urls.url(r'^scale-out$', views.ScaleOutView.as_view(), name='scale_out'), + urls.url(r'^download-overcloudrc$', + views.download_overcloudrc_file, + name='download_overcloudrc'), ) diff --git a/tuskar_ui/infrastructure/overview/views.py b/tuskar_ui/infrastructure/overview/views.py index 970725c8..90f9fa37 100644 --- a/tuskar_ui/infrastructure/overview/views.py +++ b/tuskar_ui/infrastructure/overview/views.py @@ -13,14 +13,18 @@ # under the License. import json +import logging +import urlparse from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse_lazy from django import http +from django import shortcuts import django.utils.text from django.utils.translation import ugettext_lazy as _ import heatclient import horizon.forms +from horizon import messages from tuskar_ui import api from tuskar_ui.infrastructure.overview import forms @@ -29,6 +33,8 @@ from tuskar_ui.infrastructure import views INDEX_URL = 'horizon:infrastructure:overview:index' +LOG = logging.getLogger(__name__) + def _steps_message(messages): total_steps = len(messages) @@ -218,6 +224,10 @@ class IndexView(horizon.forms.ModalFormView, views.StackMixin): controller_role.parameter_prefix + 'AdminPassword') context['dashboard_urls'] = stack.dashboard_urls + no_proxy = [urlparse.urlparse(url).hostname + for url in stack.dashboard_urls] + context['no_proxy'] = ",".join(no_proxy) + context['auth_url'] = stack.keystone_auth_url else: messages = forms.validate_plan(request, plan) context['plan_messages'] = messages @@ -344,3 +354,37 @@ class ScaleOutView(horizon.forms.ModalFormView, views.StackMixin): 'plan': plan, }) return context + + +def _get_openrc_credentials(request): + plan = api.tuskar.Plan.get_the_plan(request) + stack = api.heat.Stack.get_by_plan(request, plan) + no_proxy = [urlparse.urlparse(url).hostname + for url in stack.dashboard_urls] + controller_role = plan.get_role_by_name("Controller") + credentials = dict(tenant_name='admin', + auth_url=stack.keystone_auth_url, + admin_password=plan.parameter_value( + controller_role.parameter_prefix + 'AdminPassword'), + no_proxy=",".join(no_proxy)) + return credentials + + +def download_overcloudrc_file(request): + template = 'infrastructure/overview/overcloudrc.sh.template' + try: + context = _get_openrc_credentials(request) + + response = shortcuts.render(request, + template, + context, + content_type="text/plain") + response['Content-Disposition'] = ('attachment; ' + 'filename="overcloudrc"') + response['Content-Length'] = str(len(response.content)) + return response + + except Exception as e: + LOG.exception("Exception in DownloadOvercloudrcForm.") + messages.error(request, _('Error Downloading RC File: %s') % e) + return shortcuts.redirect(request.build_absolute_uri()) diff --git a/tuskar_ui/infrastructure/static/infrastructure/js/tuskar.deployment_live.js b/tuskar_ui/infrastructure/static/infrastructure/js/tuskar.deployment_live.js new file mode 100644 index 00000000..22e4f2f5 --- /dev/null +++ b/tuskar_ui/infrastructure/static/infrastructure/js/tuskar.deployment_live.js @@ -0,0 +1,17 @@ +tuskar.deployment_live = (function () { + 'use strict'; + + var module = {}; + + module.init = function () { + $("#overcloudrc").on("hide.bs.collapse", function(){ + $("span.overcloudrc").html('Show '); + }); + $("#overcloudrc").on("show.bs.collapse", function(){ + $("span.overcloudrc").html('Hide '); + }); + }; + + horizon.addInitFunction(module.init); + return module; +} ()); diff --git a/tuskar_ui/infrastructure/templates/infrastructure/_scripts.html b/tuskar_ui/infrastructure/templates/infrastructure/_scripts.html index 61d91811..ff190f01 100644 --- a/tuskar_ui/infrastructure/templates/infrastructure/_scripts.html +++ b/tuskar_ui/infrastructure/templates/infrastructure/_scripts.html @@ -10,6 +10,7 @@ + {% endblock %} {% comment %} Tuskar-UI Client-side Templates (These should *not* be inside the "compress" tag.) {% endcomment %} diff --git a/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_base.html b/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_base.html index b8065a6d..04bf8eef 100644 --- a/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_base.html +++ b/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_base.html @@ -22,4 +22,6 @@ +{% block deployment-overcloudrc %}{% endblock %} + {% block templates %}{% endblock %} diff --git a/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_live.html b/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_live.html index 9d371641..af6dfa81 100644 --- a/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_live.html +++ b/tuskar_ui/infrastructure/templates/infrastructure/overview/deployment_live.html @@ -56,3 +56,58 @@ {% endblock %} + +{% block deployment-overcloudrc %} +
+
+ +
+
+

{% trans "Overcloudrc Information" %}

+
+
+
NOVA_VERSION:
+
1.1
+
+
+
OS_USERNAME:
+
admin
+
+
+
OS_PASSWORD:
+
{{ admin_password }}
+
+
+
OS_AUTH_URL:
+
{{ auth_url }}
+
+
+
OS_TENANT_NAME:
+
admin
+
+
+
COMPUTE_API_VERSION:
+
1.1
+
+
+
OS_NO_CACHE:
+
True
+
+
+
no_proxy:
+
{{ no_proxy }}
+
+
+
{% trans "Download" %}
+ +
+
+
+{% endblock %} diff --git a/tuskar_ui/infrastructure/templates/infrastructure/overview/overcloudrc.sh.template b/tuskar_ui/infrastructure/templates/infrastructure/overview/overcloudrc.sh.template new file mode 100644 index 00000000..5977bb37 --- /dev/null +++ b/tuskar_ui/infrastructure/templates/infrastructure/overview/overcloudrc.sh.template @@ -0,0 +1,9 @@ +#!/bin/bash +export NOVA_VERSION=1.1 +export OS_AUTH_URL={{ auth_url }} +export OS_TENANT_NAME="admin" +export OS_USERNAME="admin" +export OS_PASSWORD={{ admin_password }} +export COMPUTE_API_VERSION=1.1 +export OS_NO_CACHE=True +export no_proxy={{ no_proxy }} -- cgit v1.2.1