Addressed reviews by Charmers
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Copyright (c) 2015, PLUMgrid Inc, http://plumgrid.com
|
||||
|
||||
# The hooks of this charm have been symlinked to functions
|
||||
# in this file.
|
||||
|
||||
import sys
|
||||
|
||||
from charmhelpers.core.hookenv import (
|
||||
Hooks,
|
||||
UnregisteredHookError,
|
||||
config,
|
||||
log,
|
||||
relation_set,
|
||||
)
|
||||
|
||||
from charmhelpers.fetch import (
|
||||
apt_install,
|
||||
apt_purge,
|
||||
configure_sources,
|
||||
)
|
||||
|
||||
from pg_dir_utils import (
|
||||
@@ -15,6 +24,11 @@ from pg_dir_utils import (
|
||||
ensure_files,
|
||||
restart_pg,
|
||||
stop_pg,
|
||||
determine_packages,
|
||||
load_iovisor,
|
||||
remove_iovisor,
|
||||
ensure_mtu,
|
||||
add_lcm_key,
|
||||
)
|
||||
|
||||
hooks = Hooks()
|
||||
@@ -23,28 +37,61 @@ CONFIGS = register_configs()
|
||||
|
||||
@hooks.hook()
|
||||
def install():
|
||||
'''
|
||||
Install hook is run when the charm is first deployed on a node.
|
||||
'''
|
||||
configure_sources(update=True)
|
||||
pkgs = determine_packages()
|
||||
for pkg in pkgs:
|
||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||
load_iovisor()
|
||||
ensure_mtu()
|
||||
ensure_files()
|
||||
add_lcm_key()
|
||||
|
||||
|
||||
@hooks.hook('plumgrid-plugin-relation-joined')
|
||||
def plumgrid_dir():
|
||||
'''
|
||||
This hook is run when relation between neutron-api-plumgrid
|
||||
and plumgrid-director is made.
|
||||
'''
|
||||
ensure_mtu()
|
||||
ensure_files()
|
||||
add_lcm_key()
|
||||
CONFIGS.write_all()
|
||||
restart_pg()
|
||||
|
||||
|
||||
@hooks.hook('plumgrid-relation-joined')
|
||||
def plumgrid_joined(relation_id=None):
|
||||
#We can pass information to the edge and gateway from there.
|
||||
relation_data = {
|
||||
'pg_virtual_ip': config('plumgrid-virtual-ip'),
|
||||
}
|
||||
relation_set(relation_id=relation_id, **relation_data)
|
||||
@hooks.hook('config-changed')
|
||||
def config_changed():
|
||||
'''
|
||||
This hook is run when a config parameter is changed.
|
||||
It also runs on node reboot.
|
||||
'''
|
||||
stop_pg()
|
||||
configure_sources(update=True)
|
||||
pkgs = determine_packages()
|
||||
for pkg in pkgs:
|
||||
apt_install(pkg, options=['--force-yes'], fatal=True)
|
||||
load_iovisor()
|
||||
ensure_mtu()
|
||||
ensure_files()
|
||||
add_lcm_key()
|
||||
CONFIGS.write_all()
|
||||
restart_pg()
|
||||
|
||||
|
||||
@hooks.hook('stop')
|
||||
def stop():
|
||||
'''
|
||||
This hook is run when the charm is destroyed.
|
||||
'''
|
||||
stop_pg()
|
||||
remove_iovisor()
|
||||
pkgs = determine_packages()
|
||||
for pkg in pkgs:
|
||||
apt_purge(pkg, fatal=False)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user