blob: dc5a19d1cdf21899c48c8a8c2332c9817d7e3ee1 [file] [log] [blame]
Alexander Gordeev06fb29c2014-01-31 18:02:07 +04001#!/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"}
11
12VM_COUNT=$1
13NETWORK_BRIDGE=$2
14
15for (( idx=0; idx<$VM_COUNT; idx++ )); do
16 NAME="baremetal${NETWORK_BRIDGE}_${idx}"
17 VOL_NAME="baremetal${NETWORK_BRIDGE}-${idx}.qcow2"
18 virsh list | grep -q $NAME && virsh destroy $NAME
19 virsh list --inactive | grep -q $NAME && virsh undefine $NAME
20
21 if virsh pool-list | grep -q $LIBVIRT_STORAGE_POOL ; then
22 virsh vol-list $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
23 virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL
24 fi
25done