2014-06-05 11:59:00 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2014-06-27 13:19:01 +01:00
|
|
|
from subprocess import check_call
|
2014-06-05 11:59:00 +01:00
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
Hooks,
|
|
|
|
UnregisteredHookError,
|
|
|
|
config,
|
|
|
|
is_relation_made,
|
|
|
|
log,
|
|
|
|
ERROR,
|
|
|
|
relation_get,
|
|
|
|
relation_ids,
|
|
|
|
relation_set,
|
|
|
|
open_port,
|
|
|
|
unit_get,
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.core.host import (
|
|
|
|
restart_on_change
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.fetch import (
|
|
|
|
apt_install, apt_update
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.utils import (
|
|
|
|
configure_installation_source,
|
|
|
|
openstack_upgrade_available,
|
|
|
|
)
|
|
|
|
from charmhelpers.contrib.openstack.neutron import (
|
2014-06-17 16:52:42 +01:00
|
|
|
neutron_plugin_attribute,
|
2014-06-05 11:59:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from neutron_api_utils import (
|
|
|
|
determine_packages,
|
|
|
|
determine_ports,
|
|
|
|
register_configs,
|
|
|
|
restart_map,
|
|
|
|
NEUTRON_CONF,
|
|
|
|
api_port,
|
2014-06-17 08:44:46 +00:00
|
|
|
CLUSTER_RES,
|
2014-06-20 11:02:09 +01:00
|
|
|
do_openstack_upgrade,
|
2014-06-05 11:59:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.hahelpers.cluster import (
|
2014-06-17 08:44:46 +00:00
|
|
|
get_hacluster_config,
|
|
|
|
is_leader,
|
2014-06-05 11:59:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.payload.execd import execd_preinstall
|
2014-07-04 12:51:35 +01:00
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.ip import (
|
|
|
|
canonical_url,
|
|
|
|
PUBLIC, INTERNAL, ADMIN
|
|
|
|
)
|
2014-06-05 11:59:00 +01:00
|
|
|
|
2014-07-16 14:15:57 +01:00
|
|
|
from charmhelpers.contrib.network.ip import (
|
|
|
|
get_iface_for_address,
|
|
|
|
get_netmask_for_address
|
|
|
|
)
|
|
|
|
|
2014-06-05 11:59:00 +01:00
|
|
|
hooks = Hooks()
|
|
|
|
CONFIGS = register_configs()
|
|
|
|
|
|
|
|
|
2014-06-27 13:19:01 +01:00
|
|
|
def configure_https():
|
|
|
|
'''
|
|
|
|
Enables SSL API Apache config if appropriate and kicks identity-service
|
|
|
|
with any required api updates.
|
|
|
|
'''
|
|
|
|
# need to write all to ensure changes to the entire request pipeline
|
|
|
|
# propagate (c-api, haprxy, apache)
|
|
|
|
CONFIGS.write_all()
|
|
|
|
if 'https' in CONFIGS.complete_contexts():
|
|
|
|
cmd = ['a2ensite', 'openstack_https_frontend']
|
|
|
|
check_call(cmd)
|
|
|
|
else:
|
|
|
|
cmd = ['a2dissite', 'openstack_https_frontend']
|
|
|
|
check_call(cmd)
|
|
|
|
|
|
|
|
for rid in relation_ids('identity-service'):
|
|
|
|
identity_joined(rid=rid)
|
|
|
|
|
|
|
|
|
2014-06-05 11:59:00 +01:00
|
|
|
@hooks.hook()
|
|
|
|
def install():
|
|
|
|
execd_preinstall()
|
|
|
|
configure_installation_source(config('openstack-origin'))
|
|
|
|
apt_update()
|
|
|
|
apt_install(determine_packages(), fatal=True)
|
|
|
|
[open_port(port) for port in determine_ports()]
|
|
|
|
|
|
|
|
|
2014-06-18 11:36:43 +01:00
|
|
|
@hooks.hook('upgrade-charm')
|
2014-06-05 11:59:00 +01:00
|
|
|
@hooks.hook('config-changed')
|
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
|
|
|
def config_changed():
|
|
|
|
global CONFIGS
|
2014-06-20 11:02:09 +01:00
|
|
|
if openstack_upgrade_available('neutron-server'):
|
2014-06-23 12:18:17 +01:00
|
|
|
do_openstack_upgrade(CONFIGS)
|
2014-06-27 13:19:01 +01:00
|
|
|
configure_https()
|
2014-06-05 11:59:00 +01:00
|
|
|
CONFIGS.write_all()
|
2014-06-17 08:44:46 +00:00
|
|
|
for r_id in relation_ids('neutron-api'):
|
|
|
|
neutron_api_relation_joined(rid=r_id)
|
2014-06-17 16:23:57 +01:00
|
|
|
for r_id in relation_ids('neutron-plugin-api'):
|
|
|
|
neutron_plugin_api_relation_joined(rid=r_id)
|
2014-06-18 11:36:43 +01:00
|
|
|
for r_id in relation_ids('amqp'):
|
|
|
|
amqp_joined(relation_id=r_id)
|
|
|
|
for r_id in relation_ids('identity-service'):
|
|
|
|
identity_joined(rid=r_id)
|
2014-06-05 11:59:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-joined')
|
|
|
|
def amqp_joined(relation_id=None):
|
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
username=config('rabbit-user'), vhost=config('rabbit-vhost'))
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-changed')
|
|
|
|
@hooks.hook('amqp-relation-departed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def amqp_changed():
|
|
|
|
if 'amqp' not in CONFIGS.complete_contexts():
|
|
|
|
log('amqp relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write(NEUTRON_CONF)
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('shared-db-relation-joined')
|
|
|
|
def db_joined():
|
2014-06-18 11:36:43 +01:00
|
|
|
if is_relation_made('pgsql-db'):
|
2014-06-05 11:59:00 +01:00
|
|
|
# error, postgresql is used
|
|
|
|
e = ('Attempting to associate a mysql database when there is already '
|
|
|
|
'associated a postgresql one')
|
|
|
|
log(e, level=ERROR)
|
|
|
|
raise Exception(e)
|
|
|
|
|
2014-06-17 14:57:40 +01:00
|
|
|
relation_set(database=config('database'),
|
|
|
|
username=config('database-user'),
|
|
|
|
hostname=unit_get('private-address'))
|
2014-06-05 11:59:00 +01:00
|
|
|
|
|
|
|
|
2014-06-17 10:22:20 +01:00
|
|
|
@hooks.hook('pgsql-db-relation-joined')
|
2014-06-05 11:59:00 +01:00
|
|
|
def pgsql_neutron_db_joined():
|
|
|
|
if is_relation_made('shared-db'):
|
|
|
|
# raise error
|
|
|
|
e = ('Attempting to associate a postgresql database'
|
|
|
|
' when there is already associated a mysql one')
|
|
|
|
log(e, level=ERROR)
|
|
|
|
raise Exception(e)
|
|
|
|
|
2014-06-17 09:43:30 +01:00
|
|
|
relation_set(database=config('database'))
|
2014-06-05 11:59:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('shared-db-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def db_changed():
|
|
|
|
if 'shared-db' not in CONFIGS.complete_contexts():
|
|
|
|
log('shared-db relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
2014-06-17 16:52:42 +01:00
|
|
|
|
2014-06-17 10:22:20 +01:00
|
|
|
@hooks.hook('pgsql-db-relation-changed')
|
2014-06-05 11:59:00 +01:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def postgresql_neutron_db_changed():
|
2014-06-23 12:18:17 +01:00
|
|
|
plugin = config('neutron-plugin')
|
|
|
|
# DB config might have been moved to main neutron.conf in H?
|
|
|
|
CONFIGS.write(neutron_plugin_attribute(plugin, 'config'))
|
2014-06-05 11:59:00 +01:00
|
|
|
|
2014-06-17 16:52:42 +01:00
|
|
|
|
2014-06-05 11:59:00 +01:00
|
|
|
@hooks.hook('amqp-relation-broken',
|
|
|
|
'identity-service-relation-broken',
|
|
|
|
'shared-db-relation-broken',
|
2014-06-17 10:22:20 +01:00
|
|
|
'pgsql-db-relation-broken')
|
2014-06-05 11:59:00 +01:00
|
|
|
def relation_broken():
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
2014-06-17 16:52:42 +01:00
|
|
|
|
2014-06-05 11:59:00 +01:00
|
|
|
@hooks.hook('identity-service-relation-joined')
|
|
|
|
def identity_joined(rid=None):
|
2014-07-04 12:51:35 +01:00
|
|
|
public_url = '{}:{}'.format(canonical_url(CONFIGS, PUBLIC),
|
2014-06-27 12:55:45 +01:00
|
|
|
api_port('neutron-server'))
|
2014-07-04 12:51:35 +01:00
|
|
|
admin_url = '{}:{}'.format(canonical_url(CONFIGS, ADMIN),
|
2014-06-27 12:55:45 +01:00
|
|
|
api_port('neutron-server'))
|
2014-07-04 12:51:35 +01:00
|
|
|
internal_url = '{}:{}'.format(canonical_url(CONFIGS, INTERNAL),
|
|
|
|
api_port('neutron-server')
|
2014-06-27 13:57:36 +01:00
|
|
|
)
|
2014-06-27 12:55:45 +01:00
|
|
|
endpoints = {
|
|
|
|
'quantum_service': 'quantum',
|
|
|
|
'quantum_region': config('region'),
|
|
|
|
'quantum_public_url': public_url,
|
|
|
|
'quantum_admin_url': admin_url,
|
|
|
|
'quantum_internal_url': internal_url,
|
|
|
|
}
|
|
|
|
relation_set(relation_id=rid, relation_settings=endpoints)
|
2014-06-05 11:59:00 +01:00
|
|
|
|
2014-06-17 16:52:42 +01:00
|
|
|
|
2014-06-05 11:59:00 +01:00
|
|
|
@hooks.hook('identity-service-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def identity_changed():
|
|
|
|
if 'identity-service' not in CONFIGS.complete_contexts():
|
|
|
|
log('identity-service relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write(NEUTRON_CONF)
|
|
|
|
for r_id in relation_ids('neutron-api'):
|
|
|
|
neutron_api_relation_joined(rid=r_id)
|
2014-06-27 13:19:01 +01:00
|
|
|
configure_https()
|
2014-06-17 16:52:42 +01:00
|
|
|
|
|
|
|
|
2014-06-05 11:59:00 +01:00
|
|
|
@hooks.hook('neutron-api-relation-joined')
|
|
|
|
def neutron_api_relation_joined(rid=None):
|
2014-07-04 12:51:35 +01:00
|
|
|
base_url = canonical_url(CONFIGS, INTERNAL)
|
2014-06-05 11:59:00 +01:00
|
|
|
neutron_url = '%s:%s' % (base_url, api_port('neutron-server'))
|
|
|
|
relation_data = {
|
2014-06-23 12:18:17 +01:00
|
|
|
'neutron-url': neutron_url,
|
|
|
|
'neutron-plugin': config('neutron-plugin'),
|
2014-06-05 11:59:00 +01:00
|
|
|
}
|
2014-06-17 09:52:15 +01:00
|
|
|
if config('neutron-security-groups'):
|
2014-06-23 12:18:17 +01:00
|
|
|
relation_data['neutron-security-groups'] = "yes"
|
2014-06-17 09:52:15 +01:00
|
|
|
else:
|
2014-06-23 12:18:17 +01:00
|
|
|
relation_data['neutron-security-groups'] = "no"
|
2014-06-05 11:59:00 +01:00
|
|
|
relation_set(relation_id=rid, **relation_data)
|
2014-06-17 16:52:42 +01:00
|
|
|
# Nova-cc may have grabbed the quantum endpoint so kick identity-service
|
2014-06-23 12:18:17 +01:00
|
|
|
# relation to register that its here
|
2014-06-05 11:59:00 +01:00
|
|
|
for r_id in relation_ids('identity-service'):
|
|
|
|
identity_joined(rid=r_id)
|
|
|
|
|
2014-06-17 16:52:42 +01:00
|
|
|
|
2014-06-05 11:59:00 +01:00
|
|
|
@hooks.hook('neutron-api-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def neutron_api_relation_changed():
|
2014-06-11 09:10:54 +00:00
|
|
|
CONFIGS.write(NEUTRON_CONF)
|
2014-06-09 17:11:19 +00:00
|
|
|
|
2014-06-17 16:52:42 +01:00
|
|
|
|
2014-06-17 16:07:02 +01:00
|
|
|
@hooks.hook('neutron-plugin-api-relation-joined')
|
|
|
|
def neutron_plugin_api_relation_joined(rid=None):
|
|
|
|
relation_data = {
|
2014-06-23 12:18:17 +01:00
|
|
|
'neutron-security-groups': config('neutron-security-groups')
|
2014-06-17 16:07:02 +01:00
|
|
|
}
|
|
|
|
relation_set(relation_id=rid, **relation_data)
|
|
|
|
|
2014-06-17 16:52:42 +01:00
|
|
|
|
2014-06-17 08:44:46 +00:00
|
|
|
@hooks.hook('cluster-relation-changed',
|
|
|
|
'cluster-relation-departed')
|
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
|
|
|
def cluster_changed():
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('ha-relation-joined')
|
|
|
|
def ha_joined():
|
|
|
|
config = get_hacluster_config()
|
|
|
|
resources = {
|
|
|
|
'res_neutron_haproxy': 'lsb:haproxy',
|
|
|
|
}
|
|
|
|
resource_params = {
|
|
|
|
'res_neutron_haproxy': 'op monitor interval="5s"'
|
2014-07-16 14:15:57 +01:00
|
|
|
}
|
|
|
|
vip_group = []
|
|
|
|
for vip in config['vip'].split():
|
|
|
|
iface = get_iface_for_address(vip)
|
|
|
|
if iface is not None:
|
|
|
|
vip_key = 'res_neutron_{}_vip'.format(iface)
|
|
|
|
resources[vip_key] = 'ocf:heartbeat:IPaddr2'
|
|
|
|
resource_params[vip_key] = (
|
|
|
|
'params ip="{vip}" cidr_netmask="{netmask}"'
|
|
|
|
' nic="{iface}"'.format(vip=vip,
|
|
|
|
iface=iface,
|
|
|
|
netmask=get_netmask_for_address(vip))
|
|
|
|
)
|
|
|
|
vip_group.append(vip_key)
|
|
|
|
|
|
|
|
if len(vip_group) > 1:
|
|
|
|
relation_set(groups={'grp_neutron_vips': ' '.join(vip_group)})
|
|
|
|
|
2014-06-17 08:44:46 +00:00
|
|
|
init_services = {
|
|
|
|
'res_neutron_haproxy': 'haproxy'
|
|
|
|
}
|
|
|
|
clones = {
|
|
|
|
'cl_nova_haproxy': 'res_neutron_haproxy'
|
|
|
|
}
|
|
|
|
relation_set(init_services=init_services,
|
|
|
|
corosync_bindiface=config['ha-bindiface'],
|
|
|
|
corosync_mcastport=config['ha-mcastport'],
|
|
|
|
resources=resources,
|
|
|
|
resource_params=resource_params,
|
|
|
|
clones=clones)
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('ha-relation-changed')
|
|
|
|
def ha_changed():
|
|
|
|
clustered = relation_get('clustered')
|
|
|
|
if not clustered or clustered in [None, 'None', '']:
|
2014-06-19 11:02:49 +01:00
|
|
|
log('ha_changed: hacluster subordinate not fully clustered.:'
|
|
|
|
+ str(clustered))
|
2014-06-17 08:44:46 +00:00
|
|
|
return
|
|
|
|
if not is_leader(CLUSTER_RES):
|
|
|
|
log('ha_changed: hacluster complete but we are not leader.')
|
|
|
|
return
|
|
|
|
log('Cluster configured, notifying other services and updating '
|
|
|
|
'keystone endpoint configuration')
|
|
|
|
for rid in relation_ids('identity-service'):
|
|
|
|
identity_joined(rid=rid)
|
|
|
|
for rid in relation_ids('neutron-api'):
|
|
|
|
neutron_api_relation_joined(rid=rid)
|
|
|
|
|
2014-06-17 16:52:42 +01:00
|
|
|
|
2014-06-05 11:59:00 +01:00
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
hooks.execute(sys.argv)
|
|
|
|
except UnregisteredHookError as e:
|
|
|
|
log('Unknown hook {} - skipping.'.format(e))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|