Last active
August 29, 2015 13:55
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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