From 46ecc13154f3af9743a07ff06f130bf873f2a2a3 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 8 May 2014 19:36:17 +0000 Subject: [PATCH] Add neutron-api relation contexts --- hooks/nova_cc_context.py | 11 +++++- hooks/nova_cc_hooks.py | 5 +++ hooks/nova_cc_utils.py | 74 +++++++++++++++++++++++----------------- metadata.yaml | 2 ++ 4 files changed, 60 insertions(+), 32 deletions(-) diff --git a/hooks/nova_cc_context.py b/hooks/nova_cc_context.py index de2be227..35a52e42 100644 --- a/hooks/nova_cc_context.py +++ b/hooks/nova_cc_context.py @@ -31,7 +31,7 @@ class NovaCellContext(context.OSContextGenerator): interfaces = ['nova-cell'] def __call__(self): - log('Generating template context for identity-service') + log('Generating template context for cell') ctxt = {} for rid in relation_ids('nova-cell'): for unit in related_units(rid): @@ -44,6 +44,14 @@ class NovaCellContext(context.OSContextGenerator): return ctxt return {} +class NeutronAPIContext(context.OSContextGenerator): + def __call__(self): + log('Generating template context for neutron plugin') + ctxt = {} + for rid in relation_ids('neutron-api'): + for unit in related_units(rid): + ctxt = relation_get(rid=rid, unit=unit) + return ctxt class VolumeServiceContext(context.OSContextGenerator): interfaces = [] @@ -222,3 +230,4 @@ class NeutronPostgresqlDBContext(context.PostgresqlDBContext): def __init__(self): super(NeutronPostgresqlDBContext, self).__init__(config('neutron-database')) + diff --git a/hooks/nova_cc_hooks.py b/hooks/nova_cc_hooks.py index 12eeff4e..a571d223 100755 --- a/hooks/nova_cc_hooks.py +++ b/hooks/nova_cc_hooks.py @@ -536,6 +536,11 @@ def nova_cell_relation_changed(): relation_set(dbready=False) CONFIGS.write(NOVA_CONF) +@hooks.hook('neutron-api-relation-changed') +def neutron_api_relation_changed(): + print "In neutron-api-relation-changed" + CONFIGS.write(NOVA_CONF) + def main(): try: diff --git a/hooks/nova_cc_utils.py b/hooks/nova_cc_utils.py index 9a2dd862..8c1bb2fe 100644 --- a/hooks/nova_cc_utils.py +++ b/hooks/nova_cc_utils.py @@ -33,6 +33,7 @@ from charmhelpers.core.hookenv import ( relation_get, relation_ids, remote_unit, + is_relation_made, INFO, ERROR, ) @@ -96,7 +97,6 @@ BASE_RESOURCE_MAP = OrderedDict([ 'contexts': [context.AMQPContext(ssl_dir=NOVA_CONF_DIR), context.SharedDBContext( relation_prefix='nova', ssl_dir=NOVA_CONF_DIR), - nova_cc_context.NovaPostgresqlDBContext(), context.ImageServiceContext(), context.OSConfigFlagContext(), context.SubordinateConfigContext( @@ -113,7 +113,6 @@ BASE_RESOURCE_MAP = OrderedDict([ nova_cc_context.HAProxyContext(), nova_cc_context.IdentityServiceContext(), nova_cc_context.VolumeServiceContext(), - nova_cc_context.NeutronCCContext(), nova_cc_context.NovaCellContext()], }), (NOVA_API_PASTE, { @@ -195,40 +194,53 @@ def resource_map(): net_manager = network_manager() - # pop out irrelevant resources from the OrderedDict (easier than adding - # them late) - if net_manager != 'quantum': - [resource_map.pop(k) for k in list(resource_map.iterkeys()) - if 'quantum' in k] - if net_manager != 'neutron': - [resource_map.pop(k) for k in list(resource_map.iterkeys()) - if 'neutron' in k] - if os.path.exists('/etc/apache2/conf-available'): resource_map.pop(APACHE_CONF) else: resource_map.pop(APACHE_24_CONF) - # add neutron plugin requirements. nova-c-c only needs the neutron-server - # associated with configs, not the plugin agent. - if net_manager in ['quantum', 'neutron']: - plugin = neutron_plugin() - if plugin: - conf = neutron_plugin_attribute(plugin, 'config', net_manager) - ctxts = (neutron_plugin_attribute(plugin, 'contexts', net_manager) - or []) - services = neutron_plugin_attribute(plugin, 'server_services', - net_manager) - resource_map[conf] = {} - resource_map[conf]['services'] = services - resource_map[conf]['contexts'] = ctxts - resource_map[conf]['contexts'].append( - nova_cc_context.NeutronCCContext()) - - # update for postgres - resource_map[conf]['contexts'].append( - nova_cc_context.NeutronPostgresqlDBContext()) - + if is_relation_made('neutron-api'): + resource_map.pop(QUANTUM_CONF) + resource_map.pop(QUANTUM_DEFAULT) + resource_map.pop(NEUTRON_CONF) + resource_map.pop(NEUTRON_DEFAULT) + resource_map[NOVA_CONF]['contexts'].append( + nova_cc_context.NeutronAPIContext()) + else: + resource_map[NOVA_CONF]['contexts'].append( + nova_cc_context.NeutronCCContext()) + resource_map[NOVA_CONF]['contexts'].append( + nova_cc_context.NeutronPostgresqlDBContext()) + # pop out irrelevant resources from the OrderedDict (easier than adding + # them late) + if net_manager != 'quantum': + [resource_map.pop(k) for k in list(resource_map.iterkeys()) + if 'quantum' in k] + if net_manager != 'neutron': + [resource_map.pop(k) for k in list(resource_map.iterkeys()) + if 'neutron' in k] + + + # add neutron plugin requirements. nova-c-c only needs the neutron-server + # associated with configs, not the plugin agent. + if net_manager in ['quantum', 'neutron']: + plugin = neutron_plugin() + if plugin: + conf = neutron_plugin_attribute(plugin, 'config', net_manager) + ctxts = (neutron_plugin_attribute(plugin, 'contexts', net_manager) + or []) + services = neutron_plugin_attribute(plugin, 'server_services', + net_manager) + resource_map[conf] = {} + resource_map[conf]['services'] = services + resource_map[conf]['contexts'] = ctxts + resource_map[conf]['contexts'].append( + nova_cc_context.NeutronCCContext()) + + # update for postgres + resource_map[conf]['contexts'].append( + nova_cc_context.NeutronPostgresqlDBContext()) + # nova-conductor for releases >= G. if os_release('nova-common') not in ['essex', 'folsom']: resource_map['/etc/nova/nova.conf']['services'] += ['nova-conductor'] diff --git a/metadata.yaml b/metadata.yaml index 3cc8b7f6..d0a1ce0d 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -32,6 +32,8 @@ requires: interface: quantum nova-cell: interface: nova-cell + neutron-api: + interface: neutron-api ha: interface: hacluster scope: container