From 4e2835cc9fdfa195bcc1bcd2522b3e5d82f4f5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Thu, 28 May 2015 11:45:22 +0200 Subject: [PATCH] Add facilities for subordinate charms to affect dashboard settings --- hooks/horizon_contexts.py | 19 +++++++++++++++++++ hooks/horizon_hooks.py | 11 +++++++++++ hooks/horizon_utils.py | 3 ++- hooks/settings-relation-changed | 1 + hooks/settings-relation-joined | 1 + metadata.yaml | 3 +++ templates/essex/local_settings.py | 2 ++ templates/folsom/local_settings.py | 2 ++ templates/grizzly/local_settings.py | 2 ++ templates/havana/local_settings.py | 2 ++ templates/icehouse/local_settings.py | 2 ++ templates/juno/local_settings.py | 2 ++ 12 files changed, 49 insertions(+), 1 deletion(-) create mode 120000 hooks/settings-relation-changed create mode 120000 hooks/settings-relation-joined diff --git a/hooks/horizon_contexts.py b/hooks/horizon_contexts.py index 7200e662..1f117e26 100644 --- a/hooks/horizon_contexts.py +++ b/hooks/horizon_contexts.py @@ -172,3 +172,22 @@ class RouterSettingContext(OSContextGenerator): 'disable_router': False if config('profile') in ['cisco'] else True } return ctxt + + +class LocalSettingsContext(OSContextGenerator): + def __call__(self): + ''' Additional config stanzas to be appended to local_settings.py ''' + + settings = [] + + for rid in relation_ids("settings"): + for unit in related_units(rid): + rdata = relation_get(unit=unit, rid=rid) + if 'setting' in rdata: + settings.append('# {0}/{1}\n{2}'.format( + rid, unit, rdata['setting']) + ) + ctxt = { + 'settings': settings + } + return ctxt \ No newline at end of file diff --git a/hooks/horizon_hooks.py b/hooks/horizon_hooks.py index a02c15bd..5c80587d 100755 --- a/hooks/horizon_hooks.py +++ b/hooks/horizon_hooks.py @@ -244,6 +244,17 @@ def update_nrpe_config(): nrpe_setup.write() +@hooks.hook('settings-relation-joined') +def settings_relation_joined(): + relation_set(release=os_release("openstack-dashboard")) + + +@hooks.hook('settings-relation-changed') +@restart_on_change(restart_map()) +def update_plugin_config(): + CONFIGS.write(LOCAL_SETTINGS) + + def main(): try: hooks.execute(sys.argv) diff --git a/hooks/horizon_utils.py b/hooks/horizon_utils.py index 37d906fd..c3eaaca0 100644 --- a/hooks/horizon_utils.py +++ b/hooks/horizon_utils.py @@ -89,7 +89,8 @@ CONFIG_FILES = OrderedDict([ (LOCAL_SETTINGS, { 'hook_contexts': [horizon_contexts.HorizonContext(), horizon_contexts.IdentityServiceContext(), - context.SyslogContext()], + context.SyslogContext(), + horizon_contexts.LocalSettingsContext()], 'services': ['apache2'] }), (APACHE_CONF, { diff --git a/hooks/settings-relation-changed b/hooks/settings-relation-changed new file mode 120000 index 00000000..3195386e --- /dev/null +++ b/hooks/settings-relation-changed @@ -0,0 +1 @@ +horizon_hooks.py \ No newline at end of file diff --git a/hooks/settings-relation-joined b/hooks/settings-relation-joined new file mode 120000 index 00000000..3195386e --- /dev/null +++ b/hooks/settings-relation-joined @@ -0,0 +1 @@ +horizon_hooks.py \ No newline at end of file diff --git a/metadata.yaml b/metadata.yaml index 4ee536a8..adc78078 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -17,6 +17,9 @@ requires: ha: interface: hacluster scope: container + settings: + interface: openstack-dashboard-settings + scope: container peers: cluster: interface: openstack-dashboard-ha diff --git a/templates/essex/local_settings.py b/templates/essex/local_settings.py index 99c459d9..e06c9408 100644 --- a/templates/essex/local_settings.py +++ b/templates/essex/local_settings.py @@ -118,3 +118,5 @@ LOGGING = { } } } + +{{ settings|join('\n\n') }} diff --git a/templates/folsom/local_settings.py b/templates/folsom/local_settings.py index 2ff61fa9..f6796303 100644 --- a/templates/folsom/local_settings.py +++ b/templates/folsom/local_settings.py @@ -167,3 +167,5 @@ LOGIN_REDIRECT_URL='{{ webroot }}' # offline compression by default. To enable online compression, install # the node-less package and enable the following option. COMPRESS_OFFLINE = {{ compress_offline }} + +{{ settings|join('\n\n') }} \ No newline at end of file diff --git a/templates/grizzly/local_settings.py b/templates/grizzly/local_settings.py index 4df94e31..d87b84c1 100644 --- a/templates/grizzly/local_settings.py +++ b/templates/grizzly/local_settings.py @@ -263,3 +263,5 @@ LOGGING = { } } } + +{{ settings|join('\n\n') }} diff --git a/templates/havana/local_settings.py b/templates/havana/local_settings.py index b6a9ada4..3557f554 100644 --- a/templates/havana/local_settings.py +++ b/templates/havana/local_settings.py @@ -483,3 +483,5 @@ COMPRESS_OFFLINE = {{ compress_offline }} # installations should have this set accordingly. For more information # see https://docs.djangoproject.com/en/dev/ref/settings/. ALLOWED_HOSTS = '*' + +{{ settings|join('\n\n') }} \ No newline at end of file diff --git a/templates/icehouse/local_settings.py b/templates/icehouse/local_settings.py index 490d5340..c39570b5 100644 --- a/templates/icehouse/local_settings.py +++ b/templates/icehouse/local_settings.py @@ -514,3 +514,5 @@ COMPRESS_OFFLINE = {{ compress_offline }} # installations should have this set accordingly. For more information # see https://docs.djangoproject.com/en/dev/ref/settings/. ALLOWED_HOSTS = '*' + +{{ settings|join('\n\n') }} \ No newline at end of file diff --git a/templates/juno/local_settings.py b/templates/juno/local_settings.py index 50415f8a..cdce17d4 100644 --- a/templates/juno/local_settings.py +++ b/templates/juno/local_settings.py @@ -619,3 +619,5 @@ LOGIN_REDIRECT_URL='{{ webroot }}' # installations should have this set accordingly. For more information # see https://docs.djangoproject.com/en/dev/ref/settings/. ALLOWED_HOSTS = '*' + +{{ settings|join('\n\n') }} \ No newline at end of file