diff options
author | Stefan K. Berg <stefan.k.berg@ericsson.com> | 2015-05-12 15:54:39 +0200 |
---|---|---|
committer | Stefan K. Berg <stefan.k.berg@ericsson.com> | 2015-05-12 15:56:16 +0200 |
commit | 129ffe434c010508f26416983835e80dec0cc1d8 (patch) | |
tree | 7ba38349007080e0825fdcd99936ef452cd120a0 /fuel/prototypes/auto-deploy/examples/libvirt/tools/cleanup_example_vms.sh | |
parent | 82acf9fc006912f50ca799dee2489b53c712d936 (diff) |
Corrected directory name
It was never meant for the first level to be called anything
else than auto-deploy - really needed to get rid of the
terrible .../deploy/deploy/deploy.sh!
JIRA
Change-Id: Ifa68e5922ca8da9cc72df963e8138a8fc0b8b63b
Signed-off-by: Stefan K. Berg <stefan.k.berg@ericsson.com>
Diffstat (limited to 'fuel/prototypes/auto-deploy/examples/libvirt/tools/cleanup_example_vms.sh')
-rwxr-xr-x | fuel/prototypes/auto-deploy/examples/libvirt/tools/cleanup_example_vms.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/fuel/prototypes/auto-deploy/examples/libvirt/tools/cleanup_example_vms.sh b/fuel/prototypes/auto-deploy/examples/libvirt/tools/cleanup_example_vms.sh new file mode 100755 index 0000000..960b21e --- /dev/null +++ b/fuel/prototypes/auto-deploy/examples/libvirt/tools/cleanup_example_vms.sh @@ -0,0 +1,58 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2015 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +error_exit () { + echo "$@" + exit 1 +} + +topdir=$(cd $(dirname $(readlink -f $BASH_SOURCE)); cd ..; pwd) +netdir=$topdir/conf/networks +vmdir=$topdir/conf/vms + +if [ ! -d $netdir ]; then + error_exit "No net directory $netdir" + exit 1 +elif [ ! -d $vmdir ]; then + error_exit "No VM directory $vmdir" + exit 1 +fi + + +if [ "`whoami`" != "root" ]; then + error_exit "You need be root to run this script" +fi + +for vm in $vmdir/* +do + vmname=`basename $vm` + virsh dumpxml $vmname >/dev/null 2>&1 + if [ $? -eq 0 ]; then + diskfile=`virsh dumpxml $vmname | grep "<source file=" | grep raw | \ + sed "s/.*<source file='\(.*\)'.*/\1/"` + echo "Removing $vmname with disk $diskfile" + virsh destroy $vmname 2>/dev/null + virsh undefine $vmname + rm -f $diskfile + fi +done + +for net in $netdir/* +do + netname=`basename $net` + virsh net-dumpxml $netname >/dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "Found net $netname, deleting" + virsh net-destroy $netname + virsh net-undefine $netname + fi +done |