Add ovs support for lxc containers.

The main problem this commit is resolving is that with openvswitch,
the ports were not get cleaned up, and after restart (hard restart or even with soft restart
lxc.service gets time-out) containers couldn't start properly, due to existing port on the bridges.

Change-Id: I707dbfc6878095f7593abe3fca3a5e5b310063e5
Depends-On: https://review.opendev.org/c/openstack/openstack-ansible/+/837742
This commit is contained in:
siavash sardari 2022-04-13 19:28:11 +04:30 committed by Dmitriy Rabotyagov
parent 37422a7e3d
commit 0b7a8645de
3 changed files with 11 additions and 3 deletions

View File

@ -23,6 +23,7 @@ VETH="${2}"
INTERFACE="${3}" INTERFACE="${3}"
BRIDGE="${4}" BRIDGE="${4}"
VETH_PEER="$(openssl rand -hex 4)" VETH_PEER="$(openssl rand -hex 4)"
BRIDGE_TYPE="${5}"
# PID of running container # PID of running container
PID="$(lxc-info -pHn ${CONTAINER_NAME})" PID="$(lxc-info -pHn ${CONTAINER_NAME})"
@ -51,10 +52,12 @@ if ip a l "${VETH_PEER}";then
EXIT=3 EXIT=3
fi fi
if [ "${BRIDGE}" != "openvswitch" ]; then
if ! brctl show "${BRIDGE}" | grep -q "${VETH}"; then if ! brctl show "${BRIDGE}" | grep -q "${VETH}"; then
brctl addif "${BRIDGE}" "${VETH}" brctl addif "${BRIDGE}" "${VETH}"
EXIT_CODE=3 EXIT_CODE=3
fi fi
fi
ns_cmd ip link set dev "${INTERFACE}" down || true ns_cmd ip link set dev "${INTERFACE}" down || true
ns_cmd systemctl restart systemd-networkd ns_cmd systemctl restart systemd-networkd

View File

@ -199,6 +199,7 @@
"{{ lxc_container_network_veth_pair[-15:] }}" "{{ lxc_container_network_veth_pair[-15:] }}"
"{{ item.value.interface }}" "{{ item.value.interface }}"
"{{ item.value.bridge }}" "{{ item.value.bridge }}"
"{{ item.value.bridge_type | default('linux_bridge') }}"
register: wiring_script register: wiring_script
with_dict: "{{ lxc_container_networks_combined }}" with_dict: "{{ lxc_container_networks_combined }}"
when: when:

View File

@ -5,5 +5,9 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
{% for key, value in lxc_container_networks_combined.items() %} {% for key, value in lxc_container_networks_combined.items() %}
{% if value.type is not defined or value.type == 'veth' %} {% if value.type is not defined or value.type == 'veth' %}
ip link del {{ lxc_container_network_veth_pair_prefix }}_{{ value.interface }} || true ip link del {{ lxc_container_network_veth_pair_prefix }}_{{ value.interface }} || true
{% if 'bridge_type' in value and value.bridge_type == "openvswitch" %}
{% set lxc_container_network_ovs_port_indexed = lxc_container_network_veth_pair_prefix ~ "_" ~ value.interface %}
ovs-vsctl --if-exists del-port {{ lxc_container_network_ovs_port_indexed[-15:] }} || true
{% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}