From e832c8549b3cb7c0f4671668a5b404374eb8a64b Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Sun, 23 Dec 2018 05:57:41 +0900 Subject: [PATCH] Allow to specify custom templates for clouds.yaml and openrc Change-Id: I1ef6899f4d14c660eba50f16e813c280657475fc Closes-Bug: #1795851 --- doc/source/configuration/settings.rst | 77 +++++++++++++++++++ .../dashboards/project/api_access/views.py | 26 ++++--- openstack_dashboard/settings.py | 3 + ...nrc-clouds-yaml-link-f1642b77e25f08ba.yaml | 8 ++ 4 files changed, 103 insertions(+), 11 deletions(-) diff --git a/doc/source/configuration/settings.rst b/doc/source/configuration/settings.rst index 66c7e02b3e..475ded289c 100644 --- a/doc/source/configuration/settings.rst +++ b/doc/source/configuration/settings.rst @@ -505,6 +505,34 @@ OpenStack dashboard to use a specific API version for a given service API. "compute": 2 } +OPENSTACK_CLOUDS_YAML_CUSTOM_TEMPLATE +------------------------------------- + +.. versionadded:: 15.0.0(Stein) + +Default: ``None`` + +Example:: ``my-clouds.yaml.template`` + +A template name for a custom user's ``clouds.yaml`` file. +``None`` means the default template for ``clouds.yaml`` is used. + +If the default template is not suitable for your deployment, +you can provide your own clouds.yaml by specifying this setting. + +The default template is defined as `clouds.yaml.template +`__ +and available context parameters are found in ``_get_openrc_credentials()`` +and ``download_clouds_yaml_file()`` functions in +`openstack_dashboard/dashboards/project/api_access/views.py +`__. + +.. note:: + + Your template needs to be placed in the search paths of Django templates. + You may need to configure `ADD_TEMPLATE_DIRS`_ setting + to contain a path where your template exists. + OPENSTACK_CLOUDS_YAML_NAME -------------------------- @@ -552,6 +580,37 @@ basic deployment. If you have multiple regions you should use the `AVAILABLE_REGIONS`_ setting instead. +OPENRC_CUSTOM_TEMPLATE +---------------------- + +.. versionadded:: 15.0.0(Stein) + +Default: ``None`` + +Example:: ``my-openrc.sh.template`` + +A template name for a custom user's ``openrc`` file. +``None`` means the default template for ``openrc`` is used. + +If the default template is not suitable for your deployment, +for example, if your deployment uses saml2, openid and so on +for authentication, the default ``openrc`` would not be sufficient. +You can provide your own clouds.yaml by specifying this setting. + +The default template is defined as `openrc.sh.template +`__ +and available context parameters are found in ``_get_openrc_credentials()`` +and ``download_rc_file()`` functions in +`openstack_dashboard/dashboards/project/api_access/views.py +`__. + +.. note:: + + Your template needs to be placed in the search paths of Django templates. + Check ``TEMPLATES[0]['DIRS']``. + You may need to specify somewhere your template exist + to ``DIRS`` in ``TEMPLATES`` setting. + OPENSTACK_PROFILER ------------------ @@ -830,6 +889,10 @@ Default:: ``True`` Controls whether the keystone openrc file is accesible from the user menu and the api access panel. +.. seealso:: + + `OPENRC_CUSTOM_TEMPLATE`_ to provide a custom ``openrc``. + SHOW_OPENSTACK_CLOUDS_YAML -------------------------- @@ -840,6 +903,11 @@ Default:: ``True`` Controls whether clouds.yaml is accesible from the user menu and the api access panel. +.. seealso:: + + `OPENSTACK_CLOUDS_YAML_CUSTOM_TEMPLATE`_ to provide a custom + ``clouds.yaml``. + SHOW_KEYSTONE_V2_RC -------------------- @@ -2431,6 +2499,15 @@ Horizon's usage of the ``TEMPLATES`` involves 3 further settings below; it is generally advised to use those before attempting to alter the ``TEMPLATES`` setting itself. +ADD_TEMPLATE_DIRS +----------------- + +.. versionadded:: 15.0.0(Stein) + +Template directories defined here will be added to ``DIRS`` option +of Django ``TEMPLATES`` setting. It is useful when you would like to +load deployment-specific templates. + ADD_TEMPLATE_LOADERS ~~~~~~~~~~~~~~~~~~~~ diff --git a/openstack_dashboard/dashboards/project/api_access/views.py b/openstack_dashboard/dashboards/project/api_access/views.py index d9e56ef098..616108a29b 100644 --- a/openstack_dashboard/dashboards/project/api_access/views.py +++ b/openstack_dashboard/dashboards/project/api_access/views.py @@ -75,14 +75,15 @@ def _get_openrc_credentials(request): keystone_url = api.base.url_for(request, 'identity', endpoint_type='publicURL') - credentials = dict(tenant_id=request.user.tenant_id, - tenant_name=request.user.tenant_name, - auth_url=keystone_url, - user=request.user, - interface='public', - os_endpoint_type='publicURL', - region=getattr(request.user, 'services_region') or "") - return credentials + return { + 'tenant_id': request.user.tenant_id, + 'tenant_name': request.user.tenant_name, + 'auth_url': keystone_url, + 'user': request.user, + 'interface': 'public', + 'os_endpoint_type': 'publicURL', + 'region': getattr(request.user, 'services_region') or "", + } def download_ec2_bundle(request): @@ -126,9 +127,10 @@ def download_rc_file_v2(request): def download_rc_file(request): - template = 'project/api_access/openrc.sh.template' - context = _get_openrc_credentials(request) + template = getattr(settings, 'OPENRC_CUSTOM_TEMPLATE', + 'project/api_access/openrc.sh.template') + context = _get_openrc_credentials(request) # make v3 specific changes context['user_domain_name'] = request.user.user_domain_name try: @@ -145,7 +147,9 @@ def download_rc_file(request): def download_clouds_yaml_file(request): - template = 'project/api_access/clouds.yaml.template' + template = getattr(settings, 'OPENSTACK_CLOUDS_YAML_CUSTOM_TEMPLATE', + 'project/api_access/clouds.yaml.template') + context = _get_openrc_credentials(request) context['cloud_name'] = getattr( settings, "OPENSTACK_CLOUDS_YAML_NAME", 'openstack') diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index 1b26aa7b02..8a42b491ad 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -135,6 +135,7 @@ CACHED_TEMPLATE_LOADERS = [ ] ADD_TEMPLATE_LOADERS = [] +ADD_TEMPLATE_DIRS = [] TEMPLATES = [ { @@ -382,6 +383,8 @@ except ImportError: if not TEMPLATES[0]['DIRS']: TEMPLATES[0]['DIRS'] = [os.path.join(ROOT_PATH, 'templates')] +TEMPLATES[0]['DIRS'] += ADD_TEMPLATE_DIRS + # configure template debugging TEMPLATES[0]['OPTIONS']['debug'] = DEBUG diff --git a/releasenotes/notes/openrc-clouds-yaml-link-f1642b77e25f08ba.yaml b/releasenotes/notes/openrc-clouds-yaml-link-f1642b77e25f08ba.yaml index bd03223f26..c303226f5e 100644 --- a/releasenotes/notes/openrc-clouds-yaml-link-f1642b77e25f08ba.yaml +++ b/releasenotes/notes/openrc-clouds-yaml-link-f1642b77e25f08ba.yaml @@ -8,3 +8,11 @@ features: the basic simple deployment and do not cover keystone authentication like saml2, openid and so on. The default ``openrc`` and ``clouds.yaml`` from horizon do not make sense for such environments. + + Custom templates for ``clouds.yaml`` and ``openrc`` files can be + configured now via ``OPENSTACK_CLOUDS_YAML_CUSTOM_TEMPLATE`` and + ``OPENRC_CUSTOM_TEMPLATE`` settings. For more detail, see the + `Settings Reference `__. + + ``ADD_TEMPLATE_DIRS`` setting is also added so that operators can place + custom templates for ``clouds.yaml`` at deployment-specific paths.