Make launch.sh idempotent

Change-Id: I9b3f989397c4c36ab3717d1cca84841778881186
This commit is contained in:
Xicheng Chang 2015-05-04 11:59:08 -07:00
parent daa1ae3f2b
commit ea07256545
5 changed files with 93 additions and 48 deletions

View File

@ -17,7 +17,15 @@ run:
./launch.sh
```
after launch finishes, to access compass server:
or
```
./launch.sh --recreate
```
the "recreate" flag will destroy all configured vms and hostonly networks in VirtualBox.
After launch finishes, to access compass server:
```
vagrant ssh

14
vagrant/destroy.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
#
VBoxManage unregistervm controller --delete
VBoxManage unregistervm compute --delete
VBoxManage unregistervm network --delete
VBoxManage unregistervm storage --delete
vagrant destroy -f
hostonlyifs=$(VBoxManage list hostonlyifs|grep '\ vboxnet'| awk -F ' ' '{print $2}')
for hostonlyif in $hostonlyifs
do
VBoxManage hostonlyif remove $hostonlyif
done
rm -rf $HOME/VirtualBox VMs/*

56
vagrant/first_run.sh Executable file
View File

@ -0,0 +1,56 @@
#!/bin/bash
#
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
if [ -f $HOME/VirtualBox\ VMs/compass-server ];then
mkdir -p $HOME/VirtualBox VMs/compass-server
fi
VBoxManage hostonlyif create
VBoxManage hostonlyif create > $HOME/adapter1info
export adapter1=`cut -d\' -f2 $HOME/adapter1info`
VBoxManage hostonlyif ipconfig $adapter1 --ip "192.168.33.1" --netmask "255.255.255.0"
VBoxManage hostonlyif create > $HOME/adapter2info
export adapter2=`cut -d\' -f2 $HOME/adapter2info`
VBoxManage hostonlyif ipconfig $adapter2 --ip "172.16.10.1" --netmask "255.255.255.0"
VBoxManage createvm --name controller --ostype Linux_64 --register
VBoxManage createvm --name compute --ostype Linux_64 --register
VBoxManage createvm --name network --ostype Linux_64 --register
VBoxManage createvm --name storage --ostype Linux_64 --register
# controller
VBoxManage modifyvm controller --memory 2048 --nic1 hostonly --hostonlyadapter1 $adapter1 --macaddress1 000102030405 --nic2 hostonly --hostonlyadapter2 $adapter2 --nicpromisc2 allow-vms --macaddress2 000120295BFA --vram 12 --boot1 net --boot2 disk
VBoxManage createhd --filename "$HOME/VirtualBox VMs/controller/controller.vdi" --size 32768
VBoxManage storagectl controller --name "controller-IDE" --add ide
VBoxManage storageattach controller --storagectl "controller-IDE" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/controller/controller.vdi"
# compute
VBoxManage modifyvm compute --memory 3072 --nic1 hostonly --hostonlyadapter1 $adapter1 --macaddress1 000102030406 --nic2 hostonly --hostonlyadapter2 $adapter2 --nicpromisc2 allow-vms --macaddress2 000120295BFB --vram 12 --boot1 net --boot2 disk
VBoxManage createhd --filename "$HOME/VirtualBox VMs/compute/compute.vdi" --size 16384
VBoxManage storagectl compute --name "compute-IDE" --add ide
VBoxManage storageattach compute --storagectl "compute-IDE" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/compute/compute.vdi"
# network
VBoxManage modifyvm network --memory 2048 --nic1 hostonly --hostonlyadapter1 $adapter1 --macaddress1 000102030407 --nic2 hostonly --hostonlyadapter2 $adapter2 --nicpromisc2 allow-vms --macaddress2 000120295BFC --vram 12 --boot1 net --boot2 disk
VBoxManage createhd --filename "$HOME/VirtualBox VMs/network/network.vdi" --size 16384
VBoxManage storagectl network --name "network-IDE" --add ide
VBoxManage storageattach network --storagectl "network-IDE" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/network/network.vdi"
# storage
VBoxManage modifyvm storage --memory 2048 --nic1 hostonly --hostonlyadapter1 $adapter1 --macaddress1 000102030408 --nic2 hostonly --hostonlyadapter2 $adapter2 --nicpromisc2 allow-vms --macaddress2 000120295BFD --vram 12 --boot1 net --boot2 disk
VBoxManage createhd --filename "$HOME/VirtualBox VMs/storage/storage.vdi" --size 32768
VBoxManage storagectl storage --name "storage-IDE" --add ide
VBoxManage storageattach storage --storagectl "storage-IDE" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/storage/storage.vdi"
# compass
# get latest ansible code
cd $SCRIPT_DIR
git clone -b dev/experimental git://git.openstack.org/stackforge/compass-adapters.git
cp -r compass-adapters/ansible/openstack_juno compass-adapters/ansible/openstack_juno_plumgrid
vagrant box list |grep compass
if [ "$?" != "0" ]; then
vagrant box add compass https://atlas.hashicorp.com/compass-dev/boxes/compass/versions/0.0.1/providers/compass.box
fi
vagrant up --provision

View File

@ -6,51 +6,9 @@ if [ -f $HOME/VirtualBox\ VMs/compass-server ];then
mkdir -p $HOME/VirtualBox VMs/compass-server
fi
VBoxManage hostonlyif create
VBoxManage hostonlyif create > $HOME/adapter1info
export adapter1=`cut -d\' -f2 $HOME/adapter1info`
VBoxManage hostonlyif ipconfig $adapter1 --ip "192.168.33.1" --netmask "255.255.255.0"
VBoxManage hostonlyif create > $HOME/adapter2info
export adapter2=`cut -d\' -f2 $HOME/adapter2info`
VBoxManage hostonlyif ipconfig $adapter2 --ip "172.16.10.1" --netmask "255.255.255.0"
VBoxManage createvm --name controller --ostype Linux_64 --register
VBoxManage createvm --name compute --ostype Linux_64 --register
VBoxManage createvm --name network --ostype Linux_64 --register
VBoxManage createvm --name storage --ostype Linux_64 --register
# controller
VBoxManage modifyvm controller --memory 2048 --nic1 hostonly --hostonlyadapter1 $adapter1 --macaddress1 000102030405 --nic2 hostonly --hostonlyadapter2 $adapter2 --nicpromisc2 allow-vms --macaddress2 000120295BFA --vram 12 --boot1 net --boot2 disk
VBoxManage createhd --filename "$HOME/VirtualBox VMs/controller/controller.vdi" --size 32768
VBoxManage storagectl controller --name "controller-IDE" --add ide
VBoxManage storageattach controller --storagectl "controller-IDE" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/controller/controller.vdi"
# compute
VBoxManage modifyvm compute --memory 3072 --nic1 hostonly --hostonlyadapter1 $adapter1 --macaddress1 000102030406 --nic2 hostonly --hostonlyadapter2 $adapter2 --nicpromisc2 allow-vms --macaddress2 000120295BFB --vram 12 --boot1 net --boot2 disk
VBoxManage createhd --filename "$HOME/VirtualBox VMs/compute/compute.vdi" --size 16384
VBoxManage storagectl compute --name "compute-IDE" --add ide
VBoxManage storageattach compute --storagectl "compute-IDE" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/compute/compute.vdi"
# network
VBoxManage modifyvm network --memory 2048 --nic1 hostonly --hostonlyadapter1 $adapter1 --macaddress1 000102030407 --nic2 hostonly --hostonlyadapter2 $adapter2 --nicpromisc2 allow-vms --macaddress2 000120295BFC --vram 12 --boot1 net --boot2 disk
VBoxManage createhd --filename "$HOME/VirtualBox VMs/network/network.vdi" --size 16384
VBoxManage storagectl network --name "network-IDE" --add ide
VBoxManage storageattach network --storagectl "network-IDE" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/network/network.vdi"
# storage
VBoxManage modifyvm storage --memory 2048 --nic1 hostonly --hostonlyadapter1 $adapter1 --macaddress1 000102030408 --nic2 hostonly --hostonlyadapter2 $adapter2 --nicpromisc2 allow-vms --macaddress2 000120295BFD --vram 12 --boot1 net --boot2 disk
VBoxManage createhd --filename "$HOME/VirtualBox VMs/storage/storage.vdi" --size 32768
VBoxManage storagectl storage --name "storage-IDE" --add ide
VBoxManage storageattach storage --storagectl "storage-IDE" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/storage/storage.vdi"
# compass
# get latest ansible code
cd $SCRIPT_DIR
git clone -b dev/experimental git://git.openstack.org/stackforge/compass-adapters.git
cp -r compass-adapters/ansible/openstack_juno compass-adapters/ansible/openstack_juno_plumgrid
vagrant box list |grep compass
if [ "$?" != "0" ]; then
vagrant box add compass https://atlas.hashicorp.com/compass-dev/boxes/compass/versions/0.0.1/providers/compass.box
if [ "$1" == "--recreate" ]; then
source destroy.sh
source first_run.sh
else
source run.sh
fi
vagrant up --provision

9
vagrant/run.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
#
VBoxManage list vms|grep controller
if [ "$?" == "0" ]; then
exit 0
else
source first_run.sh
fi