Skip to content

Instantly share code, notes, and snippets.

@dosaboy
Created April 12, 2016 18:45
Show Gist options
  • Save dosaboy/d86517011096e8c5e3679044953af6a6 to your computer and use it in GitHub Desktop.
Save dosaboy/d86517011096e8c5e3679044953af6a6 to your computer and use it in GitHub Desktop.
#!/bin/bash -eux
read -a instances<<<`nova list --all-tenants| grep -Ev "$\+\-\-+|\sID\s"| awk '{print $2}'| sed '/^$/d'`
echo ${#instances[@]} instances to be deleted
for vm in ${instances[@]}; do
echo "Deleting instance $vm"
#nova delete $vm && continue
read -p "Soft delete instance failed. Try hard delete? [Y,n] " answer
if [ -z "$answer" ] || [ ${answer,,} = "y" ]; then
#nova force-delete $vm
:
fi
done
attached=`cinder list --all-tenants| grep -Ev "$\+\-\-+|\sID\s"| awk '{print $14}'| grep -Ev "\|"| sed '/^$/d'`
for vm in ${attached[@]}; do
read -a a_vols<<<`cinder list --all-tenants| grep $vm| awk '{print $2}'`
if ((${#a_vols[@]})); then
echo "Vol(s) ${a_vols[@]} are still attached to vm $vm"
fi
done
read -a vols<<<`cinder list --all-tenants| grep -Ev "$\+\-\-+|\sID\s"| awk '{print $2}'| sed '/^$/d'`
echo ${#vols[@]} vols to be deleted
for vol in ${vols[@]}; do
echo "Deleting volume $vol"
#cinder delete $vol && continue
read -p "Soft delete volume failed. Try hard delete? [Y,n] " answer
if [ -z "$answer" ] || [ ${answer,,} = "y" ]; then
#cinder force-delete $vol
:
fi
done
read -a images<<<`glance image-list| grep -Ev "$\+\-\-+|\sID\s"| awk '{print $2}'| sed '/^$/d'`
echo ${#images[@]} images to be deleted
for image in ${image[@]}; do
echo "Deleting image $image"
#glance image-delete $image
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment