Remove failing VMs in OpenStack

Occasionally OpenStack VMs fail to spawn or fail to terminate and cannot be removed from the VM list. Deleting the VM using the command line or web interface has no effect, they are stuck in the “spawning” or “deleting” state. To get rid of these zombie entries I remove them from the database using the following bash script (pass the machine UUID as parameter):

mysql -uroot -ppassword << EOF
use nova;
DELETE a FROM nova.security_group_instance_association AS a INNER JOIN nova.instances AS b ON where b.uuid='$1';
DELETEĀ FROM nova.instance_info_caches WHERE instance_id='$1';
DELETEĀ FROM nova.instances WHERE uuid='$1';