diff options
| author | Eduardo Gonzalez <dabarren@gmail.com> | 2017-02-09 12:46:30 +0000 |
|---|---|---|
| committer | Eduardo Gonzalez <dabarren@gmail.com> | 2017-04-24 14:53:24 +0200 |
| commit | f6f99db4a2f6c2b457b0ff28d18b9511051b5b94 (patch) | |
| tree | 46c1eb28371871bad617acaab91c2cb22fef33d1 /tools/cleanup-images | |
| parent | e26f9f876d589f1646dcf75d8dac27098f325bb6 (diff) | |
| download | kolla-ansible-f6f99db4a2f6c2b457b0ff28d18b9511051b5b94.tar.gz kolla-ansible-f6f99db4a2f6c2b457b0ff28d18b9511051b5b94.zip | |
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
Diffstat (limited to 'tools/cleanup-images')
| -rwxr-xr-x | tools/cleanup-images | 74 |
1 files changed, 68 insertions, 6 deletions
diff --git a/tools/cleanup-images b/tools/cleanup-images index 255c33791..5d2c30f2a 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 <<EOF +Usage: $0 COMMAND [options] + +Options: + --all, -a Remove all kolla images + --dangling Remove orphaned images + --help, -h Show this usage information + --image, -i <image> Delete selected images + --image-version <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 |
