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"} |
| 11 | |
| 12 | VM_COUNT=$1 |
| 13 | NETWORK_BRIDGE=$2 |
| 14 | |
| 15 | for (( idx=0; idx<$VM_COUNT; idx++ )); do |
| 16 | NAME="baremetal${NETWORK_BRIDGE}_${idx}" |
| 17 | VOL_NAME="baremetal${NETWORK_BRIDGE}-${idx}.qcow2" |
| 18 | virsh list | grep -q $NAME && virsh destroy $NAME |
| 19 | virsh list --inactive | grep -q $NAME && virsh undefine $NAME |
| 20 | |
| 21 | if virsh pool-list | grep -q $LIBVIRT_STORAGE_POOL ; then |
| 22 | virsh vol-list $LIBVIRT_STORAGE_POOL | grep -q $VOL_NAME && |
| 23 | virsh vol-delete $VOL_NAME --pool $LIBVIRT_STORAGE_POOL |
| 24 | fi |
| 25 | done |