Created
February 27, 2018 03:36
-
-
Save ljjjustin/6da7da90c9a4146bb26033aa1c592928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "usage: $0 <volume id>" | |
fi | |
volume_id=$1 | |
## check if volume exists | |
if cinder show ${volume_id} | grep -q 'No volume'; then | |
echo "${volume_id} don't exist, exit.." | |
exit | |
fi | |
## detach if server exists | |
server_id=$(mysql -e "select instance_uuid from cinder.volume_attachment where deleted=0 and volume_id='${volume_id}'" | sed -e '1d' | awk '{print $1}') | |
if nova show ${server_id} | grep -q ' image '; then | |
nova volume-detach ${server_id} ${volume_id} | |
sleep 5 | |
fi | |
## clean attachment | |
mysql -e "update cinder.volume_attachment set deleted=1, attach_status='detached' where deleted=0 and volume_id='${volume_id}'" | |
## set to available status | |
cinder reset-state ${volume_id} --state available --attach-status detached | |
## delete volume | |
cinder delete ${volume_id} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment