Integration testing preparation for Ironic

Add ability to create/register qemu vms for Ironic testing purposes

Implements bp:deprecate-baremetal-driver

Change-Id: If452438fcc0ff562531b33a36cd189b235654b48
diff --git a/tools/ironic/scripts/cleanup-nodes b/tools/ironic/scripts/cleanup-nodes
new file mode 100755
index 0000000..dc5a19d
--- /dev/null
+++ b/tools/ironic/scripts/cleanup-nodes
@@ -0,0 +1,25 @@
+#!/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"}
+
+VM_COUNT=$1
+NETWORK_BRIDGE=$2
+
+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