Move generation of baremetal VM names to lib/ironic
The create-nodes script currently receives a total # of VMs to create
and creates them all, generating their names on the fly. This moves
that name generation to lib/ironic and makes the script create only
single VMs as directed. This centralizes the naming of things to
lib/ironic and will make it easier to reference these things elsewhere.
Change-Id: I98e61f7188e027e690303e32aff7cd2347f6d2c2
diff --git a/tools/ironic/scripts/cleanup-node b/tools/ironic/scripts/cleanup-node
new file mode 100755
index 0000000..c4e4e70
--- /dev/null
+++ b/tools/ironic/scripts/cleanup-node
@@ -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"}
+LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}
+
+NAME=$1
+NETWORK_BRIDGE=$2
+
+export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI
+
+VOL_NAME="$NAME.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