137 lines
3.2 KiB
Python
Raw Normal View History

2014-06-05 11:59:23 +01:00
#!/usr/bin/python
2014-06-05 11:59:23 +01:00
import sys
from charmhelpers.contrib.openstack.utils import (
config_value_changed,
git_install_requested,
)
2014-06-05 11:59:23 +01:00
from charmhelpers.core.hookenv import (
Hooks,
UnregisteredHookError,
config,
2014-06-05 11:59:23 +01:00
log,
relation_set,
2014-09-09 13:09:30 +00:00
relation_ids,
2014-06-05 11:59:23 +01:00
)
from charmhelpers.core.host import (
restart_on_change
)
from charmhelpers.fetch import (
2015-09-08 15:12:14 +01:00
apt_purge,
2014-06-05 11:59:23 +01:00
)
from charmhelpers.contrib.openstack.utils import (
os_requires_version,
2014-06-05 11:59:23 +01:00
)
from neutron_ovs_utils import (
2015-03-02 14:56:11 +00:00
DVR_PACKAGES,
2015-02-02 15:28:26 +00:00
configure_ovs,
2015-03-08 10:52:40 +00:00
git_install,
2014-09-09 13:09:30 +00:00
get_topics,
get_shared_secret,
2014-06-05 11:59:23 +01:00
register_configs,
restart_map,
2015-03-02 14:56:11 +00:00
use_dvr,
2015-09-08 15:12:14 +01:00
enable_nova_metadata,
enable_local_dhcp,
install_packages,
2014-06-05 11:59:23 +01:00
)
hooks = Hooks()
CONFIGS = register_configs()
@hooks.hook()
def install():
2015-09-08 15:12:14 +01:00
install_packages()
2015-03-08 10:52:40 +00:00
git_install(config('openstack-origin-git'))
2014-06-19 10:56:25 +01:00
2014-06-17 15:31:03 +01:00
@hooks.hook('neutron-plugin-relation-changed')
@hooks.hook('config-changed')
2014-06-10 17:56:10 +00:00
@restart_on_change(restart_map())
2014-06-17 15:31:03 +01:00
def config_changed():
2015-09-08 15:12:14 +01:00
install_packages()
2015-04-02 20:35:37 +00:00
if git_install_requested():
if config_value_changed('openstack-origin-git'):
git_install(config('openstack-origin-git'))
2015-02-03 14:17:30 +00:00
configure_ovs()
2014-06-05 11:59:23 +01:00
CONFIGS.write_all()
2014-09-09 13:09:30 +00:00
for rid in relation_ids('zeromq-configuration'):
zeromq_configuration_relation_joined(rid)
2015-09-08 13:17:28 +01:00
for rid in relation_ids('neutron-plugin'):
neutron_plugin_joined(relation_id=rid)
2014-06-19 10:56:25 +01:00
@hooks.hook('neutron-plugin-api-relation-changed')
@restart_on_change(restart_map())
def neutron_plugin_api_changed():
2015-03-02 14:56:11 +00:00
if use_dvr():
2015-09-08 15:12:14 +01:00
install_packages()
2015-03-02 14:56:11 +00:00
else:
apt_purge(DVR_PACKAGES, fatal=True)
configure_ovs()
2014-06-05 11:59:23 +01:00
CONFIGS.write_all()
# If dvr setting has changed, need to pass that on
for rid in relation_ids('neutron-plugin'):
neutron_plugin_joined(relation_id=rid)
2015-02-25 13:50:38 +00:00
@hooks.hook('neutron-plugin-relation-joined')
def neutron_plugin_joined(relation_id=None):
2015-09-08 15:12:14 +01:00
if enable_local_dhcp():
install_packages()
secret = get_shared_secret() if enable_nova_metadata() else None
rel_data = {
2015-03-02 14:56:11 +00:00
'metadata-shared-secret': secret,
}
relation_set(relation_id=relation_id, **rel_data)
2014-06-19 10:56:25 +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_all()
2014-06-05 11:59:23 +01:00
2014-06-19 10:56:25 +01:00
2014-09-09 13:09:30 +00:00
@hooks.hook('zeromq-configuration-relation-joined')
2015-03-16 16:15:06 +00:00
@os_requires_version('kilo', 'neutron-common')
2014-09-09 13:09:30 +00:00
def zeromq_configuration_relation_joined(relid=None):
relation_set(relation_id=relid,
topics=" ".join(get_topics()),
2014-09-10 10:12:06 +00:00
users="neutron")
2014-09-09 13:09:30 +00:00
@hooks.hook('zeromq-configuration-relation-changed')
@restart_on_change(restart_map(), stopstart=True)
def zeromq_configuration_relation_changed():
CONFIGS.write_all()
2014-06-05 11:59:23 +01:00
def main():
try:
hooks.execute(sys.argv)
except UnregisteredHookError as e:
log('Unknown hook {} - skipping.'.format(e))
if __name__ == '__main__':
main()