summaryrefslogtreecommitdiff
path: root/remove-vm
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-07-04 11:51:34 +0300
committerLars Wirzenius <liw@liw.fi>2015-07-04 11:51:34 +0300
commit5b8fce78452aeb32956e706f3c775f5fbe1df26f (patch)
tree7690c0ecb4356180511c7c4e249f302623967e94 /remove-vm
parent7358aee78c36862750fd40c385ad9e2d1d749d0c (diff)
downloadansibleness-5b8fce78452aeb32956e706f3c775f5fbe1df26f.tar.gz
Add script to remove a VM
Diffstat (limited to 'remove-vm')
-rwxr-xr-xremove-vm31
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."