
Fixing https://bugs.launchpad.net/osops/+bug/1534660. Some of these fixes are not pretty and I've not been able to test the tools still work. I think the bashate rules should be relaxed for operations tools ... or people shouldn't use bash for such tools. Sometimes it's pretty difficult to shorten lines and still have readable code. Co-Authored-By: Peter Jenkins <mail@peter-jenkins.com> Co-Authored-By: Mike Dorman <mdorman@godaddy.com> Change-Id: I70cfc2420cc9a2a4ec553ab7b7ca43a7fc38a9f0
41 lines
1.2 KiB
Bash
Executable File
41 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# This script will look at the configured vm's and will check to make sure that
|
|
# their disk drive still exists, If not then it will remove the vm from
|
|
# libvirt. This fixes the nova errors about disks missing from VM's
|
|
#
|
|
# Author: Kris Lindgren <klindgren@godaddy.com>
|
|
|
|
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
|
|
}
|
|
|
|
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
|