Add setup for configuring an external bridge
This commit is contained in:
parent
5ab3daeb05
commit
2f1aceb741
|
@ -47,3 +47,12 @@ options:
|
|||
.
|
||||
This network will be used for tenant network traffic in overlay
|
||||
networks.
|
||||
ext-port:
|
||||
type: string
|
||||
default:
|
||||
description: |
|
||||
A space-separated list of external ports to use for routing of instance
|
||||
traffic to the external public network. Valid values are either MAC
|
||||
addresses (in which case only MAC addresses for interfaces without an IP
|
||||
address already assigned will be used), or interfaces (eth0)
|
||||
|
||||
|
|
|
@ -6,12 +6,17 @@ from charmhelpers.core.hookenv import (
|
|||
config,
|
||||
unit_get,
|
||||
)
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_address_in_network,
|
||||
get_ipv4_addr,
|
||||
get_ipv6_addr,
|
||||
is_bridge_member,
|
||||
)
|
||||
from charmhelpers.core.host import list_nics, get_nic_hwaddr
|
||||
from charmhelpers.contrib.openstack import context
|
||||
from charmhelpers.core.host import service_running, service_start
|
||||
from charmhelpers.contrib.network.ovs import add_bridge, add_bridge_port
|
||||
from charmhelpers.contrib.openstack.utils import get_host_ip
|
||||
from charmhelpers.contrib.network.ip import get_address_in_network
|
||||
from charmhelpers.contrib.openstack.context import OSContextGenerator
|
||||
|
||||
import re
|
||||
|
@ -139,3 +144,45 @@ class L3AgentContext(OSContextGenerator):
|
|||
else:
|
||||
ctxt['agent_mode'] = 'legacy'
|
||||
return ctxt
|
||||
|
||||
|
||||
class NeutronPortContext(OSContextGenerator):
|
||||
|
||||
def _resolve_port(self, config_key):
|
||||
if not config(config_key):
|
||||
return None
|
||||
hwaddr_to_nic = {}
|
||||
hwaddr_to_ip = {}
|
||||
for nic in list_nics(['eth', 'bond']):
|
||||
hwaddr = get_nic_hwaddr(nic)
|
||||
hwaddr_to_nic[hwaddr] = nic
|
||||
addresses = get_ipv4_addr(nic, fatal=False) + \
|
||||
get_ipv6_addr(iface=nic, fatal=False)
|
||||
hwaddr_to_ip[hwaddr] = addresses
|
||||
mac_regex = re.compile(r'([0-9A-F]{2}[:-]){5}([0-9A-F]{2})', re.I)
|
||||
for entry in config(config_key).split():
|
||||
entry = entry.strip()
|
||||
if re.match(mac_regex, entry):
|
||||
if entry in hwaddr_to_nic and len(hwaddr_to_ip[entry]) == 0:
|
||||
# If the nic is part of a bridge then don't use it
|
||||
if is_bridge_member(hwaddr_to_nic[entry]):
|
||||
continue
|
||||
# Entry is a MAC address for a valid interface that doesn't
|
||||
# have an IP address assigned yet.
|
||||
return hwaddr_to_nic[entry]
|
||||
else:
|
||||
# If the passed entry is not a MAC address, assume it's a valid
|
||||
# interface, and that the user put it there on purpose (we can
|
||||
# trust it to be the real external network).
|
||||
return entry
|
||||
return None
|
||||
|
||||
|
||||
class ExternalPortContext(NeutronPortContext):
|
||||
|
||||
def __call__(self):
|
||||
port = self._resolve_port('ext-port')
|
||||
if port:
|
||||
return {"ext_port": port}
|
||||
else:
|
||||
return None
|
||||
|
|
|
@ -7,6 +7,10 @@ from charmhelpers.contrib.openstack.utils import (
|
|||
os_release,
|
||||
)
|
||||
import neutron_ovs_context
|
||||
from charmhelpers.contrib.network.ovs import (
|
||||
add_bridge,
|
||||
add_bridge_port,
|
||||
)
|
||||
|
||||
NOVA_CONF_DIR = "/etc/nova"
|
||||
NEUTRON_CONF_DIR = "/etc/neutron"
|
||||
|
@ -15,6 +19,7 @@ NEUTRON_DEFAULT = '/etc/default/neutron-server'
|
|||
NEUTRON_L3_AGENT_CONF = "/etc/neutron/l3_agent.ini"
|
||||
NEUTRON_FWAAS_CONF = "/etc/neutron/fwaas_driver.ini"
|
||||
ML2_CONF = '%s/plugins/ml2/ml2_conf.ini' % NEUTRON_CONF_DIR
|
||||
EXT_PORT_CONF = '/etc/init/ext-port.conf'
|
||||
|
||||
BASE_RESOURCE_MAP = OrderedDict([
|
||||
(NEUTRON_CONF, {
|
||||
|
@ -34,8 +39,15 @@ BASE_RESOURCE_MAP = OrderedDict([
|
|||
'services': ['neutron-vpn-agent'],
|
||||
'contexts': [neutron_ovs_context.L3AgentContext()],
|
||||
}),
|
||||
(EXT_PORT_CONF, {
|
||||
'services': [],
|
||||
'contexts': [neutron_ovs_context.ExternalPortContext()],
|
||||
}),
|
||||
])
|
||||
TEMPLATES = 'templates/'
|
||||
INT_BRIDGE = "br-int"
|
||||
EXT_BRIDGE = "br-ex"
|
||||
DATA_BRIDGE = 'br-data'
|
||||
|
||||
|
||||
def determine_dvr_packages():
|
||||
|
@ -77,3 +89,13 @@ def restart_map():
|
|||
state.
|
||||
'''
|
||||
return {k: v['services'] for k, v in resource_map().iteritems()}
|
||||
|
||||
|
||||
def configure_ovs():
|
||||
add_bridge(INT_BRIDGE)
|
||||
add_bridge(EXT_BRIDGE)
|
||||
ext_port_ctx = neutron_ovs_context.ExternalPortContext()()
|
||||
if ext_port_ctx and ext_port_ctx['ext_port']:
|
||||
add_bridge_port(EXT_BRIDGE, ext_port_ctx['ext_port'])
|
||||
|
||||
add_bridge(DATA_BRIDGE)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
description "Enabling Quantum external networking port"
|
||||
|
||||
start on runlevel [2345]
|
||||
|
||||
task
|
||||
|
||||
script
|
||||
ip link set {{ ext_port }} up
|
||||
end script
|
Loading…
Reference in New Issue