4f1eb22919
The lxc_container_create role creates containers specified via an inventory. Multiple network interfaces can be added to a container during creation. These interfaces are provided by the task 'LXC host config for container networks' in openstack-ansible-lxc_container_create/tasks/container_create.yml The task 'LXC host config for container networks' utilizes a template file, openstack-ansible-lxc_container_create/templates/container-interface.ini.j2 The configuration for a specified interface is created using this template. The template currenlty offers the ability to modify the value 'lxc.network.type' which defaults to type 'veth' if no value is supplied. Supplying a value other than 'veth' is currently valid for this template. However, the creation of a veth pair device is hard coded into the template whether or not 'lxc.network.type' resolves to a value other than 'veth' This creates two unwanted side effects: First, a veth pair that is not being utilized by the corresponding container is created. We should not create a veth pair if it will not be used. Secondly, if the value of the variable 'lxc.network.link' defined in the same template file is something other than a bridge, the unwanted veth creation will fail resulting in a container that will not start. Additionally, if the corresponding veth pair is not created, then the template openstack-ansible-lxc_container_create/templates/veth-cleanup.sh.j2 should be modified to filter out interfaces that are not of type 'veth'. This change implements interface type detection in the template files veth-cleanup.sh.j2 and container-interface.ini.j2 to prevent creation of unwanted veth interfaces and their associated cleanup. Change-Id: I1c0a26d07e8de0ca862d21ea7b49e02ae447f83a Closes-Bug: #1531935
16 lines
929 B
Django/Jinja
16 lines
929 B
Django/Jinja
#!/usr/bin/env bash
|
|
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
# LXC eth0 is considered special and not managed by the base container_networks
|
|
# data structure. This is being added outside of the loop for this reason.
|
|
ip link del {{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_eth0 || true
|
|
logger "LXC container {{ inventory_hostname }} removing veth {{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_eth0"
|
|
|
|
# Veth cleanup for items in the container_networks data structure
|
|
{% for key, value in container_networks.items() %}
|
|
{% if value.type == 'veth' or value.type is none %}
|
|
ip link del {{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_{{ value.interface }} || true
|
|
logger "LXC container {{ inventory_hostname }} removing veth {{ inventory_hostname[-8:].replace('-', '').replace('_', '') }}_{{ value.interface }}"
|
|
{% endif %}
|
|
{% endfor %}
|