diff options
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 + |