Configurable Managment interface support
This commit is contained in:
commit
7fbc457f3a
|
@ -9,6 +9,10 @@ options:
|
|||
default: 'null'
|
||||
type: string
|
||||
description: Public SSH key of PLUMgrid LCM which is running PG-Tools
|
||||
mgmt-interface:
|
||||
type: string
|
||||
default: 'juju-br0'
|
||||
description: The interface connected to PLUMgrid Managment network.
|
||||
network-device-mtu:
|
||||
type: string
|
||||
default: '1580'
|
||||
|
|
|
@ -71,8 +71,8 @@ class PGGwContext(context.NeutronContext):
|
|||
pg_ctxt['local_ip'] = pg_dir_ips
|
||||
unit_hostname = get_unit_hostname()
|
||||
pg_ctxt['pg_hostname'] = unit_hostname
|
||||
from pg_gw_utils import check_interface_type, get_gw_interfaces
|
||||
pg_ctxt['interface'] = check_interface_type()
|
||||
from pg_gw_utils import get_mgmt_interface, get_gw_interfaces
|
||||
pg_ctxt['interface'] = get_mgmt_interface()
|
||||
pg_ctxt['label'] = unit_hostname
|
||||
pg_ctxt['fabric_mode'] = 'host'
|
||||
pg_ctxt['ext_interfaces'] = get_gw_interfaces()
|
||||
|
|
|
@ -7,6 +7,12 @@ from copy import deepcopy
|
|||
from charmhelpers.core.hookenv import (
|
||||
log,
|
||||
config,
|
||||
unit_get
|
||||
)
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_iface_from_addr,
|
||||
get_bridges,
|
||||
get_bridge_nics,
|
||||
)
|
||||
from charmhelpers.core.host import (
|
||||
write_file,
|
||||
|
@ -25,7 +31,6 @@ import pg_gw_context
|
|||
import subprocess
|
||||
import time
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
|
||||
LXC_CONF = "/etc/libvirt/lxc.conf"
|
||||
|
@ -143,20 +148,29 @@ def remove_iovisor():
|
|||
error_msg='Error Loading Iovisor Kernel Module')
|
||||
|
||||
|
||||
def check_interface_type():
|
||||
def get_mgmt_interface():
|
||||
'''
|
||||
Checks the interface. Support added for AWS deployments. There are 2
|
||||
possible interfaces "juju-br0" and "eth0". The default being juju-br0
|
||||
Returns the managment interface.
|
||||
'''
|
||||
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
|
||||
def interface_exists(interface):
|
||||
'''
|
||||
Checks if interface exists on node.
|
||||
'''
|
||||
try:
|
||||
subprocess.check_call(['ip', 'link', 'show', interface],
|
||||
stdout=open(os.devnull, 'w'),
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
return True
|
||||
|
||||
mgmt_interface = config('mgmt-interface')
|
||||
if interface_exists(mgmt_interface):
|
||||
return mgmt_interface
|
||||
else:
|
||||
return default_interface
|
||||
log('Provided managment interface %s does not exist'
|
||||
% mgmt_interface)
|
||||
return get_iface_from_addr(unit_get('private-address'))
|
||||
|
||||
|
||||
def get_gw_interfaces():
|
||||
|
@ -180,16 +194,13 @@ def ensure_mtu():
|
|||
'''
|
||||
Ensures required MTU of the underlying networking of the node.
|
||||
'''
|
||||
log("Changing MTU of juju-br0 and all attached interfaces")
|
||||
interface_mtu = config('network-device-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)
|
||||
mgmt_interface = get_mgmt_interface()
|
||||
if mgmt_interface in get_bridges():
|
||||
attached_interfaces = get_bridge_nics(mgmt_interface)
|
||||
for interface in attached_interfaces:
|
||||
set_nic_mtu(interface, interface_mtu)
|
||||
set_nic_mtu(mgmt_interface, interface_mtu)
|
||||
|
||||
|
||||
def _exec_cmd(cmd=None, error_msg='Command exited with ERRORs', fatal=False):
|
||||
|
|
|
@ -37,9 +37,9 @@ class PGGwContextTest(CharmTestCase):
|
|||
@patch.object(context, '_pg_dir_settings')
|
||||
@patch.object(charmhelpers.contrib.openstack.context,
|
||||
'neutron_plugin_attribute')
|
||||
@patch.object(utils, 'check_interface_type')
|
||||
@patch.object(utils, 'get_mgmt_interface')
|
||||
@patch.object(utils, 'get_gw_interfaces')
|
||||
def test_neutroncc_context_api_rel(self, _gw_int, _int_type,
|
||||
def test_neutroncc_context_api_rel(self, _gw_int, _mgmt_int,
|
||||
_npa, _pg_dir_settings,
|
||||
_save_flag_file, _config_flag,
|
||||
_unit_get, _unit_priv_ip, _config,
|
||||
|
@ -58,7 +58,7 @@ class PGGwContextTest(CharmTestCase):
|
|||
_is_clus.return_value = False
|
||||
_config_flag.return_value = False
|
||||
_pg_dir_settings.return_value = {'pg_dir_ip': '192.168.100.201'}
|
||||
_int_type.return_value = 'juju-br0'
|
||||
_mgmt_int.return_value = 'juju-br0'
|
||||
_gw_int.return_value = ['eth1']
|
||||
napi_ctxt = context.PGGwContext()
|
||||
expect = {
|
||||
|
|
Loading…
Reference in New Issue