72 lines
1.4 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.core.hookenv import (
Hooks,
UnregisteredHookError,
config,
2014-06-05 11:59:23 +01:00
log,
relation_set,
)
from charmhelpers.core.host import (
restart_on_change
)
from charmhelpers.fetch import (
apt_install, apt_update
)
from neutron_ovs_utils import (
determine_packages,
register_configs,
restart_map,
NEUTRON_CONF,
2014-06-05 11:59:23 +01:00
)
hooks = Hooks()
CONFIGS = register_configs()
@hooks.hook()
def install():
apt_update()
apt_install(determine_packages(), fatal=True)
2014-06-10 17:56:10 +00:00
@restart_on_change(restart_map())
@hooks.hook('config-changed')
2014-06-05 11:59:23 +01:00
def config_changed():
CONFIGS.write_all()
2014-06-10 17:56:10 +00:00
@restart_on_change(restart_map())
@hooks.hook('neutron-plugin-relation-changed')
def neutron_plugin_relation_changed():
2014-06-05 11:59:23 +01:00
CONFIGS.write_all()
@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)
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()