#!/bin/bash

run() {
    number=$1
    shift
    python scripts/get_hosts.py | grep -v controller | xargs -n 1 -P $number \
        -I BOX sh -c "echo - BOX && (vagrant $* BOX 2>&1 >> log/BOX.log)"
}

if [[ ! -e config.yaml ]]; then
    echo "error: configuration file 'config.yaml' does not exist"
    exit 1
fi

echo "$(date) cleaning up"
rm -f log/*
vagrant destroy

echo "$(date) bringign up, provisioning and reloading the controller VM"
vagrant up controller >> log/controller.log
vagrant reload controller >> log/controller.log

echo "$(date) brining up all VMs"
run 2 up --no-provision

echo "$(date) provisioning all other VMs"
run 4 provision

echo "$(date) reloading all other VMs"
run 4 reload

echo "$(date) initializing the controller node"
vagrant ssh controller -c '/home/vagrant/scripts/initialize.sh' 2>&1 >> log/controller.log

#!/bin/bash

if [[ -z "$1" ]]; then
    p=1
else
    p=$1
fi

run() {
    number=$1
    shift
    python scripts/get_hosts.py | grep -v controller | xargs -n 1 -P $number \
        -I BOX sh -c "echo - BOX && (vagrant $* BOX 2>&1 >> log/BOX.log)"
}

if [[ ! -e config.yaml ]]; then
    echo "error: configuration file 'config.yaml' does not exist"
    exit 1
fi

echo "$(date) cleaning up"
rm -f log/*
vagrant destroy

echo "$(date) bringign up, provisioning and reloading the controller VM"
vagrant up controller >> log/controller.log
vagrant reload controller >> log/controller.log

echo "$(date) brining up all VMs"
run $p up --no-provision

echo "$(date) provisioning all other VMs"
run $p provision

echo "$(date) reloading all other VMs"
run $p reload

echo "$(date) initializing the controller node"
vagrant ssh controller -c '/home/vagrant/scripts/initialize.sh' 2>&1 >> log/controller.log

Make number of parallel running Vagrant processes configurable
Make number of parallel running Vagrant processes configurable

Only run 1 Vagrant process by default because it looks like there are
locking issues with the current Vagrant version when running several
Vagrant processes in a multi machine environment.

Change-Id: I5b6cd752367255acabea76d0dc365aea0ffcc5ea
