Skip to content

Instantly share code, notes, and snippets.

@rabin-io
Forked from larsks/virt-delete
Last active April 18, 2018 16:24
Show Gist options
  • Save rabin-io/4011f15fe9a8129dcb3c2f1cc2630ab7 to your computer and use it in GitHub Desktop.
Save rabin-io/4011f15fe9a8129dcb3c2f1cc2630ab7 to your computer and use it in GitHub Desktop.
A shell script for deleting a libvirt domain and associated storage
#!/bin/sh
echo "Destroy: $1"
virsh destroy $1 2> /dev/null
for disk in $(virsh -q domblklist $1 | awk '{print $2}'); do
pool=$(virsh vol-pool $disk)
name=$(virsh vol-info $disk | awk '$1 == "Name:" {print $2}')
echo "Delete volume: $disk ($name in $pool)"
virsh vol-delete $name $pool
done
echo "Undefine: $1"
virsh undefine $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment