From 64336feb91795d5784cf612d5ccc8a13b654a45f Mon Sep 17 00:00:00 2001 From: Junaid Ali Date: Wed, 4 May 2016 02:45:42 -0400 Subject: [PATCH] added relation with director to extract pg vip etc. --- config.yaml | 12 ------------ hooks/neutron_plumgrid_context.py | 31 ++++++++++++++++++++++++++----- hooks/neutron_plumgrid_hooks.py | 7 +++++++ metadata.yaml | 4 ++++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/config.yaml b/config.yaml index eb76c09..3cfb354 100644 --- a/config.yaml +++ b/config.yaml @@ -21,18 +21,6 @@ options: type: string description: | Provide the version of networking-plumgrid package that needs to be installed - plumgrid-username: - default: plumgrid - type: string - description: Username to access PLUMgrid Director - plumgrid-password: - default: plumgrid - type: string - description: Password to access PLUMgrid Director - plumgrid-virtual-ip: - default: 192.168.100.250 - type: string - description: IP address of PLUMgrid Director hardware-vendor-name: type: string default: vendor_name diff --git a/hooks/neutron_plumgrid_context.py b/hooks/neutron_plumgrid_context.py index 5604066..dced6d1 100644 --- a/hooks/neutron_plumgrid_context.py +++ b/hooks/neutron_plumgrid_context.py @@ -29,7 +29,28 @@ def _edge_settings(): return ctxt +def _plumgrid_configs(): + ''' + Inspects plumgrid-director relation to get plumgrid virtup ip, username and password. + ''' + ctxt = {} + for rid in relation_ids('plumgrid-configs'): + for unit in related_units(rid): + rdata = relation_get(rid=rid, unit=unit) + if 'plumgrid_virtual_ip' in rdata: + ctxt['plumgrid_virtual_ip'] = \ + rdata['plumgrid_virtual_ip'] + ctxt['plumgrid_username'] = \ + rdata['plumgrid_username'] + ctxt['plumgrid_password'] = \ + rdata['plumgrid_password'] + return ctxt + + def _identity_context(): + ''' + Inspects keystone relation to get keystone credentials. + ''' ctxs = [{ 'auth_host': gethostbyname(hostname), 'auth_port': relation_get('service_port', unit, rid), @@ -87,10 +108,6 @@ class NeutronPGPluginContext(context.NeutronContext): conf = config() enable_metadata = conf['enable-metadata'] - # (TODO) get this information from director - pg_ctxt['pg_username'] = conf['plumgrid-username'] - pg_ctxt['pg_password'] = conf['plumgrid-password'] - pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip'] pg_ctxt['hardware_vendor_name'] = config('hardware-vendor-name') pg_ctxt['switch_username'] = config('switch-username') pg_ctxt['switch_password'] = config('switch-password') @@ -114,6 +131,10 @@ class NeutronPGPluginContext(context.NeutronContext): pg_ctxt['service_protocol'] = identity_context['service_protocol'] pg_ctxt['auth_port'] = identity_context['auth_port'] pg_ctxt['auth_host'] = identity_context['auth_host'] + plumgrid_configs = _plumgrid_configs() + if plumgrid_configs: + pg_ctxt['pg_username'] = plumgrid_configs['plumgrid_username'] + pg_ctxt['pg_password'] = plumgrid_configs['plumgrid_password'] + pg_ctxt['virtual_ip'] = plumgrid_configs['plumgrid_virtual_ip'] print pg_ctxt - return pg_ctxt diff --git a/hooks/neutron_plumgrid_hooks.py b/hooks/neutron_plumgrid_hooks.py index 1db1b3b..c881355 100755 --- a/hooks/neutron_plumgrid_hooks.py +++ b/hooks/neutron_plumgrid_hooks.py @@ -95,6 +95,13 @@ def neutron_plugin_joined(): set_neutron_relation() +@hooks.hook("plumgrid-configs-relation-changed") +@hooks.hook("plumgrid-configs-relation-broken") +@restart_on_change(restart_map()) +def plumgrid_configs_relation(): + CONFIGS.write_all() + + @hooks.hook("identity-admin-relation-changed") @hooks.hook("identity-admin-relation-broken") @restart_on_change(restart_map()) diff --git a/metadata.yaml b/metadata.yaml index 8ad5126..7a39e3f 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -27,5 +27,9 @@ requires: container: interface: neutron-plugin-api scope: container + plumgrid: + interface: plumgrid identity-admin: interface: keystone-admin + plumgrid-configs: + interface: plumgrid-configs