devstack/tools/ironic/scripts/cleanup-nodes
Adam Gandelman bd93f02850 Set VIRSH_DEFAULT_CONNECT_URI in Ironic scripts
Ironic setup scripts that interface with virsh should default to always
connecting to the 'qemu:///system' URI.  Adds LIBVIRT_CONNECT_URI that
ends up exported as VIRSH_DEFAULT_CONNECT_URI in scripts that require
it.

Change-Id: Ib660bd51a8c7bfe96e14aab4b6d3a6e83a5a4220
2014-03-17 16:31:49 -07:00

29 lines
872 B
Bash
Executable File

#!/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
LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
VM_COUNT=$1
NETWORK_BRIDGE=$2
export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
for (( idx=0; idx<$VM_COUNT; idx++ )); do
NAME="baremetal${NETWORK_BRIDGE}_${idx}"
VOL_NAME="baremetal${NETWORK_BRIDGE}-${idx}.qcow2"
virsh list | grep -q $NAME && virsh destroy $NAME
virsh list --inactive | grep -q $NAME && virsh undefine $NAME
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
done