summaryrefslogtreecommitdiff
path: root/destroy-vm.sh
blob: 001db9e58a9fd10e3cd25596f181ae26a4049556 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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