Skip to content

Instantly share code, notes, and snippets.

@fghaas
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fghaas/8705466 to your computer and use it in GitHub Desktop.
Save fghaas/8705466 to your computer and use it in GitHub Desktop.
Script that creates a number of Cirros instances and then attempts to destroy them in parallel
#!/bin/bash
set -x
NUMDOMAINS=${1:-10}
PARALLEL=${2:-15}
BACKINGFILE=/var/lib/libvirt/images/test-cirros-base.qcow2
SOURCE=https://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-disk.img
parallel_virsh() {
cmd=${1:-domstate}
for j in `seq $NUMDOMAINS`; do
echo test-${j}
done | xargs -n 1 -P $PARALLEL virsh $cmd
}
wget -nc -O $BACKINGFILE $SOURCE
set -e
# Create domains
for i in `seq $NUMDOMAINS`; do
img=/var/lib/libvirt/images/test-$i.qcow2
qemu-img create -f qcow2 -b $BACKINGFILE $img
virt-install --virt-type qemu --hvm --nonetwork --name test-${i} --ram 64 --import --disk $img --noreboot
done
# Start domains in parallel
parallel_virsh start
# Destroy domains in parallel
parallel_virsh destroy
# Undefine (remove) domains in parallel
parallel_virsh undefine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment