#!/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

# Make tracing more educational
export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}:   '

LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}

NAME=$1

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

# Delete the Virtual BMC
if [[ $(type -P vbmc) != "" ]]; then
    vbmc list | grep -a $NAME && vbmc delete $NAME
fi

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

sudo brctl delif br-$NAME ovs-$NAME || true
sudo ip link set dev  br-$NAME down || true
sudo brctl delbr br-$NAME || true

#!/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

# Make tracing more educational
export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}:   '

LIBVIRT_STORAGE_POOL=${LIBVIRT_STORAGE_POOL:-"default"}
LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"}

NAME=$1

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 --nvram

# Delete the Virtual BMC
if [[ $(type -P vbmc) != "" ]]; then
    vbmc list | grep -a $NAME && vbmc delete $NAME
fi

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

sudo brctl delif br-$NAME ovs-$NAME || true
sudo ip link set dev  br-$NAME down || true
sudo brctl delbr br-$NAME || true

Fix cleaning up nodes with NVRAM (UEFI)
DevStack: Fix cleaning up nodes with NVRAM (UEFI)

This patch is fixing the cleanup_nodes.sh script to take in account
undefining nodes with NVRAM set (UEFI mode). The --nvram option is now
being passed to the "virsh undefine" command, this will undefine nodes
with (and without) NVRAM set.

Change-Id: Idbc2d0d1765cad969e68544109bd44963cadc06c
Closes-Bug: #1659335
