Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 1 | #!/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 | |
| 8 | set -exu |
| 9 | |
| 10 | LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"} |
Adam Gandelman | bd93f02 | 2014-03-17 16:31:49 -0700 | [diff] [blame] | 11 | LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"} |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 12 | |
| 13 | VM_COUNT=$1 |
| 14 | NETWORK_BRIDGE=$2 |
| 15 | |
Adam Gandelman | bd93f02 | 2014-03-17 16:31:49 -0700 | [diff] [blame] | 16 | export VIRSH_DEFAULT_CONNECT_URI=$LIBVIRT_CONNECT_URI |
| 17 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 18 | for (( 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 |
| 28 | done |