Cleanup errors in shell scripts identified by bashate

Change-Id: Ib3c4d841e4282368343b81e5824a0319e9817b48
This commit is contained in:
Christian Berendt 2015-09-29 18:21:47 +02:00 committed by JJ Asghar
parent f243b8c739
commit 99594b48f6
10 changed files with 196 additions and 219 deletions

View File

@ -2,8 +2,8 @@
# OpenStack credentialss are expected to be in your environment variables # OpenStack credentialss are expected to be in your environment variables
if [ -z "$OS_AUTH_URL" -o -z "$OS_PASSWORD" -o -z "$OS_USERNAME" ]; then if [ -z "$OS_AUTH_URL" -o -z "$OS_PASSWORD" -o -z "$OS_USERNAME" ]; then
echo "Please set OpenStack auth environment variables." echo "Please set OpenStack auth environment variables."
exit 1 exit 1
fi fi
# temp files for caching outputs # temp files for caching outputs
@ -16,11 +16,11 @@ final_report=$(mktemp)
echo -en "Retrieving list of all volumes...\r" echo -en "Retrieving list of all volumes...\r"
# oh cinder... # oh cinder...
for volume in `cinder list --all-tenants | tail -n +4 | awk '{print $2}'`; do for volume in `cinder list --all-tenants | tail -n +4 | awk '{print $2}'`; do
for line in `cinder show $volume | grep 'os-vol-tenant-attr:tenant_id\| id ' | awk '{print $4}'`; do for line in `cinder show $volume | grep 'os-vol-tenant-attr:tenant_id\| id ' | awk '{print $4}'`; do
echo -en " $line" >> $volume_ids echo -en " $line" >> $volume_ids
done done
echo "" >> $volume_ids echo "" >> $volume_ids
done done
awk '{print $2}' < $volume_ids | sort -u > $cinder_reported_tenants awk '{print $2}' < $volume_ids | sort -u > $cinder_reported_tenants
# get a list of all tenants, as reported by keystone # get a list of all tenants, as reported by keystone
@ -33,13 +33,13 @@ echo "+--------------------------------------+----------------------------------
echo "| volume_id | tenant_id | created_at | display_name | size | status |" echo "| volume_id | tenant_id | created_at | display_name | size | status |"
echo "+--------------------------------------+-----------------------------------+----------------------------+--------------+------+--------+" echo "+--------------------------------------+-----------------------------------+----------------------------+--------------+------+--------+"
for tenant_id in `comm --nocheck-order -13 $keystone_tenants $cinder_reported_tenants`; do for tenant_id in `comm --nocheck-order -13 $keystone_tenants $cinder_reported_tenants`; do
for volume_id in `grep $tenant_id $volume_ids | awk '{print $1}'`; do for volume_id in `grep $tenant_id $volume_ids | awk '{print $1}'`; do
echo -en "| $volume_id | $tenant_id |" echo -en "| $volume_id | $tenant_id |"
for attr in `cinder show $volume_id | grep ' status \| size \| display_name \| created_at ' | awk '{print $4}'`; do for attr in `cinder show $volume_id | grep ' status \| size \| display_name \| created_at ' | awk '{print $4}'`; do
echo -en " $attr |" echo -en " $attr |"
done done
echo "" echo ""
done done
done done
# cleanup after ourself # cleanup after ourself

View File

@ -13,23 +13,23 @@
#UUIDS="" #UUIDS=""
if [ -z "$UUIDS" ]; then if [ -z "$UUIDS" ]; then
echo "UUIDS value not defined" echo "UUIDS value not defined"
exit 1 exit 1
fi fi
for i in `virsh list --all | grep -E '^ [0-9-]+' | awk '{print $2;}'` ; do for i in `virsh list --all | grep -E '^ [0-9-]+' | awk '{print $2;}'` ; do
virsh dumpxml $i | grep "source file" | grep -E "$UUIDS" >/dev/null virsh dumpxml $i | grep "source file" | grep -E "$UUIDS" >/dev/null
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -n "+ $i is NOT known to OpenStack, removing managedsave info... " echo -n "+ $i is NOT known to OpenStack, removing managedsave info... "
[ ! -z "$1" ] && virsh managedsave-remove $i 1>/dev/null 2>&1 [ ! -z "$1" ] && virsh managedsave-remove $i 1>/dev/null 2>&1
echo -n "destroying VM... " echo -n "destroying VM... "
[ ! -z "$1" ] && virsh destroy $i 1>/dev/null 2>&1 [ ! -z "$1" ] && virsh destroy $i 1>/dev/null 2>&1
echo -n "undefining VM... " echo -n "undefining VM... "
[ ! -z "$1" ] && virsh undefine $i 1>/dev/null 2>&1 [ ! -z "$1" ] && virsh undefine $i 1>/dev/null 2>&1
echo DONE echo DONE
else else
echo "* $i is known to OpenStack, not removing." echo "* $i is known to OpenStack, not removing."
fi fi
done done

View File

@ -4,42 +4,35 @@
# If not then it will remove the vm from libvirt. This fixes the nova errors about disks missing from VM's # If not then it will remove the vm from libvirt. This fixes the nova errors about disks missing from VM's
# #
# Author: Kris Lindgren <klindgren@godaddy.com> # Author: Kris Lindgren <klindgren@godaddy.com>
#
removeorphan(){ removeorphan(){
local domain local domain
local tmp local tmp
domain=$1 domain=$1
tmp=$( virsh destroy $domain ) tmp=$( virsh destroy $domain )
tmp=$( virsh undefine $domain ) tmp=$( virsh undefine $domain )
tmp=$(virsh list --all | grep $domain ) tmp=$(virsh list --all | grep $domain )
if [ $? -eq 1 ] if [ $? -eq 1 ]; then
then tmp=$( ps auxwwwf | grep $domain | grep -v grep )
tmp=$( ps auxwwwf | grep $domain | grep -v grep ) if [ $? -eq 1 ]; then
if [ $? -eq 1 ] return 0
then fi
return 0 fi
fi return 1
fi
return 1
} }
for i in /etc/libvirt/qemu/*.xml for i in /etc/libvirt/qemu/*.xml; do
do disklocation=$( grep /var/lib/nova/instances $i | grep disk | cut -d"'" -f2,2)
disklocation=$( grep /var/lib/nova/instances $i | grep disk | cut -d"'" -f2,2) if [ ! -e $disklocation ]; then
if [ ! -e $disklocation ] orphan=$(echo $i | cut -d"/" -f5,5 | cut -d"." -f1,1)
then echo "$orphan does not have a disk located at: $disklocation"
orphan=$(echo $i | cut -d"/" -f5,5 | cut -d"." -f1,1) echo "This is an orphan of openstack... stopping the orphaned vm."
echo "$orphan does not have a disk located at: $disklocation" removeorphan $orphan
echo "This is an orphan of openstack... stopping the orphaned vm." if [ $? -eq 0 ]; then
removeorphan $orphan echo "Domain $orphan has been shutdown and removed"
if [ $? -eq 0 ] else
then echo "Domain $orphan has *NOT* been shutdown and removed"
echo "Domain $orphan has been shutdown and removed" fi
else fi
echo "Domain $orphan has *NOT* been shutdown and removed"
fi
fi
done done

View File

@ -3,10 +3,9 @@ source /root/scripts/stackrc
echo "$(date): Tenant quota correction - started" echo "$(date): Tenant quota correction - started"
for x in $(keystone --insecure tenant-list | awk -F' | ' '!/^\+/ && !/\ id\ / {print $2}'); for x in $(keystone --insecure tenant-list | awk -F' | ' '!/^\+/ && !/\ id\ / {print $2}'); do
do echo "Correcting quota for tenant $x"
echo "Correcting quota for tenant $x" python /root/scripts/auto-fix-quota.py --tenant $x
python /root/scripts/auto-fix-quota.py --tenant $x
done done
echo "$(date): Tenant quota correction - finished" echo "$(date): Tenant quota correction - finished"

View File

@ -7,7 +7,6 @@
# at https://bugs.launchpad.net/nova/+bug/1356534 # at https://bugs.launchpad.net/nova/+bug/1356534
# #
# Author: Mike Dorman <mdorman@godaddy.com> # Author: Mike Dorman <mdorman@godaddy.com>
#
cd /root cd /root
mkdir -p blank mkdir -p blank
@ -15,11 +14,10 @@ mkisofs -o blank.iso blank/ >/dev/null 2>&1
rmdir blank rmdir blank
for i in `ls /var/lib/nova/instances | grep -E '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}'`; do for i in `ls /var/lib/nova/instances | grep -E '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}'`; do
ls -l /var/lib/nova/instances/$i/disk.config ls -l /var/lib/nova/instances/$i/disk.config
if [ ! -s /var/lib/nova/instances/$i/disk.config ]; then if [ ! -s /var/lib/nova/instances/$i/disk.config ]; then
echo "$i config drive doesn't exist, or is size zero." echo "$i config drive doesn't exist, or is size zero."
cp -f /root/blank.iso /var/lib/nova/instances/$i/disk.config cp -f /root/blank.iso /var/lib/nova/instances/$i/disk.config
chown qemu:qemu /var/lib/nova/instances/$i/disk.config chown qemu:qemu /var/lib/nova/instances/$i/disk.config
fi fi
done done

View File

@ -4,17 +4,15 @@
# [Hypervisor Host] [UUID] [Status] [IP Address] [Name] # [Hypervisor Host] [UUID] [Status] [IP Address] [Name]
# #
# Author: Mike Dorman <mdorman@godaddy.com> # Author: Mike Dorman <mdorman@godaddy.com>
#
for i in `nova list --all-tenants | grep -v '^+-' | grep -v '^| ID' | awk '{print $2 "," $4 "," $6;}'`; do for i in `nova list --all-tenants | grep -v '^+-' | grep -v '^| ID' | awk '{print $2 "," $4 "," $6;}'`; do
ID=`echo $i | cut -d, -f 1` ID=`echo $i | cut -d, -f 1`
NAME=`echo $i | cut -d, -f 2` NAME=`echo $i | cut -d, -f 2`
STATUS=`echo $i | cut -d, -f 3` STATUS=`echo $i | cut -d, -f 3`
SHOW=`nova show ${ID}` SHOW=`nova show ${ID}`
HV=`echo "${SHOW}" | grep OS-EXT-SRV-ATTR:host | awk '{print $4;}'` HV=`echo "${SHOW}" | grep OS-EXT-SRV-ATTR:host | awk '{print $4;}'`
IP=`echo "${SHOW}" | grep " network" | awk '{print $5;}'` IP=`echo "${SHOW}" | grep " network" | awk '{print $5;}'`
echo -e "${HV}\t${ID}\t${STATUS}\t${IP}\t${NAME}"
echo -e "${HV}\t${ID}\t${STATUS}\t${IP}\t${NAME}"
done done

View File

@ -4,7 +4,6 @@
# was removed, but VMs were still in the tenant.) # was removed, but VMs were still in the tenant.)
# #
# Author: Kris Lindgren <klindgren@godaddy.com> # Author: Kris Lindgren <klindgren@godaddy.com>
#
echo "THIS SCRIPT NEED TO HAVE keystonerc sourced to work" echo "THIS SCRIPT NEED TO HAVE keystonerc sourced to work"
sleep 5 sleep 5
@ -19,14 +18,12 @@ novatenants=$( echo "$novavmsraw" | awk '{print $6}' | sort | uniq | grep -v Ten
echo "Starting to list vm's that are no longer attached to a tenant..." echo "Starting to list vm's that are no longer attached to a tenant..."
echo "Fields are:" echo "Fields are:"
echo "| VM ID | VM Name | Tenant Id | User Id |" echo "| VM ID | VM Name | Tenant Id | User Id |"
for i in $novatenants for i in $novatenants; do
do tmp=$( echo "$keystoneraw" | grep $i )
tmp=$( echo "$keystoneraw" | grep $i ) if [ $? -eq 0 ]; then
if [ $? -eq 0 ] continue
then else
continue vms=$( echo "$novavmsraw" | grep $i )
else echo "$vms"
vms=$( echo "$novavmsraw" | grep $i ) fi
echo "$vms"
fi
done done

View File

@ -26,80 +26,77 @@ unset DRY_RUN
# tables to arhive deleted records from # tables to arhive deleted records from
DATABASE=nova DATABASE=nova
TABLES="security_group_rules security_group_instance_association security_groups instance_info_caches instances reservations compute_node_stats" TABLES="security_group_rules security_group_instance_association security_groups instance_info_caches instance_system_metadata instances reservations compute_node_stats "
FKTABLES="block_device_mapping instance_metadata instance_system_metadata instance_actions instance_faults virtual_interfaces fixed_ips security_group_instance_association migrations instance_extra" FKTABLES="block_device_mapping instance_metadata instance_system_metadata instance_actions instance_faults virtual_interfaces fixed_ips security_group_instance_association migrations instance_extra"
TABLES="${TABLES} ${FKTABLES}" TABLES="${TABLES} ${FKTABLES}"
## process the command line arguments ## process the command line arguments
while getopts "hnad:H:u:p:" opt; do while getopts "hnd:H:u:p:" opt; do
case $opt in case $opt in
h) h)
echo "openstack_db_archive.sh - archive records flagged as deleted into the shadow tables." echo "openstack_db_archive.sh - archive records flagged as deleted into the shadow tables."
echo "Records are archived from the following tables:" echo "Records are archived from the following tables:"
echo echo
for TABLE in ${TABLES} for TABLE in ${TABLES}; do
do echo " ${DATABASE}.${TABLE}"
echo " ${DATABASE}.${TABLE}" done
done echo
echo echo "Options:"
echo "Options:" echo " -n dry run mode - pass --dry-run to pt-archiver"
echo " -n dry run mode - pass --dry-run to pt-archiver" echo " -d db name"
echo " -a no safe auto increment - pass --nosafe-auto-increment to pt-archiver" echo " -H db hostname"
echo " -d db name" echo " -u db username"
echo " -H db hostname" echo " -p db password"
echo " -u db username" echo " -h (show help)"
echo " -p db password" exit 0
echo " -h (show help)" ;;
exit 0 n)
;; DRY_RUN="--dry-run"
n) ;;
DRY_RUN="--dry-run" NOSAI="--nosafe-auto-increment"
;; ;;
a) d)
NOSAI="--nosafe-auto-increment" DATABASE=${OPTARG}
;; ;;
d) H)
DATABASE=${OPTARG} HOSTPT=",h=${OPTARG}"
;; HOST="-h ${OPTARG}"
H) ;;
HOSTPT=",h=${OPTARG}" u)
HOST="-h ${OPTARG}" USERPT=",u=${OPTARG}"
;; USER="-u ${OPTARG}"
u) ;;
USERPT=",u=${OPTARG}" p)
USER="-u ${OPTARG}" PASSPT=",p=${OPTARG}"
;; PASS="-p${OPTARG}"
p) ;;
PASSPT=",p=${OPTARG}" \?)
PASS="-p${OPTARG}" echo "Invalid option: -$OPTARG" >&2
;; exit 1
\?) ;;
echo "Invalid option: -$OPTARG" >&2 :)
exit 1 echo "Option -$OPTARG requires an argument." >&2
;; exit 1
:) ;;
echo "Option -$OPTARG requires an argument." >&2 esac
exit 1
;;
esac
done done
echo echo
echo `date` "OpenStack Database Archiver starting.." echo `date` "OpenStack Database Archiver starting.."
echo echo
echo `date` "Purging nova.instance_system_metadata of deleted instance data"
echo `date` "Purging nova.instance_actions_events of deleted instance data"
# this is back to front (on delete if you can find a record in instances flagged for deletion) # this is back to front (on delete if you can find a record in instances flagged for deletion)
# --where 'EXISTS(SELECT * FROM instance_actions, instances WHERE instance_actions.id=instance_actions_events.action_id AND instance_actions.instance_uuid=instances.uuid AND instances.deleted!=0)' # --where 'EXISTS(SELECT * FROM instances WHERE deleted!=0 AND uuid=instance_system_metadata.instance_uuid)'
# to delete where there is no active record:
# --where 'NOT EXISTS(SELECT * FROM instances WHERE deleted=0 AND uuid=instance_system_metadata.instance_uuid)'
TABLE=instance_actions_events TABLE=instance_system_metadata
SHADOW_TABLE="shadow_${TABLE}" SHADOW_TABLE="shadow_${TABLE}"
pt-archiver ${DRY_RUN} ${NOSAI} --statistics --sleep-coef 0.75 --progress 100 --commit-each --limit 10 \ pt-archiver ${DRY_RUN} --statistics --sleep-coef 0.75 --progress 100 --commit-each --limit 10 \
--source D=${DATABASE},t=${TABLE}${HOSTPT}${USERPT}${PASSPT} --no-check-charset \ --source D=${DATABASE},t=${TABLE}${HOSTPT}${USERPT}${PASSPT} --no-check-charset \
--dest D=${DATABASE},t=${SHADOW_TABLE}${HOSTPT}${USERPT}${PASSPT} \ --dest D=${DATABASE},t=${SHADOW_TABLE}${HOSTPT}${USERPT}${PASSPT} \
--where 'EXISTS(SELECT * FROM instance_actions, instances WHERE instance_actions.id=instance_actions_events.action_id AND instance_actions.instance_uuid=instances.uuid AND instances.deleted!=0)' --where 'EXISTS(SELECT * FROM instances WHERE deleted!=0 AND uuid=instance_system_metadata.instance_uuid)'
for TABLE in ${FKTABLES}; do for TABLE in ${FKTABLES}; do
echo `date` "Purging nova.${TABLE} of deleted instance data" echo `date` "Purging nova.${TABLE} of deleted instance data"
@ -115,35 +112,33 @@ for TABLE in ${FKTABLES}; do
--where 'EXISTS(SELECT * FROM instances WHERE deleted!=0 AND uuid='${TABLE}'.instance_uuid)' --where 'EXISTS(SELECT * FROM instances WHERE deleted!=0 AND uuid='${TABLE}'.instance_uuid)'
done done
for TABLE in ${TABLES}; do
SHADOW_TABLE="shadow_${TABLE}"
for TABLE in ${TABLES} ACTIVE_RECORDS=`mysql ${HOST} ${USER} ${PASS} -B -e "select count(id) from ${DATABASE}.${TABLE} where deleted=0" | tail -1`
do DELETED_RECORDS=`mysql ${HOST} ${USER} ${PASS} -B -e "select count(id) from ${DATABASE}.${TABLE} where deleted!=0" | tail -1`
SHADOW_TABLE="shadow_${TABLE}"
ACTIVE_RECORDS=`mysql ${HOST} ${USER} ${PASS} -B -e "select count(id) from ${DATABASE}.${TABLE} where deleted=0" | tail -1` LOCAL_ABORTS=`mysql ${HOST} ${USER} ${PASS} -B -e "SHOW STATUS LIKE 'wsrep_%'" | grep -e wsrep_local_bf_aborts -e wsrep_local_cert_failures`
DELETED_RECORDS=`mysql ${HOST} ${USER} ${PASS} -B -e "select count(id) from ${DATABASE}.${TABLE} where deleted!=0" | tail -1`
LOCAL_ABORTS=`mysql ${HOST} ${USER} ${PASS} -B -e "SHOW STATUS LIKE 'wsrep_%'" | grep -e wsrep_local_bf_aborts -e wsrep_local_cert_failures` echo
echo
echo `date` "Archiving ${DELETED_RECORDS} records to ${SHADOW_TABLE} from ${TABLE}, leaving ${ACTIVE_RECORDS}"
echo `date` "LOCAL_ABORTS before"
echo ${LOCAL_ABORTS}
echo pt-archiver ${DRY_RUN} --statistics --progress 100 --commit-each --limit 10 \
echo --source D=${DATABASE},t=${TABLE}${HOSTPT}${USERPT}${PASSPT} \
echo `date` "Archiving ${DELETED_RECORDS} records to ${SHADOW_TABLE} from ${TABLE}, leaving ${ACTIVE_RECORDS}" --dest D=${DATABASE},t=${SHADOW_TABLE}${HOSTPT}${USERPT}${PASSPT} \
echo `date` "LOCAL_ABORTS before" --ignore --no-check-charset --sleep-coef 0.75 \
echo ${LOCAL_ABORTS} --where "deleted!=0"
pt-archiver ${DRY_RUN} ${NOSAI} --statistics --progress 100 --commit-each --limit 10 \ echo `date` "Finished archiving ${DELETED_RECORDS} to ${SHADOW_TABLE} from ${TABLE}"
--source D=${DATABASE},t=${TABLE}${HOSTPT}${USERPT}${PASSPT} \ echo `date` "LOCAL_ABORTS before"
--dest D=${DATABASE},t=${SHADOW_TABLE}${HOSTPT}${USERPT}${PASSPT} \ echo ${LOCAL_ABORTS}
--ignore --no-check-charset --sleep-coef 0.75 \ LOCAL_ABORTS=`mysql ${HOST} ${USER} ${PASS} -B -e "SHOW STATUS LIKE 'wsrep_%'" | grep -e wsrep_local_bf_aborts -e wsrep_local_cert_failures`
--where "deleted!=0" echo `date` "LOCAL_ABORTS after"
echo ${LOCAL_ABORTS}
echo `date` "Finished archiving ${DELETED_RECORDS} to ${SHADOW_TABLE} from ${TABLE}" echo
echo `date` "LOCAL_ABORTS before"
echo ${LOCAL_ABORTS}
LOCAL_ABORTS=`mysql ${HOST} ${USER} ${PASS} -B -e "SHOW STATUS LIKE 'wsrep_%'" | grep -e wsrep_local_bf_aborts -e wsrep_local_cert_failures`
echo `date` "LOCAL_ABORTS after"
echo ${LOCAL_ABORTS}
echo
done done
echo echo

View File

@ -17,41 +17,38 @@
# under the License. # under the License.
# Report on the current state of unarchived records in the main nova.* tables # Report on the current state of unarchived records in the main nova.* tables
#
DATABASE=nova DATABASE=nova
FKTABLES="block_device_mapping instance_metadata instance_system_metadata instance_actions instance_faults virtual_interfaces fixed_ips security_group_instance_association migrations instance_extra" FKTABLES="block_device_mapping instance_metadata instance_system_metadata instance_actions instance_faults virtual_interfaces fixed_ips security_group_instance_association migrations instance_extra"
TABLES="${TABLES} ${FKTABLES}" TABLES="${TABLES} ${FKTABLES}"
function usage() { function usage {
echo "$0: Report on the current state of unarchived records in the main nova.* tables" echo "$0: Report on the current state of unarchived records in the main nova.* tables"
echo "Usage: $0 -d [database] -H [hostname] -u [username] -p [password]" echo "Usage: $0 -d [database] -H [hostname] -u [username] -p [password]"
} }
while getopts "d:H:u:p:" opt; do while getopts "d:H:u:p:" opt; do
case $opt in case $opt in
d) d)
DATABASE=${OPTARG} DATABASE=${OPTARG}
;; ;;
H) H)
HOST="-h ${OPTARG}" HOST="-h ${OPTARG}"
;; ;;
u) u)
USER="-u ${OPTARG}" USER="-u ${OPTARG}"
;; ;;
p) p)
PASS="-p${OPTARG}" PASS="-p${OPTARG}"
;; ;;
*) *)
usage usage
exit 1 exit 1
;; ;;
esac esac
done done
for TABLE in ${TABLES} for TABLE in ${TABLES}; do
do
SHADOW_TABLE="shadow_${TABLE}" SHADOW_TABLE="shadow_${TABLE}"
ACTIVE_RECORDS=`mysql ${HOST} ${USER} ${PASS} -B -e "select count(id) from ${DATABASE}.${TABLE} where deleted=0" | tail -1` ACTIVE_RECORDS=`mysql ${HOST} ${USER} ${PASS} -B -e "select count(id) from ${DATABASE}.${TABLE} where deleted=0" | tail -1`

View File

@ -2,8 +2,8 @@
# OpenStack credentials are expected to be in your environment variables # OpenStack credentials are expected to be in your environment variables
if [ -z "$OS_AUTH_URL" -o -z "$OS_PASSWORD" -o -z "$OS_USERNAME" ]; then if [ -z "$OS_AUTH_URL" -o -z "$OS_PASSWORD" -o -z "$OS_USERNAME" ]; then
echo "Please set OpenStack auth environment variables." echo "Please set OpenStack auth environment variables."
exit 1 exit 1
fi fi
# temp files used for caching outputs # temp files used for caching outputs
@ -15,9 +15,9 @@ echo -en "Retrieving list of all VMs...\r"
nova list --all-tenants --fields tenant_id | tail -n +4 | awk '{print $4}' | sort -u > $vm_tenants nova list --all-tenants --fields tenant_id | tail -n +4 | awk '{print $4}' | sort -u > $vm_tenants
total_vms=$(cat $vm_tenants | wc -l) total_vms=$(cat $vm_tenants | wc -l)
if [ $total_vms == 0 ]; then if [ $total_vms == 0 ]; then
echo "Zero VMs found. Exiting..." echo "Zero VMs found. Exiting..."
rm -f $vm_tenants $keystone_tenants rm -f $vm_tenants $keystone_tenants
exit 1 exit 1
fi fi
# get a list of all tenants/projects in the cluster # get a list of all tenants/projects in the cluster
@ -25,9 +25,9 @@ echo -en "Retrieving list of all tenants...\r"
keystone tenant-list | tail -n +4 | awk '{print $2}' | sort -u > $keystone_tenants keystone tenant-list | tail -n +4 | awk '{print $2}' | sort -u > $keystone_tenants
total_tenants=$(cat $keystone_tenants | wc -l) total_tenants=$(cat $keystone_tenants | wc -l)
if [ $total_tenants == 0 ]; then if [ $total_tenants == 0 ]; then
echo "Zero tenants found. Exiting..." echo "Zero tenants found. Exiting..."
rm -f $vm_tenants $keystone_tenants rm -f $vm_tenants $keystone_tenants
exit 1 exit 1
fi fi
# compare all VM owners to all tenants as reported by keystone and print # compare all VM owners to all tenants as reported by keystone and print
@ -35,12 +35,12 @@ fi
echo -en "Comparing outputs to locate orphaned VMs....\r" echo -en "Comparing outputs to locate orphaned VMs....\r"
iter=0 iter=0
for tenant_id in `comm --nocheck-order -13 $keystone_tenants $vm_tenants`; do for tenant_id in `comm --nocheck-order -13 $keystone_tenants $vm_tenants`; do
if [[ $iter == 0 ]]; then if [[ $iter == 0 ]]; then
nova list --all-tenants --tenant=$tenant_id --fields tenant_id,name,status,created,updated | head -n -1 nova list --all-tenants --tenant=$tenant_id --fields tenant_id,name,status,created,updated | head -n -1
let "iter++" let "iter++"
else else
nova list --all-tenants --tenant=$tenant_id --fields tenant_id,name,status,created,updated | tail -n +4 | head -n -1 nova list --all-tenants --tenant=$tenant_id --fields tenant_id,name,status,created,updated | tail -n +4 | head -n -1
fi fi
done done
# cleanup after ourself # cleanup after ourself