Enhance configurability of LXC net interfaces

Add the ability to append pre-up, post-up, pre-down, and post-down script
entries to the container_networks dict that are dropped along with the OSA
default configurations when templating the container's interface config files.

The keys preup, postup, predown, and postdown will be appended to the OSA
lxc_container_default_{pre,post}{up/down} lists when dropping the interface
config.

Change-Id: Idf15ec17bac03b55638fb8d862e5445093677f23
This commit is contained in:
Logan V 2017-03-03 12:48:05 -06:00
parent 0f8e133da2
commit eeabfbc042
4 changed files with 34 additions and 6 deletions

View File

@ -74,6 +74,14 @@ lxc_container_fs_type: ext4
# using the directory backing.
lxc_container_vg_name: lxc
# Scripts allowing the configuration of pre/post-up/down scripts in Ubuntu
# interface files. These are merged with per-interface scripts defined in the
# container_networks dict
lxc_container_default_preup: []
lxc_container_default_postup: []
lxc_container_default_predown: []
lxc_container_default_postdown: []
lxc_container_default_mtu: "1500"
lxc_container_domain: "openstack.local"
@ -110,4 +118,3 @@ lxc_container_network_veth_pair: "{{ inventory_hostname[-8:].replace('-', '').re
# Enable fixed mac address generation for an lxc container
lxc_container_fixed_mac: false

View File

@ -0,0 +1,7 @@
---
features:
- In the lxc_container_create role, the keys ``preup``, ``postup``,
``predown``, and ``postdown`` are now supported in the
``container_networks`` dict for Ubuntu systems. This allows operators to
configure custom scripts to be run by Ubuntu's ifupdown system when network
interface states are changed.

View File

@ -10,10 +10,6 @@ iface {{ item.value.interface }} inet static
gateway {{ item.value.gateway }}
{% endif %}
mtu {{ item.value.mtu|default(lxc_container_default_mtu) }}
# needed to enable gratuitous arps on interface events
post-up sysctl -w net.ipv4.conf.$IFACE.arp_notify=1
# needed to force an interface event (setting mac to what it already is)
post-up ip link set $IFACE address $(cat /sys/class/net/$IFACE/address)
{% 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
@ -22,4 +18,16 @@ iface {{ item.value.interface }} inet static
{% else %}
iface {{ item.value.interface }} inet manual
{% endif %}
### end generated network for [ {{ item.value.interface }} ] ###
{% for item in item.value.preup | default([]) | union(lxc_container_default_preup) %}
pre-up {{ item }}
{% endfor %}
{% for item in item.value.postup | default([]) | union(lxc_container_default_postup) %}
post-up {{ item }}
{% endfor %}
{% for item in item.value.predown | default([]) | union(lxc_container_default_predown) %}
pre-down {{ item }}
{% endfor %}
{% for item in item.value.postdown | default([]) | union(lxc_container_default_postdown) %}
post-down {{ item }}
{% endfor %}
### end generated network for [ {{ item.value.interface }} ] ###

View File

@ -29,3 +29,9 @@ lxc_container_map:
distro: ubuntu
arch: "{{ lxc_architecture_mapping.get( hostvars[physical_host]['ansible_architecture'] | lower ) }}"
release: xenial
lxc_container_default_postup:
# needed to enable gratuitous arps on interface events
- "sysctl -w net.ipv4.conf.$IFACE.arp_notify=1"
# needed to force an interface event (setting mac to what it already is)
- "ip link set $IFACE address $(cat /sys/class/net/$IFACE/address)"