blob: 680bef4eadafb4a9b2e377c4c0789bdd913eb797 (
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
|
#!/bin/sh
#
# Remove a VM for liw.
set -eu
# Command line parameters.
name="$1"
# What volume group should we use?
vg="exolobe1-vg"
# Shut down and remove the VM, if it exists.
if virsh list --all | grep -F "$name" > /dev/null
then
virsh destroy "$name" || true
virsh undefine "$name"
fi
# Remove the LV, if it exists.
lvpath="/dev/$vg/$name"
if [ -e "$lvpath" ]
then
sudo lvremove --force "$lvpath"
fi
# Remove the host from /etc/hosts, if there.
awk -v "name=$name" '$2 != name' /etc/hosts | sudo sponge /etc/hosts
# Done.
echo "Virtual machine $name is gone."
|