Added post and pre hook script for veth cleanup

The change adds a simple post and pre hook script to clean up all of the
the named veth pairs that are assosiated within a given container.

Change-Id: I563a4be9f5e04c1599a9e4e592970a4ef0dbb38e
Implements: blueprint named-veths
This commit is contained in:
kevin 2015-09-03 17:34:03 -05:00
parent 5e6dea8ab6
commit 3a3b076c47
No known key found for this signature in database
GPG Key ID: 69FEFFC5E2D9273F
2 changed files with 42 additions and 0 deletions

View File

@ -214,6 +214,34 @@
tags:
- lxc-container-networks
# Adds post-down and pre-start hooks
- name: Drop veth cleanup script
template:
src: "veth-cleanup.sh.j2"
dest: "/var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh"
owner: "root"
group: "root"
mode: "0755"
delegate_to: "{{ physical_host }}"
tags:
- lxc-container-networks
# This is being defined due to an issue with dangling veth pairs.
# TODO(someone) This should be removed once an upstream patch has
# been submitted to either the kernel or LXC to fix the veth issues.
# Container restart is not happening here because it's not needed.
- name: Defines a pre and post hook script
lineinfile:
dest: "/var/lib/lxc/{{ inventory_hostname }}/config"
line: "{{ item }}"
backup: "true"
with_items:
- "lxc.hook.pre-start = /var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh"
- "lxc.hook.post-stop = /var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh"
delegate_to: "{{ physical_host }}"
tags:
- lxc-container-networks
# Flush the handlers to ensure the container and networking is online.
- meta: flush_handlers

View File

@ -0,0 +1,14 @@
#!/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() %}
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 }}"
{% endfor %}