#!/bin/bash # os-glance-swift-crosscheck.sh, ABr, 20141021 # Review all images in glance against swift # get all images in swift l_swift_images=$(swift --os-tenant-name=service list glance | cut -d'-' -f 1-5 | uniq) # headings echo "Orphan|Tenant|Name|Size|Status|Deleted|Is_Public|Protected" # step over glance and find status l_tmp="/tmp/os-glance-swift-crosscheck.$$" for i in $l_swift_images; do # initialize variables l_image_is_orphan='True' l_image_deleted='[n/a]' l_image_is_public='[n/a]' l_image_name='[n/a]' l_image_owner='[n/a]' l_image_protected='[n/a]' l_image_size='[n/a]' l_image_status='[n/a]' l_image_tenant='[n/a]' # get info if glance image-show $i > $l_tmp 2>/dev/null; then # extract what we want l_image_is_orphan='False' l_image_deleted=$(cat $l_tmp | grep -e "^| deleted " | cut -d'|' -f 3 | sed -e 's#^ \+##; s#[ \t]*$##' 2>&1) l_image_is_public=$(cat $l_tmp | grep -e "^| is_public " | cut -d'|' -f 3 | sed -e 's#^ \+##; s#[ \t]*$##' 2>&1) l_image_name=$(cat $l_tmp | grep -e "^| name " | cut -d'|' -f 3 | sed -e 's#^ \+##; s#[ \t]*$##' 2>&1) l_image_owner=$(cat $l_tmp | grep -e "^| owner " | cut -d'|' -f 3 | sed -e 's#^ \+##; s#[ \t]*$##' 2>&1) l_image_protected=$(cat $l_tmp | grep -e "^| protected " | cut -d'|' -f 3 | sed -e 's#^ \+##; s#[ \t]*$##' 2>&1) l_image_size=$(cat $l_tmp | grep -e "^| size " | cut -d'|' -f 3 | sed -e 's#^ \+##; s#[ \t]*$##' 2>&1) l_image_status=$(cat $l_tmp | grep -e "^| status " | cut -d'|' -f 3 | sed -e 's#^ \+##; s#[ \t]*$##' 2>&1) # get the tenant if [ -n "$l_image_owner" ]; then # do this way to prevent error messages keystone tenant-get $l_image_owner 2>/dev/null >$l_tmp l_rc=$? if [ $l_rc -eq 0 ]; then # the tenant is valid; get the name l_image_tenant=$(cat $l_tmp | grep -e "^| \+name " | cut -d'|' -f 3 | sed -e 's#^ \+##; s#[ \t]*$##' 2>&1) else # we have an orphan; project not found l_image_is_orphan='True' l_image_tenant="[n/a] ($l_image_owner)" fi else l_image_tenant="none ([n/a])" fi fi # show the line echo "$l_image_is_orphan|$l_image_tenant ($l_image_owner)|$l_image_name ($i)|$l_image_size|$l_image_status|$l_image_deleted|$l_image_is_public|$l_image_protected" done rm -f $l_tmp