From 5b8fce78452aeb32956e706f3c775f5fbe1df26f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 4 Jul 2015 11:51:34 +0300 Subject: Add script to remove a VM --- remove-vm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 remove-vm (limited to 'remove-vm') 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." -- cgit v1.2.1