diff --git a/config.yaml b/config.yaml index c450253..7782791 100644 --- a/config.yaml +++ b/config.yaml @@ -25,7 +25,7 @@ options: type: string description: | Interfaces that will provide fabric connectivity on the director nodes. - Provided in form of json in a string. These interfaces have to be connected + Provided in form of json in a string. These interfaces have to be connected to the os-data-network specified in the config. Default value is MANAGEMENT which will configure the management interface as the fabric interface on each director. @@ -55,3 +55,7 @@ options: default: null type: string description: Provide the PLUMgrid ONS License key. + opsvm-ip: + default: 127.0.0.1 + type: string + description: IP address of the PLUMgrid Operations VM Management interface. diff --git a/hooks/pg_dir_context.py b/hooks/pg_dir_context.py old mode 100644 new mode 100755 index ce78d07..29c3b5d --- a/hooks/pg_dir_context.py +++ b/hooks/pg_dir_context.py @@ -104,5 +104,6 @@ class PGDirContext(context.NeutronContext): pg_ctxt['fabric_mode'] = 'host' virtual_ip_array = re.split('\.', conf['plumgrid-virtual-ip']) pg_ctxt['virtual_router_id'] = virtual_ip_array[3] + pg_ctxt['opsvm_ip'] = conf['opsvm-ip'] return pg_ctxt diff --git a/hooks/pg_dir_hooks.py b/hooks/pg_dir_hooks.py old mode 100644 new mode 100755 index 94b547c..5942896 --- a/hooks/pg_dir_hooks.py +++ b/hooks/pg_dir_hooks.py @@ -8,12 +8,15 @@ import sys import time from charmhelpers.core.host import service_running +from charmhelpers.contrib.network.ip import is_ip from charmhelpers.core.hookenv import ( Hooks, UnregisteredHookError, log, config, + relation_set, + relation_ids ) from charmhelpers.fetch import ( @@ -64,6 +67,21 @@ def dir_joined(): restart_pg() +@hooks.hook('plumgrid-relation-joined') +def plumgrid_joined(relation_id=None): + ''' + This hook is run when relation with edge or gateway is created. + ''' + opsvm_ip = config('opsvm-ip') + print is_ip(opsvm_ip) + if opsvm_ip == '127.0.0.1': + return 1 + elif not is_ip(opsvm_ip): + raise ValueError('Incorrect IP specified') + else: + relation_set(relation_id=relation_id, opsvm_ip=opsvm_ip) + + @hooks.hook('config-changed') def config_changed(): ''' @@ -96,6 +114,10 @@ def config_changed(): apt_install(pkg, options=['--force-yes'], fatal=True) remove_iovisor() load_iovisor() + if charm_config.changed('opsvm-ip'): + for rid in relation_ids('plumgrid'): + plumgrid_joined(rid) + stop_pg() ensure_mtu() CONFIGS.write_all() if not service_running('plumgrid'): diff --git a/hooks/pg_dir_utils.py b/hooks/pg_dir_utils.py old mode 100644 new mode 100755 index 697ecbf..c5f92d9 --- a/hooks/pg_dir_utils.py +++ b/hooks/pg_dir_utils.py @@ -50,6 +50,7 @@ PG_DEF_CONF = '%s/conf/pg/nginx.conf' % PG_LXC_DATA_PATH PG_HN_CONF = '%s/conf/etc/hostname' % PG_LXC_DATA_PATH PG_HS_CONF = '%s/conf/etc/hosts' % PG_LXC_DATA_PATH PG_IFCS_CONF = '%s/conf/pg/ifcs.conf' % PG_LXC_DATA_PATH +OPS_CONF = '%s/conf/etc/00-pg.conf' % PG_LXC_DATA_PATH AUTH_KEY_PATH = '%s/root/.ssh/authorized_keys' % PG_LXC_DATA_PATH TEMP_LICENSE_FILE = '/tmp/license' @@ -74,6 +75,10 @@ BASE_RESOURCE_MAP = OrderedDict([ 'services': ['plumgrid'], 'contexts': [pg_dir_context.PGDirContext()], }), + (OPS_CONF, { + 'services': ['plumgrid'], + 'contexts': [pg_dir_context.PGDirContext()], + }), (PG_IFCS_CONF, { 'services': [], 'contexts': [pg_dir_context.PGDirContext()], diff --git a/hooks/plumgrid-relation-joined b/hooks/plumgrid-relation-joined new file mode 120000 index 0000000..6530c5a --- /dev/null +++ b/hooks/plumgrid-relation-joined @@ -0,0 +1 @@ +pg_dir_hooks.py \ No newline at end of file diff --git a/templates/kilo/00-pg.conf b/templates/kilo/00-pg.conf new file mode 100644 index 0000000..c5a6016 --- /dev/null +++ b/templates/kilo/00-pg.conf @@ -0,0 +1 @@ +$template ls_json,"{{'{'}}{{'%'}}timestamp:::date-rfc3339,jsonf:@timestamp%,%source:::jsonf:@source_host%,%msg:::json%}":syslogtag,isequal,"pg:" @{{ opsvm_ip }}:6000;ls_json diff --git a/templates/kilo/nginx.conf b/templates/kilo/nginx.conf index 00f58f1..7f5c51b 100644 --- a/templates/kilo/nginx.conf +++ b/templates/kilo/nginx.conf @@ -13,7 +13,7 @@ upstream pgCli { } upstream pgMW { - server 127.0.0.1:4000; + server {{ opsvm_ip }}:4000; } map $http_upgrade $connection_upgrade {