blob: adeca5cd9e33db8a83301674d6ac8b36f454cfea [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"}
Adam Gandelmanbd93f022014-03-17 16:31:49 -070011LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040012
13VM_COUNT=$1
14NETWORK_BRIDGE=$2
15
Adam Gandelmanbd93f022014-03-17 16:31:49 -070016export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
17
Alexander Gordeev06fb29c2014-01-31 18:02:07 +040018for (( idx=0; idx<$VM_COUNT; idx++ )); do
19 NAME="baremetal${NETWORK_BRIDGE}_${idx}"
20 VOL_NAME="baremetal${NETWORK_BRIDGE}-${idx}.qcow2"
21 virsh list | grep -q $NAME && virsh destroy $NAME
22 virsh list --inactive | grep -q $NAME && virsh undefine $NAME
23
24 if virsh pool-list | grep -q $LIBVIRT_STORAGE_POOL ; then
25 virsh vol-list $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME &&
26 virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL
27 fi
28done