-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathclean-cluster
executable file
·71 lines (64 loc) · 1.89 KB
/
clean-cluster
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
statedir=${1:-.}
function volume_present() {
vol="$1"
for v in $(virsh --quiet vol-list --pool default |awk '{print $1}') ; do
[[ $v == $vol ]] && return 0
done
return 1
}
function delete_volume() {
for vol in "$@" ; do
volume_present "$vol" && {
echo "Deleting volume $vol"
virsh vol-delete --pool default "$vol"
}
done
}
function destroy_net() {
for net in "$@" ; do
[[ -n $(virsh --quiet net-list --all |awk '{print $1}' |grep "$net") ]] && {
echo "Destroying net $net"
virsh net-destroy "$net"
virsh net-undefine "$net"
}
done
}
function destroy_node() {
for node in "$@" ; do
[[ -n $(virsh --quiet list --all |awk '{print $2}' |grep "$node") ]] && {
echo "Destroying $node"
virsh destroy "$node"
virsh undefine "$node"
delete_volume "$node"
}
done
}
if [[ $OPENSHIFT_INSTALL_PLATFORM == libvirt ]] ; then
tmp_cluster_name=$(virsh --quiet net-list | awk '{print $1}' | grep "^${statedir}")
[[ -n $tmp_cluster_name ]] && {
statedir=$tmp_cluster_name
workers=$(virsh list --name |grep -E "^(${statedir}-)?worker-")
if [[ -n $workers ]] ; then
echo -n "Destroying workers..."
destroy_node $workers
echo
fi
destroy_net "$statedir"
destroy_net $(virsh --quiet net-list | awk '{print $1}' | grep "^${statedir}")
destroy_node "${statedir}-bootstrap"
destroy_node "${statedir}-master-0"
for f in base master-0 master.ign worker.ign bootstrap bootstrap.ign ; do
delete_volume ${statedir}-$f
done
delete_volume $(virsh --quiet vol-list --pool default | awk '{print $1}' | grep "^${statedir}")
}
fi
if [[ -n $statedir && $statedir != . && $statedir != .. ]] ; then
echo "Removing statedir $statedir"
rm -rf "$statedir"
else
echo "Removing state"
rm -rf .openshift_install_state.json terraform.tfstate terraform.tfvars terraform.state metadata.json auth tectonic
fi
echo Done