Merge "modified to get the juju 2.1.0 as release juju version."
[joid.git] / ci / cleanvm.sh
index d334517..3756c40 100755 (executable)
@@ -1,27 +1,22 @@
 #!/bin/bash
 
-set -ex
+set -x
+
+echo " Cleanup Started ..."
 
 #use the below commands if you needs to delete the virtual machine
 # also along with envuronment destroy.
-
-echo " Cleanup Started ..."
 ./clean.sh
- virsh destroy opnfv-maas || true
- virsh destroy bootstrap || true
- virsh destroy node1-control || true
- virsh destroy node3-control || true
- virsh destroy node4-control || true
- virsh destroy node2-compute || true
- virsh destroy node5-compute || true
- virsh undefine opnfv-maas || true
- virsh undefine bootstrap || true
- virsh undefine node1-control || true
- virsh undefine node3-control || true
- virsh undefine node4-control || true
- virsh undefine node2-compute || true
- virsh undefine node5-compute || true
- sudo rm -rf  /var/lib/libvirt/images/opnfv-maas.img /var/lib/libvirt/images/bootstrap.img /var/lib/libvirt/images/node1-control.img /var/lib/libvirt/images/node3-control.img /var/lib/libvirt/images/node4-control.img /var/lib/libvirt/images/node2-compute.img /var/lib/libvirt/images/node5-compute.img || true
+
+vm_list=$(sudo virsh list --all)
+
+for vm in node1-control node2-compute node3-control node4-control \
+          node5-compute bootstrap
+do
+    echo "$vm_list" | grep -q " $vm " || continue
+    sudo virsh destroy $vm
+    sudo virsh undefine $vm
+    sudo rm -f /var/lib/libvirt/images/${vm}.qcow2
+done
+
 echo " Cleanup Finished ..."