From f6f99db4a2f6c2b457b0ff28d18b9511051b5b94 Mon Sep 17 00:00:00 2001 From: Eduardo Gonzalez Date: Thu, 9 Feb 2017 12:46:30 +0000 Subject: [PATCH] Add cli options to cleanup-images Allow remove all kolla images Allow remove specific kolla version images Allow remove dangling images Allow remove single images, all images matched Usage examples: * cleanup-images --all - Remove all kolla images * cleanup-images --image-version 4.0.0 - Remove all images matching 4.0.0 kolla_version * cleanup-images --dangling - Remove all dangling images * cleanup-images --image nova - Remove all nova images * cleanup-images --image nova-scheduler - Only remove nova-scheduler image Implements: blueprint add-cleanup-images-cli-options Change-Id: I997272098879350e13e0ac00762ae3485e618355 --- .../roles/destroy/tasks/cleanup_images.yml | 2 +- doc/operating-kolla.rst | 2 +- tools/cleanup-images | 74 +++++++++++++++++-- ...p-images-cli-options-dd5c43fcc683b8e0.yaml | 6 ++ 4 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 tools/releasenotes/notes/add-cleanup-images-cli-options-dd5c43fcc683b8e0.yaml diff --git a/ansible/roles/destroy/tasks/cleanup_images.yml b/ansible/roles/destroy/tasks/cleanup_images.yml index 83ecb68635..ea8f8715c9 100644 --- a/ansible/roles/destroy/tasks/cleanup_images.yml +++ b/ansible/roles/destroy/tasks/cleanup_images.yml @@ -1,5 +1,5 @@ --- - name: Removing Kolla images - command: /tmp/kolla-cleanup/tools/cleanup-images + command: /tmp/kolla-cleanup/tools/cleanup-images --all when: - destroy_include_images | bool diff --git a/doc/operating-kolla.rst b/doc/operating-kolla.rst index f8285682d5..fd6506cb3a 100644 --- a/doc/operating-kolla.rst +++ b/doc/operating-kolla.rst @@ -79,7 +79,7 @@ triggered on the Docker host when the neutron-agents containers are launched. This can be useful when you want to do a new clean deployment, particularly one changing the network topology. -``tools/cleanup-images`` is used to remove all Docker images built by Kolla +``tools/cleanup-images --all`` is used to remove all Docker images built by Kolla from the local Docker cache. ``kolla-ansible -i INVENTORY deploy`` is used to deploy and start all Kolla diff --git a/tools/cleanup-images b/tools/cleanup-images index 255c337919..5d2c30f2ae 100755 --- a/tools/cleanup-images +++ b/tools/cleanup-images @@ -6,11 +6,73 @@ cd "$(dirname "$REAL_PATH")/.." . tools/validate-docker-execute.sh -KOLLA_IMAGES=$(docker images -a --filter "label=kolla_version" --format "{{.ID}}") +function process_cmd { + if [[ -z "$KOLLA_IMAGES" ]]; then + echo "No images to cleanup, exit now." + exit 0 + fi -if [[ -z "$KOLLA_IMAGES" ]]; then - echo "No images to cleanup, exit now." - exit 0 -fi + $CMD -docker rmi -f $@ $KOLLA_IMAGES + if [[ $? -ne 0 ]]; then + echo "Command failed $CMD" + exit 1 + fi +} + +function usage { + cat < Delete selected images + --image-version Set Kolla image version +EOF +} + +SHORT_OPTS="ahi:" +LONG_OPTS="all,dangling,help,image:,image-version:" +ARGS=$(getopt -o "${SHORT_OPTS}" -l "${LONG_OPTS}" --name "$0" -- "$@") || { usage >&2; exit 2; } + +eval set -- "$ARGS" + +case "$1" in + + (--all|-a) + KOLLA_IMAGES="$(docker images -a --filter "label=kolla_version" --format "{{.ID}}")" + shift + ;; + + (--dangling) + KOLLA_IMAGES="$(docker images -a --filter dangling=true --format "{{.ID}}")" + shift + ;; + + (--image|-i) + KOLLA_IMAGES="$(docker images -a --filter "label=kolla_version" --format "{{.Repository}}\t{{.ID}}" | grep -E "$2" | awk '{print $2}')" + shift 2 + ;; + + (--image-version) + KOLLA_IMAGES="$(docker images -a --filter "label=kolla_version=${2}" --format "{{.ID}}")" + shift 2 + ;; + + (--help|-h) + usage + shift + exit 0 + ;; + + (--) + shift + break + ;; + +esac + +CMD="docker rmi -f $@ $KOLLA_IMAGES" +process_cmd diff --git a/tools/releasenotes/notes/add-cleanup-images-cli-options-dd5c43fcc683b8e0.yaml b/tools/releasenotes/notes/add-cleanup-images-cli-options-dd5c43fcc683b8e0.yaml new file mode 100644 index 0000000000..59ada4baf3 --- /dev/null +++ b/tools/releasenotes/notes/add-cleanup-images-cli-options-dd5c43fcc683b8e0.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Cleanup-images support advanced features such as remove all kolla + images, remove dangling images, delete user selected images and + remove images from specific kolla_version.