blob: c4e4e706f4d4597984034e8e9d8566119139d8c5 [file] [log] [blame]
Adam Gandelman22ec45e2014-10-16 17:41:22 -07001#!/usr/bin/env bash
2
3# **cleanup-nodes**
4
5# Cleans up baremetal poseur nodes and volumes created during ironic setup
6# Assumes calling user has proper libvirt group membership and access.
7
8set -exu
9
10LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
11LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
12
13NAME=$1
14NETWORK_BRIDGE=$2
15
16export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
17
18VOL_NAME="$NAME.qcow2"
19virsh list | grep -q $NAME && virsh destroy $NAME
20virsh list --inactive | grep -q $NAME && virsh undefine $NAME
21
22if virsh pool-list | grep -q $LIBVIRT_STORAGE_POOL ; then
23 virsh vol-list $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
24 virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL
25fi