Review uuid verification method

Previous method verify if line that contain "source file"
exists into dumpxml of every virtual machine to extract
uuid of virtual machines running on hypervisor but this
line exists only when a disk file is present on the host
and boot from volumes for example has not "source file" line
into dumpxml and this script will kill them.
To avoid theese case it should be possible to use
'virsh list --uuid --all' to list directly the virtual machine
uuids of nova instances.
This changes avoid to shut running customer virtual machines.

This also fixes handling of --noop by correcting the condition checking
for arguments.

Change-Id: Ib9ec04a37bfe69e323f14f6bf4cb72b0fa818803
Closes-Bug: #1816434
Signed-off-by: Davide Panarese <dpanarese@enter.it>
This commit is contained in:
Davide Panarese 2019-01-25 12:23:30 +01:00 committed by Sean McGinnis
parent 73953ddb5e
commit e2275cbf6d
1 changed files with 7 additions and 9 deletions

View File

@ -17,19 +17,17 @@ if [ -z "$UUIDS" ]; then
exit 1
fi
for i in `virsh list --all | grep -E '^ [0-9-]+' | awk '{print $2;}'` ; do
virsh dumpxml $i | grep "source file" | grep -E "$UUIDS" >/dev/null
for vm-uuid in `virsh list --uuid --all` ; do
echo $vm-uuid | grep -E "$UUIDS" >/dev/null
if [ $? -ne 0 ]; then
echo -n "+ $i is NOT known to OpenStack, removing managedsave info... "
[ ! -z "$1" ] && virsh managedsave-remove $i 1>/dev/null 2>&1
echo -n "+ $vm-uuid is NOT known to OpenStack, removing managedsave info... "
[ -z "$1" ] && virsh managedsave-remove $vm-uuid 1>/dev/null 2>&1
echo -n "destroying VM... "
[ ! -z "$1" ] && virsh destroy $i 1>/dev/null 2>&1
[ -z "$1" ] && virsh destroy $vm-uuid 1>/dev/null 2>&1
echo -n "undefining VM... "
[ ! -z "$1" ] && virsh undefine $i 1>/dev/null 2>&1
[ -z "$1" ] && virsh undefine $vm-uuid 1>/dev/null 2>&1
echo DONE
else
echo "* $i is known to OpenStack, not removing."
echo "* $vm-uuid is known to OpenStack, not removing."
fi
done