2014-06-05 11:59:23 +01:00
|
|
|
#!/usr/bin/python
|
2014-06-10 12:50:03 +00:00
|
|
|
import uuid
|
2014-06-05 11:59:23 +01:00
|
|
|
import sys
|
2014-06-09 10:37:59 +00:00
|
|
|
import json
|
2014-06-05 11:59:23 +01:00
|
|
|
|
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
Hooks,
|
|
|
|
UnregisteredHookError,
|
|
|
|
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,
|
2014-06-09 10:37:59 +00:00
|
|
|
NEUTRON_SETTINGS,
|
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-07 05:02:19 +00:00
|
|
|
@restart_on_change(restart_map())
|
2014-06-05 11:59:23 +01:00
|
|
|
@hooks.hook('config-changed')
|
|
|
|
def config_changed():
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
2014-06-09 10:37:59 +00:00
|
|
|
@hooks.hook('neutron-plugin-relation-joined')
|
2014-06-10 12:50:03 +00:00
|
|
|
def neutron_plugin_relation_joined(remote_restart=True):
|
|
|
|
if remote_restart:
|
|
|
|
comment = ('restart', 'Restart Trigger: ' + str(uuid.uuid4()))
|
|
|
|
for conf in NEUTRON_SETTINGS['neutron']:
|
|
|
|
if 'sections' in NEUTRON_SETTINGS['neutron'][conf] and \
|
|
|
|
'COMMENT' in NEUTRON_SETTINGS['neutron'][conf]['sections']:
|
|
|
|
NEUTRON_SETTINGS['neutron'][conf]['sections']['COMMENT'].append(comment)
|
2014-06-10 10:28:12 +00:00
|
|
|
relation_set(subordinate_configuration=json.dumps(NEUTRON_SETTINGS))
|
2014-06-09 10:37:59 +00:00
|
|
|
|
2014-06-07 05:02:19 +00:00
|
|
|
@restart_on_change(restart_map())
|
2014-06-05 11:59:23 +01:00
|
|
|
@hooks.hook('neutron-plugin-relation-changed')
|
|
|
|
def neutron_plugin_relation_changed():
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
hooks.execute(sys.argv)
|
|
|
|
except UnregisteredHookError as e:
|
|
|
|
log('Unknown hook {} - skipping.'.format(e))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|