github.com/openshift/installer@v1.4.17/scripts/maintenance/virsh-cleanup.sh (about) 1 #!/bin/sh 2 3 printf 'Warning: This will destroy effectively all libvirt resources\nContinue [yN]? ' 4 read -r CONTINUE 5 if test "${CONTINUE}" != y -a "${CONTINUE}" != Y 6 then 7 echo 'Aborted' >&2 8 exit 1 9 fi 10 11 CONNECT="${CONNECT:=qemu:///system}" 12 13 run() 14 { 15 echo "$*" 16 "$@" 17 } 18 19 for DOMAIN in $(virsh -c "${CONNECT}" list --all --name) 20 do 21 run virsh -c "${CONNECT}" destroy "${DOMAIN}" 22 run virsh -c "${CONNECT}" undefine "${DOMAIN}" 23 done 24 25 for POOL in $(virsh -c "${CONNECT}" pool-list --all --name) 26 do 27 virsh -c "${CONNECT}" vol-list "${POOL}" | tail -n +3 | while read -r VOLUME _ 28 do 29 if test -z "${VOLUME}" 30 then 31 continue 32 fi 33 run virsh -c "${CONNECT}" vol-delete --pool "${POOL}" "${VOLUME}" 34 done 35 run virsh -c "${CONNECT}" pool-destroy "${POOL}" 36 run virsh -c "${CONNECT}" pool-undefine "${POOL}" 37 done 38 39 for NET in $(virsh -c "${CONNECT}" net-list --all --name) 40 do 41 if test "${NET}" = default 42 then 43 continue 44 fi 45 run virsh -c "${CONNECT}" net-destroy "${NET}" 46 run virsh -c "${CONNECT}" net-undefine "${NET}" 47 done