-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup-node.sh
executable file
·36 lines (25 loc) · 1006 Bytes
/
cleanup-node.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
#!/usr/bin/env bash
# **cleanup-nodes**
# Cleans up baremetal poseur nodes and volumes created during ironic setup
# Assumes calling user has proper libvirt group membership and access.
set -exu
# Make tracing more educational
export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: '
LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
NAME=$1
tapif=tap-$NAME
export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
VOL_NAME="$NAME.qcow2"
virsh list | grep -q $NAME && virsh destroy $NAME
virsh list --inactive | grep -q $NAME && virsh undefine $NAME --nvram
# Delete the Virtual BMC
if [[ $(type -P vbmc) != "" ]]; then
vbmc list | grep -a $NAME && vbmc delete $NAME
fi
if virsh pool-list | grep -q $LIBVIRT_STORAGE_POOL ; then
virsh vol-list $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL
fi
sudo ovs-vsctl del-port $tapif
sudo ip link del dev $tapif