diff options
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/rubbos_dev_env_setup/deploy.sh | 98 | ||||
-rw-r--r-- | utils/rubbos_dev_env_setup/env_config.sh | 7 | ||||
-rw-r--r-- | utils/rubbos_dev_env_setup/libvirt_template.xml | 41 | ||||
-rwxr-xr-x | utils/rubbos_dev_env_setup/mac_generator.sh | 28 | ||||
-rw-r--r-- | utils/rubbos_dev_env_setup/meta-data_template | 11 | ||||
-rw-r--r-- | utils/rubbos_dev_env_setup/user-data_template | 2 |
6 files changed, 187 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 + diff --git a/utils/rubbos_dev_env_setup/env_config.sh b/utils/rubbos_dev_env_setup/env_config.sh new file mode 100644 index 00000000..326b9a57 --- /dev/null +++ b/utils/rubbos_dev_env_setup/env_config.sh @@ -0,0 +1,7 @@ +export HOSTNAMES=${HOSTNAMES:-"control,httpd,mysql,tomcat,client1,client2,client3,client4,benchmark"} +export VIRT_NUMBER=9 +export VIRT_MEM=4096 +export VIRT_CPUS=4 +export IMAGE_URL=${IMAGE_URL:-"file:///bottlenecks/trusty-server-cloudimg-amd64-disk1.img"} +export IMAGE_NAME=disk.img +export IPADDR_PREFIX="192.168.122." diff --git a/utils/rubbos_dev_env_setup/libvirt_template.xml b/utils/rubbos_dev_env_setup/libvirt_template.xml new file mode 100644 index 00000000..eddeff00 --- /dev/null +++ b/utils/rubbos_dev_env_setup/libvirt_template.xml @@ -0,0 +1,41 @@ +<domain type='kvm'> + <name>REPLACE_NAME</name> + <memory unit='MiB'>REPLACE_MEM</memory> + <currentMemory unit='MiB'>REPLACE_MEM</currentMemory> + <vcpu placement='static'>REPLACE_CPU</vcpu> + <os> + <type arch='x86_64'>hvm</type> + <boot dev='hd'/> + </os> + <features> + <acpi/><apic/><pae/> + </features> + <clock offset="utc"/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>restart</on_crash> + <devices> + <disk type='file' device='disk'> + <driver name='qemu' type='qcow2'/> + <source file='REPLACE_IMAGE'/> + <target dev='vda' bus='virtio'/> + </disk> + <disk type='file' device='cdrom'> + <driver name='qemu'/> + <source file='REPLACE_SEED_IMAGE'/> + <target dev='hdb'/> + <readonly/> + </disk> + <interface type='network'> + <source network='default'/> + <mac address='REPLACE_MAC_ADDR'/> + <model type='virtio'/> + </interface> + <input type='tablet' bus='usb'/> + <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/> + <console type='pty'/> + <video> + <model type='cirrus'/> + </video> + </devices> +</domain> diff --git a/utils/rubbos_dev_env_setup/mac_generator.sh b/utils/rubbos_dev_env_setup/mac_generator.sh new file mode 100755 index 00000000..bc5f6c2e --- /dev/null +++ b/utils/rubbos_dev_env_setup/mac_generator.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# this is a modified copy from compass4nfv/deploy/mac_generator.sh + +function mac_address_part() { + hex_number=$(printf '%02x' $RANDOM) + number_length=${#hex_number} + number_start=$(expr $number_length - 2) + echo ${hex_number:$number_start:2} +} + +function mac_address() { + echo "00:00:$(mac_address_part):$(mac_address_part):$(mac_address_part):$(mac_address_part)" +} + +machines='' +for i in `seq $1`; do + mac=$(mac_address) + + if [[ -z $machines ]]; then + machines="${mac}" + else + machines="${machines} ${mac}" + fi +done + +echo ${machines} + diff --git a/utils/rubbos_dev_env_setup/meta-data_template b/utils/rubbos_dev_env_setup/meta-data_template new file mode 100644 index 00000000..43db6597 --- /dev/null +++ b/utils/rubbos_dev_env_setup/meta-data_template @@ -0,0 +1,11 @@ +instance-id: iid-abcdeff +network-interfaces: | + # The primary network interface + auto eth0 + iface eth0 inet static + address REPLACE_IPADDR + netmask 255.255.255.0 + gateway REPLACE_GATEWAY + dns-nameservers 8.8.8.8 +local-hostname: REPLACE_HOSTNAME + diff --git a/utils/rubbos_dev_env_setup/user-data_template b/utils/rubbos_dev_env_setup/user-data_template new file mode 100644 index 00000000..77f616df --- /dev/null +++ b/utils/rubbos_dev_env_setup/user-data_template @@ -0,0 +1,2 @@ +#cloud-config + |