destroy-vm.sh: script to destroy a VM
authorvarac <varacanero@zeromail.org>
Thu, 17 Jan 2013 13:18:34 +0000 (14:18 +0100)
committervarac <varacanero@zeromail.org>
Thu, 17 Jan 2013 13:18:34 +0000 (14:18 +0100)
destroy-vm.sh [new file with mode: 0755]

diff --git a/destroy-vm.sh b/destroy-vm.sh
new file mode 100755 (executable)
index 0000000..001db9e
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh 
+
+ETC='/etc/libvirt/local/cloudinit'
+CONFIG="$ETC/cloudinit.cfg"
+
+# source parameters
+[ -e $CONFIG ] && . $CONFIG
+
+vm=$1
+
+if [ -z $vm ]
+then 
+  echo "please provide name of VM"
+  exit 1
+fi 
+
+if [ -z $VG ] 
+then 
+  echo "please provide name of volume group in $CONFIG"
+  exit 1 
+fi 
+
+echo "----- Warning ---- Are you really shure to destroy & delete libvirt guest $vm ?"
+echo "Type <yes>"
+read answer
+
+if [ "$answer" != 'yes' ]
+then 
+  echo "Ok, exiting"
+  exit 1
+fi
+
+echo "Destroying $vm ..."
+echo "Please ignore warnings"
+echo
+
+virsh destroy $vm 
+sleep 2
+
+# remove stale device mappings
+dmsetup remove $VG-$vm--rootp1 
+dmsetup remove $VG-$vm--rootp2
+
+
+lvremove /dev/$VG/$vm-root
+lvremove /dev/$VG/$vm-swap
+virsh undefine $vm