declare -A admin_ip_arr
declare -A public_ip_arr
+vagrant_box_dir=~/.vagrant.d/boxes/opnfv-VAGRANTSLASH-centos-7.0/1.0.0/virtualbox/
+vagrant_box_vmdk=box-disk1.vmdk
vm_dir=/var/opt/opnfv
script=`realpath $0`
##END VARS
echo "${blue}Detecting network configuration...${reset}"
##detect host 1 or 3 interface configuration
#output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
- output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | cut -d " " -f10`
+ #output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | cut -d " " -f10`
+ output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | awk {'print $9'}`
fi
if [ ! "$output" ]; then
subnet_mask=$(find_netmask $interface)
if [ "$if_counter" -eq 0 ]; then
admin_subnet_mask=$subnet_mask
+ admin_ip=$new_ip
if ! verify_subnet_size $admin_subnet_mask 5; then
echo "${red} Not enough IPs in admin subnet: ${interface_ip_arr[$if_counter]} ${admin_subnet_mask}. Need at least 5 IPs. Please resize subnet! Exiting ${reset}"
exit 1
done <<< "$public_output"
fi
+ ##replace admin_network param for bare metal deployments
+ if [ -z "$virtual" ]; then
+ admin_subnet=$(find_subnet $admin_ip $admin_subnet_mask)
+ sed -i 's/^.*admin_network:.*$/ admin_network:'" $admin_subnet"'/' opnfv_ksgen_settings.yml
+ else
+ sed -i 's/^.*admin_network:.*$/ admin_network:'" \"false\""'/' opnfv_ksgen_settings.yml
+ fi
##replace public_network param
public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
node_type=config_nodes_${node}_type
node_type=$(eval echo \$$node_type)
+ ##modify memory and cpu
+ node_memory=$(eval echo \${config_nodes_${node}_memory})
+ node_vcpus=$(eval echo \${config_nodes_${node}_cpus})
+ node_storage=$(eval echo \${config_nodes_${node}_disk})
+
+ sed -i 's/^.*vb.memory =.*$/ vb.memory = '"$node_memory"'/' Vagrantfile
+ sed -i 's/^.*vb.cpus =.*$/ vb.cpus = '"$node_vcpus"'/' Vagrantfile
+
+ if ! resize_vagrant_disk $node_storage; then
+ echo "${red}Error while resizing vagrant box to size $node_storage for $node! ${reset}"
+ exit 1
+ fi
+
##trozet test make compute nodes wait 20 minutes
if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
##modify provisioning to do puppet install, config, and foreman check-in
##substitute host_name and dns_server in the provisioning script
- host_string=config_nodes_${node}_hostname
- host_name=$(eval echo \$$host_string)
+ host_string=config_nodes_${node}_short_name
+ short_host_name=$(eval echo \$$host_string)
+ ##substitute domain_name
+ domain_name=$config_domain_name
+ sed -i 's/^domain_name=REPLACE/domain_name='$domain_name'/' vm_nodes_provision.sh
+ host_name=${short_host_name}.${domain_name}
sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
##dns server should be the foreman server
sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
## modify default_gw to be node_default_gw
sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
- ## modify VM memory to be 4gig
- ##if node type is controller
- if [ "$node_type" == "controller" ]; then
- sed -i 's/^.*vb.memory =.*$/ vb.memory = 4096/' Vagrantfile
- fi
echo "${blue}Starting Vagrant Node $node! ${reset}"
##stand up vagrant
if ! vagrant up; then
if [ ! -z "$horizon_public_vip" ]; then
echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
else
- echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${odl_control_ip} ${reset}"
+ ##Find public IP of controller
+ for node in ${nodes}; do
+ node_type=config_nodes_${node}_type
+ node_type=$(eval echo \$$node_type)
+ if [ "$node_type" == "controller" ]; then
+ pushd $vm_dir/$node
+ horizon_ip=`vagrant ssh -c "ifconfig enp0s10" | grep -Eo "inet [0-9\.]+" | awk {'print $2'}`
+ popd
+ break
+ fi
+ done
+ if [ -z "$horizon_ip" ]; then
+ echo "${red}Warn: Unable to determine horizon IP, please login to your controller node to find it${reset}"
+ fi
+ echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_ip} ${reset}"
fi
fi
}
fi
}
+##resizes vagrant disk (cannot shrink)
+##params: size in GB
+##usage: resize_vagrant_disk 100
+resize_vagrant_disk() {
+ if [[ "$1" < 40 ]]; then
+ echo "${blue}Warn: Requested disk size cannot be less than 40, using 40 as new size${reset}"
+ new_size_gb=40
+ else
+ new_size_gb=$1
+ fi
+
+ if ! vagrant box list | grep opnfv; then
+ vagrant box remove -f opnfv/centos-7.0
+ if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
+ echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
+ exit 1
+ fi
+ fi
+
+ pushd $vagrant_box_dir
+
+ # Close medium to make sure we can modify it
+ vboxmanage closemedium disk $vagrant_box_vmdk
+
+ cur_size=$(vboxmanage showhdinfo $vagrant_box_vmdk | grep -i capacity | grep -Eo [0-9]+)
+ cur_size_gb=$((cur_size / 1024))
+
+ if [ "$cur_size_gb" -eq "$new_size_gb" ]; then
+ echo "${blue}Info: Disk size already ${cur_size_gb} ${reset}"
+ popd
+ return
+ elif [[ "$new_size_gb" < "$cur_size_gb" ]] ; then
+ echo "${blue}Info: Requested disk is less than ${cur_size_gb} ${reset}"
+ echo "${blue}Re-adding vagrant box${reset}"
+ if vagrant box list | grep opnfv; then
+ popd
+ vagrant box remove -f opnfv/centos-7.0
+ if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
+ echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
+ exit 1
+ fi
+ pushd $vagrant_box_dir
+ fi
+ fi
+
+ new_size=$((new_size_gb * 1024))
+ if ! vboxmanage clonehd $vagrant_box_vmdk tmp-disk.vdi --format vdi; then
+ echo "${red}Error: Unable to clone ${vagrant_box_vmdk}${reset}"
+ popd
+ return 1
+ fi
+
+ if ! vboxmanage modifyhd tmp-disk.vdi --resize $new_size; then
+ echo "${red}Error: Unable modify tmp-disk.vdi to ${new_size}${reset}"
+ popd
+ return 1
+ fi
+
+ if ! vboxmanage clonehd tmp-disk.vdi resized-disk.vmdk --format vmdk; then
+ echo "${red}Error: Unable clone tmp-disk.vdi to vmdk${reset}"
+ popd
+ return 1
+ fi
+
+ vboxmanage closemedium disk tmp-disk.vdi --delete
+ rm -f tmp-disk.vdi $vagrant_box_vmdk
+ cp -f resized-disk.vmdk $vagrant_box_vmdk
+ vboxmanage closemedium disk resized-disk.vmdk --delete
+ popd
+}
+
##END FUNCTIONS
main() {