From 556388e7370d467acf89b248fb37159beef61b74 Mon Sep 17 00:00:00 2001 From: Daneyon Hansen Date: Wed, 6 May 2015 21:00:38 +0000 Subject: [PATCH] Updates cleanup-containers Previously cleanup-containers suffered from the following limitations: 1. The docker rm command would fail if all the containers were not stopped. 2. The script would throw an error if no containers existed. 3. Artifacts such as veths, bridges, etc.. would remain on the host after containers were removed. These artifacts should be removed if the containers are removed. Change-Id: I5eadb23fec9e34125a32f6c3e39c241d97932910 --- tools/cleanup-containers | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tools/cleanup-containers b/tools/cleanup-containers index 7b0e8341e0..57c663c9cd 100755 --- a/tools/cleanup-containers +++ b/tools/cleanup-containers @@ -1,3 +1,39 @@ #!/bin/bash -docker rm $@ $(docker ps -a -q) +# Check if user is root +if [[ $EUID -ne 0 ]]; then + echo "You must execute this script as root." 1>&2 + exit 1 +fi + +# Move to top level directory +REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')") +cd "$(dirname "$REAL_PATH")/.." + +# Remove docker containers +docker ps -a -q | while read -r line ; do + echo "Removing docker containers" + docker rm -f $line +done + +# Spawning the neutron-agents container leaves artifacts on the host. +# This script removes these artifacts. +ip netns list | while read -r line ; do + echo "Removing network namespaces on the host" + ip netns delete $line +done + +ifconfig | grep tap | awk '{print $1;}'| cut -f1 -d':' | while read -r line ; do + echo "Removing tap interfaces on the host" + ip link delete $line type veth +done + +ifconfig | grep brq | awk '{print $1;}'| cut -f1 -d':' | while read -r line ; do + echo "Removing linux bridges on the host" + ip link delete $line type bridge +done + +ifconfig | grep vxlan | awk '{print $1;}'| cut -f1 -d':' | while read -r line ; do + echo "Removing vxlan interfaces on the host" + ip link delete $line type vxlan +done