From 88abf130b7b2ff0a9be6d327e2bb9c407d0b693e Mon Sep 17 00:00:00 2001 From: Hassaan Pasha Date: Mon, 10 Aug 2015 14:57:25 +0500 Subject: [PATCH] Added HA coverage --- hooks/pg_gw_context.py | 26 +++++++++++++++----------- hooks/pg_gw_utils.py | 29 +++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/hooks/pg_gw_context.py b/hooks/pg_gw_context.py index 3208c28..671fdb6 100644 --- a/hooks/pg_gw_context.py +++ b/hooks/pg_gw_context.py @@ -17,17 +17,12 @@ def _pg_dir_settings(): ''' Inspects relation with PLUMgrid director. ''' - pg_settings = { - 'pg_dir_ip': '192.168.100.201', - } + director_ips=[] for rid in relation_ids('plumgrid'): for unit in related_units(rid): rdata = relation_get(rid=rid, unit=unit) - pg_settings = { - 'pg_dir_ip': rdata['private-address'], - } - return pg_settings - + director_ips.append(str(rdata['private-address'])) + return director_ips class PGGwContext(context.NeutronContext): @@ -63,12 +58,21 @@ class PGGwContext(context.NeutronContext): return {} conf = config() + pg_dir_ips = '' pg_dir_settings = _pg_dir_settings() - pg_ctxt['local_ip'] = pg_dir_settings['pg_dir_ip'] - + single_ip = True + for ip in pg_dir_settings: + if single_ip: + pg_dir_ips=str(ip) + single_ip = False + else: + pg_dir_ips= pg_dir_ips + ',' + str(ip) + pg_ctxt['local_ip'] = pg_dir_ips unit_hostname = get_unit_hostname() pg_ctxt['pg_hostname'] = unit_hostname - pg_ctxt['interface'] = "juju-br0" + from pg_gw_utils import check_interface_type + interface_type = check_interface_type() + pg_ctxt['interface'] = interface_type pg_ctxt['label'] = unit_hostname pg_ctxt['fabric_mode'] = 'host' diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py index bdf6523..8f0e770 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py @@ -24,6 +24,7 @@ import pg_gw_context import subprocess import time import os +import re LXC_CONF = "/etc/libvirt/lxc.conf" TEMPLATES = 'templates/' @@ -134,6 +135,20 @@ def remove_iovisor(): ''' _exec_cmd(cmd=['rmmod', 'iovisor'], error_msg='Error Loading Iovisor Kernel Module') +def check_interface_type(): + ''' + Checks the interface. Support added for AWS deployments. There are 2 + possible interfaces "juju-br0" and "eth0". The default being juju-br0 + ''' + log("Checking Interface Type") + default_interface = "juju-br0" + AWS_interface = "eth0" + shell_output = subprocess.check_output(['brctl','show','juju-br0']) + output = re.split(' |\n|\t',shell_output) + if output[10] == '': + return AWS_interface + else: + return default_interface def ensure_mtu(): ''' @@ -141,12 +156,14 @@ def ensure_mtu(): ''' log("Changing MTU of juju-br0 and all attached interfaces") interface_mtu = config('network-device-mtu') - cmd = subprocess.check_output(["brctl", "show", "juju-br0"]) - words = cmd.split() - for word in words: - if 'eth' in word: - set_nic_mtu(word, interface_mtu) - set_nic_mtu('juju-br0', interface_mtu) + interface_type = check_interface_type() + if interface_type == "juju-br0": + cmd = subprocess.check_output(["brctl", "show", interface_type]) + words = cmd.split() + for word in words: + if 'eth' in word: + set_nic_mtu(word, interface_mtu) + set_nic_mtu(interface_type, interface_mtu) def _exec_cmd(cmd=None, error_msg='Command exited with ERRORs', fatal=False):