From 7173543940d85a017c230a57b6f822b033160292 Mon Sep 17 00:00:00 2001 From: Davide Panarese Date: Mon, 4 Feb 2019 16:30:13 +0100 Subject: [PATCH] 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. Change-Id: I45cc77853e3ae97df77f886407fbdf32d729fa1a Signed-off-by: Davide Panarese --- libvirt/cleanup-orphaned-vms.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libvirt/cleanup-orphaned-vms.sh b/libvirt/cleanup-orphaned-vms.sh index 90e140b..7fdd5ed 100755 --- a/libvirt/cleanup-orphaned-vms.sh +++ b/libvirt/cleanup-orphaned-vms.sh @@ -17,19 +17,19 @@ if [ -z "$UUIDS" ]; then exit 1 fi -for i in `virsh list --all | grep -E '^ [0-9-]+' | awk '{print $2;}'` ; do +for uuid in `virsh list --uuid --all` ; do - virsh dumpxml $i | grep "source file" | grep -E "$UUIDS" >/dev/null + echo $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 "+ $uuid is NOT known to OpenStack, removing managedsave info... " + [ -z "$1" ] && virsh managedsave-remove $uuid 1>/dev/null 2>&1 echo -n "destroying VM... " - [ -z "$1" ] && virsh destroy $i 1>/dev/null 2>&1 + [ -z "$1" ] && virsh destroy $uuid 1>/dev/null 2>&1 echo -n "undefining VM... " - [ -z "$1" ] && virsh undefine $i 1>/dev/null 2>&1 + [ -z "$1" ] && virsh undefine $uuid 1>/dev/null 2>&1 echo DONE else - echo "* $i is known to OpenStack, not removing." + echo "* $uuid is known to OpenStack, not removing." fi done