forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virsh-cleanup.sh
executable file
·47 lines (41 loc) · 1021 Bytes
/
virsh-cleanup.sh
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
41
42
43
44
45
46
47
#!/bin/sh
printf 'Warning: This will destroy effectively all libvirt resources\nContinue [yN]? '
read -r CONTINUE
if test "${CONTINUE}" != y -a "${CONTINUE}" != Y
then
echo 'Aborted' >&2
exit 1
fi
CONNECT="${CONNECT:=qemu:///system}"
run()
{
echo "$*"
"$@"
}
for DOMAIN in $(virsh -c "${CONNECT}" list --all --name)
do
run virsh -c "${CONNECT}" destroy "${DOMAIN}"
run virsh -c "${CONNECT}" undefine "${DOMAIN}"
done
for POOL in $(virsh -c "${CONNECT}" pool-list --all --name)
do
virsh -c "${CONNECT}" vol-list "${POOL}" | tail -n +3 | while read -r VOLUME _
do
if test -z "${VOLUME}"
then
continue
fi
run virsh -c "${CONNECT}" vol-delete --pool "${POOL}" "${VOLUME}"
done
run virsh -c "${CONNECT}" pool-destroy "${POOL}"
run virsh -c "${CONNECT}" pool-undefine "${POOL}"
done
for NET in $(virsh -c "${CONNECT}" net-list --all --name)
do
if test "${NET}" = default
then
continue
fi
run virsh -c "${CONNECT}" net-destroy "${NET}"
run virsh -c "${CONNECT}" net-undefine "${NET}"
done