diff --git a/hooks/neutron_api_context.py b/hooks/neutron_api_context.py index 329dea67..a9538f9f 100644 --- a/hooks/neutron_api_context.py +++ b/hooks/neutron_api_context.py @@ -154,9 +154,14 @@ class NeutronCCContext(context.NeutronContext): for k, v in _config.iteritems(): if k.startswith('vsd'): ctxt[k.replace('-', '_')] = v - if 'vsd-address' in _config: - ctxt['vsd_server'] = _config['vsd-address'] - elif 'vsd_server' not in ctxt: + for rid in relation_ids('vsd-rest-api'): + for unit in related_units(rid): + rdata = relation_get(rid=rid, unit=unit) + vsd_ip = rdata.get('vsd-ip-address') + log('relation data:vsd-ip-address: {}'.format(vsd_ip)) + if vsd_ip is not None: + ctxt['vsd_server'] = '{}:8443'.format(vsd_ip) + if 'vsd_server' not in ctxt: ctxt['vsd_server'] = '1.1.1.1:8443' ctxt['verbose'] = config('verbose') diff --git a/hooks/neutron_api_hooks.py b/hooks/neutron_api_hooks.py index cb9f7b0c..b50ae295 100755 --- a/hooks/neutron_api_hooks.py +++ b/hooks/neutron_api_hooks.py @@ -130,8 +130,6 @@ def install(): key = config('neutron-plugin-ppa-key') add_source(config('neutron-plugin-repository-url'), key) packages += config('vsp-packages').split() - if config('vsd-server'): - save_vsd_address_to_config(config('vsd-server')) apt_update() apt_install(packages, fatal=True) @@ -171,18 +169,11 @@ def vsd_changed(relation_id=None, remote_unit=None): if not vsd_ip_address: return vsd_address = '{}:8443'.format(vsd_ip_address) - save_vsd_address_to_config(vsd_address) log('vsd-rest-api-relation-changed: ip address:{}'.format(vsd_address)) vsd_config_file = config('vsd-config-file') update_config_file(vsd_config_file, 'server', vsd_address) -def save_vsd_address_to_config(vsd_address): - _config = config() - _config['vsd-address'] = vsd_address - _config.save() - - @hooks.hook('upgrade-charm') @hooks.hook('config-changed') @restart_on_change(restart_map(), stopstart=True) diff --git a/unit_tests/test_neutron_api_hooks.py b/unit_tests/test_neutron_api_hooks.py index 8cd78052..120cf1dd 100644 --- a/unit_tests/test_neutron_api_hooks.py +++ b/unit_tests/test_neutron_api_hooks.py @@ -56,7 +56,6 @@ TO_PATCH = [ 'update_nrpe_config', 'service_reload', 'IdentityServiceContext', - 'save_vsd_address_to_config', 'update_config_file', ] NEUTRON_CONF_DIR = "/etc/neutron"