Add support for static routes on networks

This commit is contained in:
Mark Goddard 2017-07-05 19:05:06 +01:00
parent 8cbeee740a
commit 22b56d5a03
3 changed files with 48 additions and 0 deletions

View File

@ -118,6 +118,7 @@ def net_vlan(context, name, inventory_hostname=None):
net_mtu = _make_attr_filter('mtu') net_mtu = _make_attr_filter('mtu')
net_routes = _make_attr_filter('routes')
@jinja2.contextfilter @jinja2.contextfilter
@ -125,8 +126,28 @@ def net_bridge_ports(context, name, inventory_hostname=None):
return net_attr(context, name, 'bridge_ports', inventory_hostname) return net_attr(context, name, 'bridge_ports', inventory_hostname)
def _route_obj(route):
"""Return a dict representation of an IP route.
The returned dict is compatible with the route item of the
interfaces_ether_interfaces and interfaces_bridge_interfaces variables in
the MichaelRigaert.interfaces role.
"""
net = netaddr.IPNetwork(route['cidr'])
return {
'network': str(net.network),
'netmask': str(net.netmask),
'gateway': route['gateway'],
}
@jinja2.contextfilter @jinja2.contextfilter
def net_interface_obj(context, name, inventory_hostname=None): def net_interface_obj(context, name, inventory_hostname=None):
"""Return a dict representation of a network interface.
The returned dict is compatible with the interfaces_ether_interfaces
variable in the MichaelRigaert.interfaces role.
"""
device = net_interface(context, name, inventory_hostname) device = net_interface(context, name, inventory_hostname)
if not device: if not device:
raise errors.AnsibleFilterError( raise errors.AnsibleFilterError(
@ -138,6 +159,9 @@ def net_interface_obj(context, name, inventory_hostname=None):
gateway = net_gateway(context, name, inventory_hostname) gateway = net_gateway(context, name, inventory_hostname)
vlan = net_vlan(context, name, inventory_hostname) vlan = net_vlan(context, name, inventory_hostname)
mtu = net_mtu(context, name, inventory_hostname) mtu = net_mtu(context, name, inventory_hostname)
routes = net_routes(context, name, inventory_hostname)
if routes:
routes = [_route_obj(route) for route in routes]
interface = { interface = {
'device': device, 'device': device,
'address': ip, 'address': ip,
@ -145,6 +169,7 @@ def net_interface_obj(context, name, inventory_hostname=None):
'gateway': gateway, 'gateway': gateway,
'vlan': vlan, 'vlan': vlan,
'mtu': mtu, 'mtu': mtu,
'route': routes,
'bootproto': 'static', 'bootproto': 'static',
'onboot': 'yes', 'onboot': 'yes',
} }
@ -154,6 +179,11 @@ def net_interface_obj(context, name, inventory_hostname=None):
@jinja2.contextfilter @jinja2.contextfilter
def net_bridge_obj(context, name, inventory_hostname=None): def net_bridge_obj(context, name, inventory_hostname=None):
"""Return a dict representation of a network bridge interface.
The returned dict is compatible with the interfaces_bridge_interfaces
variable in the MichaelRigaert.interfaces role.
"""
device = net_interface(context, name, inventory_hostname) device = net_interface(context, name, inventory_hostname)
if not device: if not device:
raise errors.AnsibleFilterError( raise errors.AnsibleFilterError(
@ -166,6 +196,9 @@ def net_bridge_obj(context, name, inventory_hostname=None):
vlan = net_vlan(context, name, inventory_hostname) vlan = net_vlan(context, name, inventory_hostname)
mtu = net_mtu(context, name, inventory_hostname) mtu = net_mtu(context, name, inventory_hostname)
ports = net_bridge_ports(context, name, inventory_hostname) ports = net_bridge_ports(context, name, inventory_hostname)
routes = net_routes(context, name, inventory_hostname)
if routes:
routes = [_route_obj(route) for route in routes]
interface = { interface = {
'device': device, 'device': device,
'address': ip, 'address': ip,
@ -174,6 +207,7 @@ def net_bridge_obj(context, name, inventory_hostname=None):
'vlan': vlan, 'vlan': vlan,
'mtu': mtu, 'mtu': mtu,
'ports': ports, 'ports': ports,
'route': routes,
'bootproto': 'static', 'bootproto': 'static',
'onboot': 'yes', 'onboot': 'yes',
} }
@ -261,6 +295,7 @@ class FilterModule(object):
'net_neutron_allocation_pool_end': net_neutron_allocation_pool_end, 'net_neutron_allocation_pool_end': net_neutron_allocation_pool_end,
'net_vlan': net_vlan, 'net_vlan': net_vlan,
'net_mtu': net_mtu, 'net_mtu': net_mtu,
'net_routes': net_routes,
'net_interface_obj': net_interface_obj, 'net_interface_obj': net_interface_obj,
'net_bridge_obj': net_bridge_obj, 'net_bridge_obj': net_bridge_obj,
'net_is_ether': net_is_ether, 'net_is_ether': net_is_ether,

View File

@ -143,6 +143,10 @@ supported:
VLAN ID. VLAN ID.
``mtu`` ``mtu``
Maximum Transmission Unit (MTU). Maximum Transmission Unit (MTU).
``routes``
List of static IP routes. Each item should be a dict containing the
items ``cidr`` and ``gateway``. ``cidr`` is the CIDR representation of the
route's destination. ``gateway`` is the IP address of the next hop.
IP addresses are allocated automatically by Kayobe from the IP addresses are allocated automatically by Kayobe from the
allocation pool allocation pool
@ -266,6 +270,9 @@ We could describe such a network as follows:
external_allocation_pool_end: 10.0.3.127 external_allocation_pool_end: 10.0.3.127
external_neutron_allocation_pool_start: 10.0.3.128 external_neutron_allocation_pool_start: 10.0.3.128
external_neutron_allocation_pool_end: 10.0.3.254 external_neutron_allocation_pool_end: 10.0.3.254
external_routes:
- cidr 10.0.4.0/24
gateway: 10.0.3.1
We can map these networks to network interfaces on the seed and controller hosts: We can map these networks to network interfaces on the seed and controller hosts:

View File

@ -41,6 +41,7 @@
# provision_oc_net_gateway: # provision_oc_net_gateway:
# provision_oc_net_vlan: # provision_oc_net_vlan:
# provision_oc_net_mtu: # provision_oc_net_mtu:
# provision_oc_net_routes:
# Workload provisioning network IP information. # Workload provisioning network IP information.
# provision_wl_net_cidr: # provision_wl_net_cidr:
@ -53,6 +54,7 @@
# provision_wl_net_gateway: # provision_wl_net_gateway:
# provision_wl_net_vlan: # provision_wl_net_vlan:
# provision_wl_net_mtu: # provision_wl_net_mtu:
# provision_wl_net_routes:
# Internal network IP information. # Internal network IP information.
# internal_net_vip_address: # internal_net_vip_address:
@ -63,6 +65,7 @@
# internal_net_gateway: # internal_net_gateway:
# internal_net_vlan: # internal_net_vlan:
# internal_net_mtu: # internal_net_mtu:
# internal_net_routes:
# External network IP information. # External network IP information.
# external_net_vip_address: # external_net_vip_address:
@ -75,6 +78,7 @@
# external_net_gateway: # external_net_gateway:
# external_net_vlan: # external_net_vlan:
# external_net_mtu: # external_net_mtu:
# external_net_routes:
# Storage network IP information. # Storage network IP information.
# storage_net_cidr: # storage_net_cidr:
@ -83,6 +87,7 @@
# storage_net_gateway: # storage_net_gateway:
# storage_net_vlan: # storage_net_vlan:
# storage_net_mtu: # storage_net_mtu:
# storage_net_routes:
# Storage management network IP information. # Storage management network IP information.
# storage_mgmt_net_cidr: # storage_mgmt_net_cidr:
@ -91,6 +96,7 @@
# storage_mgmt_net_gateway: # storage_mgmt_net_gateway:
# storage_mgmt_net_vlan: # storage_mgmt_net_vlan:
# storage_mgmt_net_mtu: # storage_mgmt_net_mtu:
# storage_mgmt_net_routes:
############################################################################### ###############################################################################
# Network virtual patch link configuration. # Network virtual patch link configuration.