-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathremove_vm.sh
More file actions
executable file
·40 lines (34 loc) · 856 Bytes
/
remove_vm.sh
File metadata and controls
executable file
·40 lines (34 loc) · 856 Bytes
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
32
33
34
35
36
37
38
39
40
#!/bin/bash
WORKDIR=`dirname $0`
CONFIG_FILE=$WORKDIR/config.sh
[ -f $CONFIG_FILE ] && source $CONFIG_FILE
DISKIMG_DIR=${DISKIMG_DIR:-$HOME/images}
export LANG=C
if [ -z "$1" ]; then
echo "Usage: $0 NAME"
exit 1
fi
NAME=$1
STATE=`virsh domstate $NAME 2>/dev/null`
if [ $? -eq 0 ]; then
if [ "$STATE" != "shut off" ]; then
echo -n "$NAME is not shut off ($STATE). Force shut off it? [y/n] "
read answer
if [[ "$answer" =~ ^[yY] ]]; then
virsh destroy $NAME
sleep 1
else
echo "Abort because $NAME is not shut off."
exit 3
fi
fi
virsh undefine $NAME
else
echo "[Skipped] $NAME is not defined."
fi
IMAGE_NAME=$DISKIMG_DIR/$NAME.img
if [ -f $IMAGE_NAME ]; then
rm -f -v $IMAGE_NAME
else
echo "[Skipped] $IMAGE_NAME does not exist."
fi