Add support for specifying custom static routes

This change allows you to specify static routes for a given network in
your openstack_user_config.yml file:

  global_overrides:
    provider_networks:
      - network:
          group_binds:
            - glance_api
            - nova_compute
            - neutron_linuxbridge_agent
          type: "raw"
          container_bridge: "br-snet"
          container_interface: "eth3"
          container_type: "veth"
          ip_from_q: "snet"
          static_routes:
            - cidr: 10.176.0.0/12
              gateway: 172.29.248.1

This will result in the following being written to
/etc/network/interfaces.d/eth3.cfg for the affected containers:

  post-up ip route add 10.176.0.0/12 via 172.29.248.1 || true

Change-Id: Id5a74db2399166af2d6ac289b71ebb0de04f5679
Closes-Bug: #1464639
This commit is contained in:
Matt Thompson
2015-06-12 13:47:12 +01:00
committed by Kevin Carter
parent e6da43ac27
commit 21a8f1ff04
2 changed files with 20 additions and 3 deletions

View File

@@ -457,7 +457,7 @@ def _load_optional_q(config, cidr_name):
def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
bridge, net_type, user_config, is_ssh_address,
is_container_address):
is_container_address, static_routes):
"""Process additional ip adds and append then to hosts as needed.
If the host is found to be "is_metal" it will be marked as "on_metal"
@@ -472,6 +472,7 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
:param user_config: ``dict`` user defined configuration details.
:param is_ssh_address: ``bol`` set this address as ansible_ssh_host.
:param is_container_address: ``bol`` set this address to container_address.
:param static_routes: ``list`` List containing static route dicts.
"""
def network_entry():
"""Return a network entry for a container."""
@@ -520,7 +521,8 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
net_type,
user_config,
is_ssh_address,
is_container_address
is_container_address,
static_routes
)
# Make sure the lookup object has a value.
@@ -590,6 +592,15 @@ def _add_additional_networks(key, inventory, ip_q, q_name, netmask, interface,
if is_container_address is True:
container['container_address'] = networks[old_address]['address']
if static_routes:
# NOTE: networks[old_address]['static_routes'] will get
# regenerated on each run
networks[old_address]['static_routes'] = []
for s in static_routes:
# only add static routes if they are specified correctly
if 'cidr' in s and 'gateway' in s:
networks[old_address]['static_routes'].append(s)
def _net_address_search(provider_networks, main_netowrk, key):
"""Set the key netwokr type to the main network if not specified.
@@ -685,7 +696,8 @@ def container_skel_load(container_skel, inventory, config):
net_type=p_net.get('container_type'),
user_config=config,
is_ssh_address=p_net.get('is_ssh_address'),
is_container_address=p_net.get('is_container_address')
is_container_address=p_net.get('is_container_address'),
static_routes=p_net.get('static_routes')
)

View File

@@ -61,6 +61,11 @@ lxc_container_interface: |
{% if item.value.gateway is defined %}
gateway {{ item.value.gateway }}
{% endif %}
{% if item.value.static_routes is defined %}
{% for route in item.value.static_routes %}
post-up ip route add {{ route['cidr'] }} via {{ route['gateway'] }} || true
{% endfor %}
{% endif %}
{% else %}
iface {{ item.value.interface }} inet manual
{% endif %}