Add support for joining charm to standalone neutron-api service

This commit is contained in:
Liam Young 2014-05-15 08:25:56 +01:00
commit 0b55e92ead
8 changed files with 86 additions and 36 deletions

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -1,7 +1,7 @@
from charmhelpers.core.hookenv import (
config, relation_ids, relation_set, log, ERROR,
unit_get)
unit_get, related_units, relation_get)
from charmhelpers.fetch import apt_install, filter_installed_packages
from charmhelpers.contrib.openstack import context, neutron, utils
@ -27,6 +27,15 @@ class ApacheSSLContext(context.ApacheSSLContext):
return super(ApacheSSLContext, self).__call__()
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 = []

View File

@ -19,12 +19,16 @@ from charmhelpers.core.hookenv import (
relation_get,
relation_ids,
relation_set,
related_units,
open_port,
unit_get,
)
from charmhelpers.core.host import (
restart_on_change
restart_on_change,
service_running,
service_stop,
service_start,
)
from charmhelpers.fetch import (
@ -500,6 +504,25 @@ def upgrade_charm():
identity_joined(rid=r_id)
@hooks.hook('neutron-api-relation-joined')
def neutron_api_relation_joined():
with open('/etc/init/neutron-server.override', 'wb') as out:
out.write('manual\n')
if service_running('neutron-server'):
service_stop('neutron-server')
@hooks.hook('neutron-api-relation-changed')
def neutron_api_relation_changed():
CONFIGS.write(NOVA_CONF)
@hooks.hook('neutron-api-relation-broken')
def neutron_api_relation_broken():
CONFIGS.write_all()
if os.path.isfile('/etc/init/neutron-server.override'):
os.remove('/etc/init/neutron-server.override')
if not service_running('neutron-server'):
service_start('neutron-server')
def main():
try:
hooks.execute(sys.argv)

View File

@ -33,12 +33,13 @@ from charmhelpers.core.hookenv import (
relation_get,
relation_ids,
remote_unit,
is_relation_made,
INFO,
ERROR,
)
from charmhelpers.core.host import (
service_start
service_start,
)
@ -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(
@ -107,8 +107,7 @@ BASE_RESOURCE_MAP = OrderedDict([
context.SyslogContext(),
nova_cc_context.HAProxyContext(),
nova_cc_context.IdentityServiceContext(),
nova_cc_context.VolumeServiceContext(),
nova_cc_context.NeutronCCContext()],
nova_cc_context.VolumeServiceContext()],
}),
(NOVA_API_PASTE, {
'services': [s for s in BASE_SERVICES if 'api' in s],
@ -189,40 +188,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']
@ -236,6 +248,7 @@ def resource_map():
for s in vmware_ctxt['services']:
if s not in resource_map[NOVA_CONF]['services']:
resource_map[NOVA_CONF]['services'].append(s)
return resource_map

View File

@ -30,6 +30,8 @@ requires:
interface: nova-volume
quantum-network-service:
interface: quantum
neutron-api:
interface: neutron-api
ha:
interface: hacluster
scope: container

View File

@ -1 +1 @@
315
500