diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py index 5e74500..976071e 100755 --- a/hooks/pg_gw_hooks.py +++ b/hooks/pg_gw_hooks.py @@ -12,6 +12,7 @@ from charmhelpers.core.hookenv import ( UnregisteredHookError, log, config, + relation_set, status_set ) @@ -74,6 +75,16 @@ def plumgrid_changed(): CONFIGS.write_all() +@hooks.hook('plumgrid-relation-joined') +def gateway_node_joined(relation_id=None): + ''' + This hook is run when relation between plumgrid-gateway and + plumgrid-director is made. + ''' + rel_data = {'gateway-peer': 'gateway-peer'} + relation_set(relation_id=relation_id, **rel_data) + + @hooks.hook('config-changed') @restart_on_stop() @restart_on_change(restart_map()) diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py index ad62133..d9b9894 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py @@ -21,6 +21,8 @@ from charmhelpers.core.hookenv import ( ) from charmhelpers.contrib.network.ip import ( get_iface_from_addr, + get_host_ip, + get_iface_addr, get_bridges, get_bridge_nics, ) @@ -97,9 +99,9 @@ def configure_analyst_opsvm(): ''' Configures Anaylyst for OPSVM ''' - opsvm_ip = pg_gw_context._pg_dir_context()['opsvm_ip'] if not service_running('plumgrid'): restart_pg() + opsvm_ip = pg_gw_context._pg_dir_context()['opsvm_ip'] NS_ENTER = ('/opt/local/bin/nsenter -t $(ps ho pid --ppid $(cat ' '/var/run/libvirt/lxc/plumgrid.pid)) -m -n -u -i -p ') sigmund_stop = NS_ENTER + '/usr/bin/service plumgrid-sigmund stop' @@ -115,6 +117,7 @@ def configure_analyst_opsvm(): log('plumgrid-sigmund couldn\'t be stopped!') return subprocess.check_call(sigmund_autoboot, shell=True) + status = subprocess.check_output(sigmund_status, shell=True) except: log('plumgrid-sigmund couldn\'t be started!') @@ -249,7 +252,13 @@ def get_mgmt_interface(): ''' mgmt_interface = config('mgmt-interface') if not mgmt_interface: - return get_iface_from_addr(unit_get('private-address')) + try: + return get_iface_from_addr(unit_get('private-address')) + except: + for bridge_interface in get_bridges(): + if (get_host_ip(unit_get('private-address')) + in get_iface_addr(bridge_interface)): + return bridge_interface elif interface_exists(mgmt_interface): return mgmt_interface else: diff --git a/hooks/plumgrid-relation-joined b/hooks/plumgrid-relation-joined new file mode 120000 index 0000000..3aec9ba --- /dev/null +++ b/hooks/plumgrid-relation-joined @@ -0,0 +1 @@ +pg_gw_hooks.py \ No newline at end of file