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