Created
January 9, 2020 19:51
-
-
Save scottlinux/cc64fdb024695cc8ba0e9b53b9b20ea1 to your computer and use it in GitHub Desktop.
Delete openstack instance stuck in error state
This file contains hidden or 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
#!/usr/bin/env bash | |
# | |
# Delete RHOS instance stuck in error state | |
# | |
set -e | |
# prompt for instance ID to delete | |
printf "\n" | |
printf 'Enter one instance ID to delete:' | |
printf "\n" | |
read -r instance | |
if [ "$instance" == n ] ; then | |
exit | |
else | |
# here we go! | |
printf '\n' | |
printf 'Deleting instance %s' $instance | |
printf '\n' | |
# reset instance state | |
nova reset-state --active "$instance" | |
# get port and trunk info | |
port="$(openstack port show $(openstack port list --server "$instance" -f value -c ID) -f value -c id)" | |
trunk="$(openstack port show $(openstack port list --server "$instance" -f value -c ID) -f value -c trunk_details | awk '{print $2}' | cut -c4-38)" | |
# unbind port | |
neutron port-update "$port" --device_owner "" --device_id "" --binding:host-id "" || true | |
# delete the instance | |
openstack server delete "$instance" | |
printf '\n' | |
printf 'Deleting trunk and port if applicable. Ignore errors if no trunk' | |
printf '\n' | |
# delete the trunk and port | |
openstack network trunk delete "$trunk" || true | |
openstack port delete "$port" || true | |
printf '\n' | |
printf 'Done!' | |
printf '\n' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment