diff options
author | QiLiang <liangqi1@huawei.com> | 2015-12-17 14:09:28 +0000 |
---|---|---|
committer | QiLiang <liangqi1@huawei.com> | 2015-12-17 14:32:21 +0000 |
commit | 459ddd6e4bcd28b37b675eaba01501e17e50de39 (patch) | |
tree | fc4b9b22d3691b97ca0bf88c15ec6f9f562e2d63 /utils/rubbos_dev_env_setup/deploy.sh | |
parent | 833d16b53e59967db779b0eba37d4f7481cb94e9 (diff) |
Add scripts to setup development env
Usage:
apt-get install -y genisoimage \
libvirt-bin \
qemu-kvm
service libvirt-bin restart
cd bottlenecks/utils/rubbos_dev_env_setup
./deploy.sh
The deploy.sh will create 9 vms (ip from 192.168.122.11 ~ 19):
control,httpd,mysql,tomcat,client1,client2,client3,client4,benchmark
TODO: add scripts to build initial disk.img
JIRA:BOTTLENECK-24
Change-Id: I99b5bcae8b795cee80e8688aae18b69e46249548
Signed-off-by: QiLiang <liangqi1@huawei.com>
Diffstat (limited to 'utils/rubbos_dev_env_setup/deploy.sh')
-rwxr-xr-x | utils/rubbos_dev_env_setup/deploy.sh | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/utils/rubbos_dev_env_setup/deploy.sh b/utils/rubbos_dev_env_setup/deploy.sh new file mode 100755 index 00000000..0b53d48b --- /dev/null +++ b/utils/rubbos_dev_env_setup/deploy.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# this is a modified copy of compass4nfv/deploy/host_virtual.sh + +set -x + +SCRIPT_DIR=`cd ${BASH_SOURCE[0]%/*};pwd` +WORK_DIR=${SCRIPT_DIR}/work + +mkdir -p $WORK_DIR + +source ./env_config.sh + +host_vm_dir=$WORK_DIR/vm + + +function download_iso() +{ + mkdir -p ${WORK_DIR}/cache + curl --connect-timeout 10 -o ${WORK_DIR}/cache/$IMAGE_NAME $IMAGE_URL +} + + +function tear_down_machines() { + for i in $HOSTNAMES; do + echo "tear down machine:" $i + sudo virsh destroy $i + sudo virsh undefine $i + rm -rf $host_vm_dir/$i + done +} + + +function get_host_macs() { + local mac_generator=${SCRIPT_DIR}/mac_generator.sh + local machines= + + chmod +x $mac_generator + mac_array=$($mac_generator $VIRT_NUMBER) + machines=$(echo $mac_array) + + echo $machines +} + +function launch_host_vms() { + mac_array=($(get_host_macs)) + + echo ${mac_array[2]} + echo ${mac_array[*]} + + old_ifs=$IFS + IFS=, + tear_down_machines + echo "bringing up vms ${mac_array[*]}" + i=0 + for host in $HOSTNAMES; do + echo "creating vm disk for instance $host" \ + "ip ${IPADDR_PREFIX}${i}" \ + "mac ${mac_array[$i]}" + vm_dir=$host_vm_dir/$host + mkdir -p $vm_dir + + cp ${WORK_DIR}/cache/$IMAGE_NAME $vm_dir + + # create seed.iso + sed -e "s/REPLACE_IPADDR/${IPADDR_PREFIX}$((i+11))/g" \ + -e "s/REPLACE_GATEWAY/${IPADDR_PREFIX}1/g" \ + -e "s/REPLACE_HOSTNAME/${host}/g" \ + meta-data_template \ + > meta-data + cp user-data_template user-data + genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data + cp seed.iso $vm_dir + + # create vm xml + sed -e "s/REPLACE_MEM/$VIRT_MEM/g" \ + -e "s/REPLACE_CPU/$VIRT_CPUS/g" \ + -e "s/REPLACE_NAME/$host/g" \ + -e "s#REPLACE_IMAGE#$vm_dir/disk.img#g" \ + -e "s#REPLACE_SEED_IMAGE#$vm_dir/seed.iso#g" \ + -e "s/REPLACE_MAC_ADDR/${mac_array[$i]}/g" \ + libvirt_template.xml \ + > $vm_dir/libvirt.xml + + sudo virsh define $vm_dir/libvirt.xml + sudo virsh start $host + let i=i+1 + done + IFS=$old_ifs + rm -rf meta-data user-data seed.iso +} + + +download_iso +launch_host_vms + +set +x + |