#!/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 " 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 rm -v "/var/lib/libvirt/cloudinit/${vm}-cloudinit_seed.img" rm -v "/var/lib/libvirt/cloudinit/${vm}01" rm -v "/var/lib/libvirt/cloudinit/${vm}00" virsh undefine $vm