diff options
Diffstat (limited to 'destroy-vm.sh')
-rwxr-xr-x | destroy-vm.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/destroy-vm.sh b/destroy-vm.sh new file mode 100755 index 0000000..001db9e --- /dev/null +++ b/destroy-vm.sh @@ -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 |