diff --git a/cinder/orphaned_volumes.sh b/cinder/orphaned_volumes.sh index 9546da0..19e57fe 100755 --- a/cinder/orphaned_volumes.sh +++ b/cinder/orphaned_volumes.sh @@ -2,8 +2,8 @@ # OpenStack credentialss are expected to be in your environment variables if [ -z "$OS_AUTH_URL" -o -z "$OS_PASSWORD" -o -z "$OS_USERNAME" ]; then - echo "Please set OpenStack auth environment variables." - exit 1 + echo "Please set OpenStack auth environment variables." + exit 1 fi # temp files for caching outputs @@ -16,11 +16,11 @@ final_report=$(mktemp) echo -en "Retrieving list of all volumes...\r" # oh cinder... 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 - echo -en " $line" >> $volume_ids - done - echo "" >> $volume_ids -done + for line in `cinder show $volume | grep 'os-vol-tenant-attr:tenant_id\| id ' | awk '{print $4}'`; do + echo -en " $line" >> $volume_ids + done + echo "" >> $volume_ids +done awk '{print $2}' < $volume_ids | sort -u > $cinder_reported_tenants # 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 "+--------------------------------------+-----------------------------------+----------------------------+--------------+------+--------+" 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 - echo -en "| $volume_id | $tenant_id |" - for attr in `cinder show $volume_id | grep ' status \| size \| display_name \| created_at ' | awk '{print $4}'`; do - echo -en " $attr |" - done - echo "" - done + for volume_id in `grep $tenant_id $volume_ids | awk '{print $1}'`; do + echo -en "| $volume_id | $tenant_id |" + for attr in `cinder show $volume_id | grep ' status \| size \| display_name \| created_at ' | awk '{print $4}'`; do + echo -en " $attr |" + done + echo "" + done done # cleanup after ourself diff --git a/libvirt/cleanup-orphaned-vms.sh b/libvirt/cleanup-orphaned-vms.sh index e153ce0..23f5725 100755 --- a/libvirt/cleanup-orphaned-vms.sh +++ b/libvirt/cleanup-orphaned-vms.sh @@ -13,23 +13,23 @@ #UUIDS="" if [ -z "$UUIDS" ]; then - echo "UUIDS value not defined" - exit 1 + echo "UUIDS value not defined" + exit 1 fi 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 - if [ $? -ne 0 ]; then - echo -n "+ $i is NOT known to OpenStack, removing managedsave info... " - [ ! -z "$1" ] && virsh managedsave-remove $i 1>/dev/null 2>&1 - echo -n "destroying VM... " - [ ! -z "$1" ] && virsh destroy $i 1>/dev/null 2>&1 - echo -n "undefining VM... " - [ ! -z "$1" ] && virsh undefine $i 1>/dev/null 2>&1 - echo DONE - else - echo "* $i is known to OpenStack, not removing." - fi + virsh dumpxml $i | grep "source file" | grep -E "$UUIDS" >/dev/null + if [ $? -ne 0 ]; then + echo -n "+ $i is NOT known to OpenStack, removing managedsave info... " + [ ! -z "$1" ] && virsh managedsave-remove $i 1>/dev/null 2>&1 + echo -n "destroying VM... " + [ ! -z "$1" ] && virsh destroy $i 1>/dev/null 2>&1 + echo -n "undefining VM... " + [ ! -z "$1" ] && virsh undefine $i 1>/dev/null 2>&1 + echo DONE + else + echo "* $i is known to OpenStack, not removing." + fi done diff --git a/libvirt/remove-deleted-orphans.sh b/libvirt/remove-deleted-orphans.sh index d311526..0a00d4d 100755 --- a/libvirt/remove-deleted-orphans.sh +++ b/libvirt/remove-deleted-orphans.sh @@ -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 # # Author: Kris Lindgren -# removeorphan(){ - local domain - local tmp - domain=$1 - - tmp=$( virsh destroy $domain ) - tmp=$( virsh undefine $domain ) - tmp=$(virsh list --all | grep $domain ) - if [ $? -eq 1 ] - then - tmp=$( ps auxwwwf | grep $domain | grep -v grep ) - if [ $? -eq 1 ] - then - return 0 - fi - fi - return 1 - + local domain + local tmp + domain=$1 + + tmp=$( virsh destroy $domain ) + tmp=$( virsh undefine $domain ) + tmp=$(virsh list --all | grep $domain ) + if [ $? -eq 1 ]; then + tmp=$( ps auxwwwf | grep $domain | grep -v grep ) + if [ $? -eq 1 ]; then + return 0 + fi + fi + return 1 } - -for i in /etc/libvirt/qemu/*.xml -do - disklocation=$( grep /var/lib/nova/instances $i | grep disk | cut -d"'" -f2,2) - if [ ! -e $disklocation ] - then - orphan=$(echo $i | cut -d"/" -f5,5 | cut -d"." -f1,1) - echo "$orphan does not have a disk located at: $disklocation" - echo "This is an orphan of openstack... stopping the orphaned vm." - removeorphan $orphan - if [ $? -eq 0 ] - then - echo "Domain $orphan has been shutdown and removed" - else - echo "Domain $orphan has *NOT* been shutdown and removed" - fi - fi + +for i in /etc/libvirt/qemu/*.xml; do + disklocation=$( grep /var/lib/nova/instances $i | grep disk | cut -d"'" -f2,2) + if [ ! -e $disklocation ]; then + orphan=$(echo $i | cut -d"/" -f5,5 | cut -d"." -f1,1) + echo "$orphan does not have a disk located at: $disklocation" + echo "This is an orphan of openstack... stopping the orphaned vm." + removeorphan $orphan + if [ $? -eq 0 ]; then + echo "Domain $orphan has been shutdown and removed" + else + echo "Domain $orphan has *NOT* been shutdown and removed" + fi + fi done diff --git a/nova/auto-fix-quota-all-tenants.sh b/nova/auto-fix-quota-all-tenants.sh index d6a8c37..2acb718 100755 --- a/nova/auto-fix-quota-all-tenants.sh +++ b/nova/auto-fix-quota-all-tenants.sh @@ -3,10 +3,9 @@ source /root/scripts/stackrc echo "$(date): Tenant quota correction - started" -for x in $(keystone --insecure tenant-list | awk -F' | ' '!/^\+/ && !/\ id\ / {print $2}'); -do - echo "Correcting quota for tenant $x" - python /root/scripts/auto-fix-quota.py --tenant $x +for x in $(keystone --insecure tenant-list | awk -F' | ' '!/^\+/ && !/\ id\ / {print $2}'); do + echo "Correcting quota for tenant $x" + python /root/scripts/auto-fix-quota.py --tenant $x done echo "$(date): Tenant quota correction - finished" diff --git a/nova/backfillconfigdrive.sh b/nova/backfillconfigdrive.sh index 0f6c7c6..08b77cd 100644 --- a/nova/backfillconfigdrive.sh +++ b/nova/backfillconfigdrive.sh @@ -7,7 +7,6 @@ # at https://bugs.launchpad.net/nova/+bug/1356534 # # Author: Mike Dorman -# cd /root mkdir -p blank @@ -15,11 +14,10 @@ mkisofs -o blank.iso blank/ >/dev/null 2>&1 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 - ls -l /var/lib/nova/instances/$i/disk.config - if [ ! -s /var/lib/nova/instances/$i/disk.config ]; then - echo "$i config drive doesn't exist, or is size zero." - cp -f /root/blank.iso /var/lib/nova/instances/$i/disk.config - chown qemu:qemu /var/lib/nova/instances/$i/disk.config - fi + ls -l /var/lib/nova/instances/$i/disk.config + if [ ! -s /var/lib/nova/instances/$i/disk.config ]; then + echo "$i config drive doesn't exist, or is size zero." + cp -f /root/blank.iso /var/lib/nova/instances/$i/disk.config + chown qemu:qemu /var/lib/nova/instances/$i/disk.config + fi done - diff --git a/nova/list-vms-by-host.sh b/nova/list-vms-by-host.sh index 70dc8f4..bc04a78 100644 --- a/nova/list-vms-by-host.sh +++ b/nova/list-vms-by-host.sh @@ -4,17 +4,15 @@ # [Hypervisor Host] [UUID] [Status] [IP Address] [Name] # # Author: Mike Dorman -# 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` - NAME=`echo $i | cut -d, -f 2` - STATUS=`echo $i | cut -d, -f 3` + ID=`echo $i | cut -d, -f 1` + NAME=`echo $i | cut -d, -f 2` + STATUS=`echo $i | cut -d, -f 3` - SHOW=`nova show ${ID}` - HV=`echo "${SHOW}" | grep OS-EXT-SRV-ATTR:host | awk '{print $4;}'` - IP=`echo "${SHOW}" | grep " network" | awk '{print $5;}'` - - echo -e "${HV}\t${ID}\t${STATUS}\t${IP}\t${NAME}" + SHOW=`nova show ${ID}` + HV=`echo "${SHOW}" | grep OS-EXT-SRV-ATTR:host | awk '{print $4;}'` + IP=`echo "${SHOW}" | grep " network" | awk '{print $5;}'` + echo -e "${HV}\t${ID}\t${STATUS}\t${IP}\t${NAME}" done diff --git a/nova/list-vms-without-tenants.sh b/nova/list-vms-without-tenants.sh index eebd9cd..316663f 100755 --- a/nova/list-vms-without-tenants.sh +++ b/nova/list-vms-without-tenants.sh @@ -4,7 +4,6 @@ # was removed, but VMs were still in the tenant.) # # Author: Kris Lindgren -# echo "THIS SCRIPT NEED TO HAVE keystonerc sourced to work" 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 "Fields are:" echo "| VM ID | VM Name | Tenant Id | User Id |" -for i in $novatenants -do - tmp=$( echo "$keystoneraw" | grep $i ) - if [ $? -eq 0 ] - then - continue - else - vms=$( echo "$novavmsraw" | grep $i ) - echo "$vms" - fi +for i in $novatenants; do + tmp=$( echo "$keystoneraw" | grep $i ) + if [ $? -eq 0 ]; then + continue + else + vms=$( echo "$novavmsraw" | grep $i ) + echo "$vms" + fi done diff --git a/nova/openstack_db_archive.sh b/nova/openstack_db_archive.sh index 64d9411..8a439e3 100755 --- a/nova/openstack_db_archive.sh +++ b/nova/openstack_db_archive.sh @@ -32,63 +32,61 @@ TABLES="${TABLES} ${FKTABLES}" ## process the command line arguments while getopts "hnad:H:u:p:" opt; do - case $opt in - h) - echo "openstack_db_archive.sh - archive records flagged as deleted into the shadow tables." - echo "Records are archived from the following tables:" - echo - for TABLE in ${TABLES} - do - echo " ${DATABASE}.${TABLE}" - done - echo - echo "Options:" - echo " -n dry run mode - pass --dry-run to pt-archiver" - echo " -a no safe auto increment - pass --nosafe-auto-increment to pt-archiver" - echo " -d db name" - echo " -H db hostname" - echo " -u db username" - echo " -p db password" - echo " -h (show help)" - exit 0 - ;; - n) - DRY_RUN="--dry-run" - ;; - a) - NOSAI="--nosafe-auto-increment" - ;; - d) - DATABASE=${OPTARG} - ;; - H) - HOSTPT=",h=${OPTARG}" - HOST="-h ${OPTARG}" - ;; - u) - USERPT=",u=${OPTARG}" - USER="-u ${OPTARG}" - ;; - p) - PASSPT=",p=${OPTARG}" - PASS="-p${OPTARG}" - ;; - \?) - echo "Invalid option: -$OPTARG" >&2 - exit 1 - ;; - :) - echo "Option -$OPTARG requires an argument." >&2 - exit 1 - ;; - esac + case $opt in + h) + echo "openstack_db_archive.sh - archive records flagged as deleted into the shadow tables." + echo "Records are archived from the following tables:" + echo + for TABLE in ${TABLES}; do + echo " ${DATABASE}.${TABLE}" + done + echo + echo "Options:" + echo " -n dry run mode - pass --dry-run to pt-archiver" + echo " -a no safe auto increment - pass --nosafe-auto-increment to pt-archiver" + echo " -d db name" + echo " -H db hostname" + echo " -u db username" + echo " -p db password" + echo " -h (show help)" + exit 0 + ;; + n) + DRY_RUN="--dry-run" + ;; + a) + NOSAI="--nosafe-auto-increment" + ;; + d) + DATABASE=${OPTARG} + ;; + H) + HOSTPT=",h=${OPTARG}" + HOST="-h ${OPTARG}" + ;; + u) + USERPT=",u=${OPTARG}" + USER="-u ${OPTARG}" + ;; + p) + PASSPT=",p=${OPTARG}" + PASS="-p${OPTARG}" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac done echo echo `date` "OpenStack Database Archiver starting.." echo - 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) # --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)' @@ -96,10 +94,9 @@ echo `date` "Purging nova.instance_actions_events of deleted instance data" TABLE=instance_actions_events SHADOW_TABLE="shadow_${TABLE}" pt-archiver ${DRY_RUN} ${NOSAI} --statistics --sleep-coef 0.75 --progress 100 --commit-each --limit 10 \ - --source D=${DATABASE},t=${TABLE}${HOSTPT}${USERPT}${PASSPT} --no-check-charset \ - --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)' - + --source D=${DATABASE},t=${TABLE}${HOSTPT}${USERPT}${PASSPT} --no-check-charset \ + --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)' for TABLE in ${FKTABLES}; do 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)' done +for TABLE in ${TABLES}; do + SHADOW_TABLE="shadow_${TABLE}" -for TABLE in ${TABLES} -do - SHADOW_TABLE="shadow_${TABLE}" + ACTIVE_RECORDS=`mysql ${HOST} ${USER} ${PASS} -B -e "select count(id) from ${DATABASE}.${TABLE} where deleted=0" | tail -1` + DELETED_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` - 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` - 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 - echo - echo `date` "Archiving ${DELETED_RECORDS} records to ${SHADOW_TABLE} from ${TABLE}, leaving ${ACTIVE_RECORDS}" - echo `date` "LOCAL_ABORTS before" - echo ${LOCAL_ABORTS} + pt-archiver ${DRY_RUN} ${NOSAI} --statistics --progress 100 --commit-each --limit 10 \ + --source D=${DATABASE},t=${TABLE}${HOSTPT}${USERPT}${PASSPT} \ + --dest D=${DATABASE},t=${SHADOW_TABLE}${HOSTPT}${USERPT}${PASSPT} \ + --ignore --no-check-charset --sleep-coef 0.75 \ + --where "deleted!=0" - pt-archiver ${DRY_RUN} ${NOSAI} --statistics --progress 100 --commit-each --limit 10 \ - --source D=${DATABASE},t=${TABLE}${HOSTPT}${USERPT}${PASSPT} \ - --dest D=${DATABASE},t=${SHADOW_TABLE}${HOSTPT}${USERPT}${PASSPT} \ - --ignore --no-check-charset --sleep-coef 0.75 \ - --where "deleted!=0" - - echo `date` "Finished archiving ${DELETED_RECORDS} to ${SHADOW_TABLE} from ${TABLE}" - 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 + echo `date` "Finished archiving ${DELETED_RECORDS} to ${SHADOW_TABLE} from ${TABLE}" + 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 echo diff --git a/nova/openstack_db_archive_progress.sh b/nova/openstack_db_archive_progress.sh index aaf050f..30f0bf3 100755 --- a/nova/openstack_db_archive_progress.sh +++ b/nova/openstack_db_archive_progress.sh @@ -17,41 +17,38 @@ # under the License. # Report on the current state of unarchived records in the main nova.* tables -# - 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" TABLES="${TABLES} ${FKTABLES}" -function usage() { - 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]" +function usage { + 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]" } while getopts "d:H:u:p:" opt; do - case $opt in - d) - DATABASE=${OPTARG} - ;; - H) - HOST="-h ${OPTARG}" - ;; - u) - USER="-u ${OPTARG}" - ;; - p) - PASS="-p${OPTARG}" - ;; - *) - usage - exit 1 - ;; - esac + case $opt in + d) + DATABASE=${OPTARG} + ;; + H) + HOST="-h ${OPTARG}" + ;; + u) + USER="-u ${OPTARG}" + ;; + p) + PASS="-p${OPTARG}" + ;; + *) + usage + exit 1 + ;; + esac done -for TABLE in ${TABLES} -do +for TABLE in ${TABLES}; do SHADOW_TABLE="shadow_${TABLE}" ACTIVE_RECORDS=`mysql ${HOST} ${USER} ${PASS} -B -e "select count(id) from ${DATABASE}.${TABLE} where deleted=0" | tail -1` diff --git a/nova/orphaned_vms.sh b/nova/orphaned_vms.sh index a1d2144..82234d4 100755 --- a/nova/orphaned_vms.sh +++ b/nova/orphaned_vms.sh @@ -2,8 +2,8 @@ # OpenStack credentials are expected to be in your environment variables if [ -z "$OS_AUTH_URL" -o -z "$OS_PASSWORD" -o -z "$OS_USERNAME" ]; then - echo "Please set OpenStack auth environment variables." - exit 1 + echo "Please set OpenStack auth environment variables." + exit 1 fi # 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 total_vms=$(cat $vm_tenants | wc -l) if [ $total_vms == 0 ]; then - echo "Zero VMs found. Exiting..." - rm -f $vm_tenants $keystone_tenants - exit 1 + echo "Zero VMs found. Exiting..." + rm -f $vm_tenants $keystone_tenants + exit 1 fi # 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 total_tenants=$(cat $keystone_tenants | wc -l) if [ $total_tenants == 0 ]; then - echo "Zero tenants found. Exiting..." - rm -f $vm_tenants $keystone_tenants - exit 1 + echo "Zero tenants found. Exiting..." + rm -f $vm_tenants $keystone_tenants + exit 1 fi # 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" iter=0 for tenant_id in `comm --nocheck-order -13 $keystone_tenants $vm_tenants`; do - if [[ $iter == 0 ]]; then - nova list --all-tenants --tenant=$tenant_id --fields tenant_id,name,status,created,updated | head -n -1 - let "iter++" - else - nova list --all-tenants --tenant=$tenant_id --fields tenant_id,name,status,created,updated | tail -n +4 | head -n -1 - fi + if [[ $iter == 0 ]]; then + nova list --all-tenants --tenant=$tenant_id --fields tenant_id,name,status,created,updated | head -n -1 + let "iter++" + else + nova list --all-tenants --tenant=$tenant_id --fields tenant_id,name,status,created,updated | tail -n +4 | head -n -1 + fi done # cleanup after ourself