openstack-ansible-lxc_conta.../templates/veth-cleanup.sh.j2
siavash sardari 0b7a8645de 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
2022-06-08 08:10:06 +00:00

14 lines
702 B
Django/Jinja

#!/usr/bin/env bash
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Veth cleanup for items in the container_networks data structure
{% for key, value in lxc_container_networks_combined.items() %}
{% if value.type is not defined or value.type == 'veth' %}
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 %}
{% endfor %}