Adds ability to specify NICs to bridge on the jumphost
[genesis.git] / foreman / ci / deploy.sh
index 2ccb64b..862077e 100755 (executable)
@@ -28,6 +28,8 @@ declare -A interface_arr
 declare -A controllers_ip_arr
 declare -A admin_ip_arr
 declare -A public_ip_arr
+
+vm_dir=/var/opt/opnfv
 ##END VARS
 
 ##FUNCTIONS
@@ -41,6 +43,33 @@ display_usage() {
   echo -e "\n   -enable_virtual_dhcp : Run dhcp server instead of using static IPs.  Use this with -virtual only. \n"
   echo -e "\n   -static_ip_range : static IP range to define when using virtual and when dhcp is not being used (default), must at least a 20 IP block.  Format: '192.168.1.1,192.168.1.20' \n"
   echo -e "\n   -ping_site : site to use to verify IP connectivity from the VM when -virtual is used.  Format: -ping_site www.blah.com \n"
+  echo -e "\n   -floating_ip_count : number of IP address from the public range to be used for floating IP. Default is 20.\n"
+  echo -e "\n   -admin_nic : Baremetal NIC for the admin network.  Required if other "nic" arguments are used.  \
+Not applicable with -virtual.  Example: -admin_nic em1"
+  echo -e "\n   -private_nic : Baremetal NIC for the private network.  Required if other "nic" arguments are used.  \
+Not applicable with -virtual.  Example: -private_nic em2"
+  echo -e "\n   -public_nic : Baremetal NIC for the public network.  Required if other "nic" arguments are used.  \
+Can also be used with -virtual.  Example: -public_nic em3"
+  echo -e "\n   -storage_nic : Baremetal NIC for the storage network.  Optional.  Not applicable with -virtual. \
+Private NIC will be used for storage if not specified. Example: -storage_nic em4"
+}
+
+##verify vm dir exists
+##params: none
+function verify_vm_dir {
+  if [ -d "$vm_dir" ]; then
+    echo -e "\n\n${red}ERROR: VM Directory: $vm_dir already exists.  Environment not clean.  Please use clean.sh.  Exiting${reset}\n\n"
+    exit 1
+  else
+    mkdir -p $vm_dir
+  fi
+
+  chmod 700 $vm_dir
+
+  if [ ! -d $vm_dir ]; then
+    echo -e "\n\n${red}ERROR: Unable to create VM Directory: $vm_dir  Exiting${reset}\n\n"
+    exit -1
+  fi
 }
 
 ##find ip of interface
@@ -57,6 +86,41 @@ function find_subnet {
   printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
 }
 
+##verify subnet has at least n IPs
+##params: subnet mask, n IPs
+function verify_subnet_size {
+  IFS=. read -r i1 i2 i3 i4 <<< "$1"
+  num_ips_required=$2
+
+  ##this function assumes you would never need more than 254
+  ##we check here to make sure
+  if [ "$num_ips_required" -ge 254 ]; then
+    echo -e "\n\n${red}ERROR: allocating more than 254 IPs is unsupported...Exiting${reset}\n\n"
+    return 1
+  fi
+
+  ##we just return if 3rd octet is not 255
+  ##because we know the subnet is big enough
+  if [ "$i3" -ne 255 ]; then
+    return 0
+  elif [ $((254-$i4)) -ge "$num_ips_required" ]; then
+    return 0
+  else
+    echo -e "\n\n${red}ERROR: Subnet is too small${reset}\n\n"
+    return 1
+  fi
+}
+
+##finds last usable ip (broadcast minus 1) of a subnet from an IP and netmask
+## Warning: This function only works for IPv4 at the moment.
+##params: ip, netmask
+function find_last_ip_subnet {
+  IFS=. read -r i1 i2 i3 i4 <<< "$1"
+  IFS=. read -r m1 m2 m3 m4 <<< "$2"
+  IFS=. read -r s1 s2 s3 s4 <<< "$((i1 & m1)).$((i2 & m2)).$((i3 & m3)).$((i4 & m4))"
+  printf "%d.%d.%d.%d\n" "$((255 - $m1 + $s1))" "$((255 - $m2 + $s2))" "$((255 - $m3 + $s3))" "$((255 - $m4 + $s4 - 1))"
+}
+
 ##increments subnet by a value
 ##params: ip, value
 ##assumes low value
@@ -93,6 +157,19 @@ function next_ip {
   echo $baseaddr.$lsv
 }
 
+##subtracts a value from an IP address
+##params: last ip, ip_count
+##assumes ip_count is less than the last octect of the address
+subtract_ip() {
+  IFS=. read -r i1 i2 i3 i4 <<< "$1"
+  ip_count=$2
+  if [ $i4 -lt $ip_count ]; then
+    echo -e "\n\n${red}ERROR: Can't subtract $ip_count from IP address $1  Exiting${reset}\n\n"
+    exit 1
+  fi
+  printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 - $ip_count ))"
+}
+
 ##removes the network interface config from Vagrantfile
 ##params: interface
 ##assumes you are in the directory of Vagrantfile
@@ -196,6 +273,30 @@ parse_cmdline() {
                 ping_site=$2
                 shift 2
             ;;
+        -floating_ip_count)
+                floating_ip_count=$2
+                shift 2
+            ;;
+        -admin_nic)
+                admin_nic=$2
+                shift 2
+                nic_arg_flag=1
+            ;;
+        -private_nic)
+                private_nic=$2
+                shift 2
+                nic_arg_flag=1
+            ;;
+        -public_nic)
+                public_nic=$2
+                shift 2
+                nic_arg_flag=1
+            ;;
+        -storage_nic)
+                storage_nic=$2
+                shift 2
+                nic_arg_flag=1
+            ;;
         *)
                 display_usage
                 exit 1
@@ -217,6 +318,43 @@ parse_cmdline() {
       exit 1
     fi
   fi
+
+  if [ -z "$floating_ip_count" ]; then
+    floating_ip_count=20
+  fi
+
+  ##Validate nic args
+  if [ $nic_arg_flag -eq 1 ]; then
+    if [ -z "$virtual" ]; then
+      for nic_type in admin_nic private_nic public_nic; do
+        eval "nic_value=\$$nic_type"
+        if [ -z "$nic_value" ]; then
+          echo "${red}$nic_type is empty or not defined.  Required when other nic args are given!${reset}"
+          exit 1
+        fi
+        interface_ip=$(find_ip $nic_value)
+        if [ ! "$interface_ip" ]; then
+          echo "${red}$nic_value does not have an IP address! Exiting... ${reset}"
+          exit 1
+        fi
+      done
+    else
+      ##if virtual only public_nic should be specified
+      for nic_type in admin_nic private_nic storage_nic; do
+        eval "nic_value=\$$nic_type"
+        if [ ! -z "$nic_value" ]; then
+          echo "${red}$nic_type is not a valid argument using -virtual.  Please only specify public_nic!${reset}"
+          exit 1
+        fi
+      done
+
+      interface_ip=$(find_ip $public_nic)
+      if [ ! "$interface_ip" ]; then
+        echo "${red}Public NIC: $public_nic does not have an IP address! Exiting... ${reset}"
+        exit 1
+      fi
+    fi
+  fi
 }
 
 ##disable selinux
@@ -334,32 +472,52 @@ install_vagrant() {
 ##params: none
 ##usage: clean_tmp()
 clean_tmp() {
-  rm -rf /tmp/bgs_vagrant
+  rm -rf $vm_dir/foreman_vm
 }
 
-##clone bgs vagrant version 1.0 using git
+##clone genesis and move to node vm dir
 ##params: none
 ##usage: clone_bgs
 clone_bgs() {
   cd /tmp/
+  rm -rf /tmp/genesis/
 
-  ##will change this to be opnfv repo when commit is done
-  if ! git clone -b v1.0 https://github.com/trozet/bgs_vagrant.git; then
-    printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
+  ##clone artifacts and move into foreman_vm dir
+  if ! GIT_SSL_NO_VERIFY=true git clone https://gerrit.opnfv.org/gerrit/genesis.git; then
+    printf '%s\n' 'deploy.sh: Unable to clone genesis repo' >&2
     exit 1
   fi
+
+  mv -f /tmp/genesis/foreman/ci $vm_dir/foreman_vm
+  rm -rf /tmp/genesis/
 }
 
 ##validates the network settings and update VagrantFile with network settings
 ##params: none
 ##usage: configure_network()
 configure_network() {
-  cd /tmp/bgs_vagrant
+  cd $vm_dir/foreman_vm
 
-  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=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
+  ##if nic_arg_flag is set, then we don't figure out
+  ##NICs dynamically
+  if [ $nic_arg_flag -eq 1 ]; then
+    echo "${blue}Static Network Interfaces Defined.  Updating Vagrantfile...${reset}"
+    if [ $virtual ]; then
+      nic_list="$public_nic"
+    elif [ -z "$storage_nic" ]; then
+      echo "${blue}storage_nic not defined, will combine storage into private VLAN ${reset}"
+      nic_list="$admin_nic $private_nic $public_nic"
+    else
+      nic_list="$admin_nic $private_nic $public_nic $storage_nic"
+    fi
+    nic_array=( $nic_list )
+    output=$nic_list
+  else
+    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=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
+  fi
 
   if [ ! "$output" ]; then
     printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
@@ -368,10 +526,15 @@ configure_network() {
 
   ##virtual we only find 1 interface
   if [ $virtual ]; then
-    ##find interface with default gateway
-    this_default_gw=$(ip route | grep default | awk '{print $3}')
-    echo "${blue}Default Gateway: $this_default_gw ${reset}"
-    this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
+    if [ ! -z "${nic_array[0]}" ]; then
+      echo "${blue}Public Interface specified: ${nic_array[0]}${reset}"
+      this_default_gw_interface=${nic_array[0]}
+    else
+      ##find interface with default gateway
+      this_default_gw=$(ip route | grep default | awk '{print $3}')
+      echo "${blue}Default Gateway: $this_default_gw ${reset}"
+      this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
+    fi
 
     ##find interface IP, make sure its valid
     interface_ip=$(find_ip $this_default_gw_interface)
@@ -398,6 +561,11 @@ configure_network() {
     public_subnet_mask=$subnet_mask
     public_short_subnet_mask=$(find_short_netmask $interface)
 
+    if ! verify_subnet_size $public_subnet_mask 25; then
+      echo "${red} Not enough IPs in public subnet: $interface_ip_arr[2] ${public_subnet_mask}.  Need at least 25 IPs.  Please resize subnet! Exiting ${reset}"
+      exit 1
+    fi
+
     ##set that interface to be public
     sed -i 's/^.*eth_replace2.*$/  config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
     if_counter=1
@@ -422,14 +590,34 @@ configure_network() {
       subnet_mask=$(find_netmask $interface)
       if [ "$if_counter" -eq 0 ]; then
         admin_subnet_mask=$subnet_mask
+        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
+        fi
+
       elif [ "$if_counter" -eq 1 ]; then
         private_subnet_mask=$subnet_mask
         private_short_subnet_mask=$(find_short_netmask $interface)
+
+        if ! verify_subnet_size $private_subnet_mask 15; then
+          echo "${red} Not enough IPs in private subnet: ${interface_ip_arr[$if_counter]} ${private_subnet_mask}.  Need at least 15 IPs.  Please resize subnet! Exiting ${reset}"
+          exit 1
+        fi
       elif [ "$if_counter" -eq 2 ]; then
         public_subnet_mask=$subnet_mask
         public_short_subnet_mask=$(find_short_netmask $interface)
+
+        if ! verify_subnet_size $public_subnet_mask 25; then
+          echo "${red} Not enough IPs in public subnet: ${interface_ip_arr[$if_counter]} ${public_subnet_mask}.  Need at least 25 IPs.  Please resize subnet! Exiting ${reset}"
+          exit 1
+        fi
       elif [ "$if_counter" -eq 3 ]; then
         storage_subnet_mask=$subnet_mask
+
+        if ! verify_subnet_size $storage_subnet_mask 10; then
+          echo "${red} Not enough IPs in storage subnet: ${interface_ip_arr[$if_counter]} ${storage_subnet_mask}.  Need at least 10 IPs.  Please resize subnet! Exiting ${reset}"
+          exit 1
+        fi
       else
         echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
         exit 1
@@ -660,11 +848,11 @@ configure_network() {
       ##replace foreman site
       sed -i 's/^.*foreman_url:.*$/  foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
       ##replace public vips
-      ##no need to do this if virtual and no dhcp
-      if [ ! -z "$enable_virtual_dhcp" ]; then
-        next_public_ip=$(increment_ip $next_public_ip 10)
-      else
+      ##no need to do this if no dhcp
+      if [[ -z "$enable_virtual_dhcp" && ! -z "$virtual" ]]; then
         next_public_ip=$(next_usable_ip $next_public_ip)
+      else
+        next_public_ip=$(increment_ip $next_public_ip 10)
       fi
 
       public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
@@ -717,10 +905,10 @@ configure_network() {
 
       ##we have to define an allocation range of the public subnet to give
       ##to neutron to use as floating IPs
-      ##we should control this subnet, so this range should work .150-200
-      ##but generally this is a bad idea and we are assuming at least a /24 subnet here
       ##if static ip range, then we take the difference of the end range and current ip
       ## to be the allocation pool
+      ##if not static ip, we will use the last 20 IP from the subnet
+      ## note that this is not a really good idea because the subnet must be at least a /27 for this to work...
       public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
       if [ ! -z "$static_ip_range" ]; then
         begin_octet=$(echo $next_public_ip | cut -d . -f4)
@@ -732,14 +920,13 @@ configure_network() {
         else
           public_allocation_start=$(next_ip $next_public_ip)
           public_allocation_end=$static_ip_range_end
-          echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
         fi
       else
-        public_allocation_start=$(increment_subnet $public_subnet 150)
-        public_allocation_end=$(increment_subnet $public_subnet 200)
-        echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
-        echo "${blue}Foreman VM is up! ${reset}"
+        last_ip_subnet=$(find_last_ip_subnet $next_public_ip $public_subnet_mask)
+        public_allocation_start=$(subtract_ip $last_ip_subnet $floating_ip_count )
+        public_allocation_end=${last_ip_subnet}
       fi
+      echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
 
       sed -i 's/^.*public_allocation_start:.*$/  public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
       sed -i 's/^.*public_allocation_end:.*$/  public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
@@ -772,7 +959,7 @@ start_foreman() {
 
   ##stand up vagrant
   if ! vagrant up; then
-    printf '%s\n' 'deploy.sh: Unable to start vagrant' >&2
+    printf '%s\n' 'deploy.sh: Unable to complete Foreman VM install' >&2
     exit 1
   else
     echo "${blue}Foreman VM is up! ${reset}"
@@ -799,19 +986,22 @@ start_virtual_nodes() {
     compute_wait_completed=false
 
     for node in ${nodes}; do
-      cd /tmp
+      cd /tmp/
 
       ##remove VM nodes incase it wasn't cleaned up
-      rm -rf /tmp/$node
+      rm -rf $vm_dir/$node
+      rm -rf /tmp/genesis/
 
-      ##clone bgs vagrant
-      ##will change this to be opnfv repo when commit is done
-      if ! git clone https://github.com/trozet/bgs_vagrant.git $node; then
+      ##clone genesis and move into node folder
+      if ! GIT_SSL_NO_VERIFY=true git clone https://gerrit.opnfv.org/gerrit/genesis.git; then
         printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
         exit 1
       fi
 
-      cd $node
+      mv -f /tmp/genesis/foreman/ci $vm_dir/$node
+      rm -rf /tmp/genesis/
+
+      cd $vm_dir/$node
 
       if [ $base_config ]; then
         if ! cp -f $base_config opnfv_ksgen_settings.yml; then
@@ -833,117 +1023,65 @@ start_virtual_nodes() {
         sleep 1400
       fi
 
-      ##find number of interfaces with ip and substitute in VagrantFile
-      output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
-
-      if [ ! "$output" ]; then
-        printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
+      ## Add Admin interface
+      mac_string=config_nodes_${node}_mac_address
+      mac_addr=$(eval echo \$$mac_string)
+      mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
+      if [ $mac_addr == "" ]; then
+        echo "${red} Unable to find mac_address for $node! ${reset}"
         exit 1
       fi
+      this_admin_ip=${admin_ip_arr[$node]}
+      sed -i 's/^.*eth_replace0.*$/  config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$this_admin_ip"\"', netmask: '\""$admin_subnet_mask"\"', :mac => '\""$mac_addr"\"'/' Vagrantfile
 
-      if_counter=0
-      for interface in ${output}; do
-
-        if [ -z "$enable_virtual_dhcp" ]; then
-          if [ "$if_counter" -ge 1 ]; then
-            break
-          fi
-        elif [ "$if_counter" -ge 4 ]; then
-          break
-        fi
-        interface_ip=$(find_ip $interface)
-        if [ ! "$interface_ip" ]; then
-          continue
-        fi
-        case "${if_counter}" in
-          0)
-            mac_string=config_nodes_${node}_mac_address
-            mac_addr=$(eval echo \$$mac_string)
-            mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
-            if [ $mac_addr == "" ]; then
-              echo "${red} Unable to find mac_address for $node! ${reset}"
-              exit 1
-            fi
-            ;;
-          1)
-            if [ "$node_type" == "controller" ]; then
-              mac_string=config_nodes_${node}_private_mac
-              mac_addr=$(eval echo \$$mac_string)
-              if [ $mac_addr == "" ]; then
-                echo "${red} Unable to find private_mac for $node! ${reset}"
-                exit 1
-              fi
-            else
-              ##generate random mac
-              mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
-            fi
-            mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
-            ;;
-          *)
-            mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
-            mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
-            ;;
-        esac
-        this_admin_ip=${admin_ip_arr[$node]}
-        sed -i 's/^.*eth_replace'"$if_counter"'.*$/  config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$this_admin_ip"\"', netmask: '\""$admin_subnet_mask"\"', :mac => '\""$mac_addr"\"'/' Vagrantfile
-        ((if_counter++))
-      done
-      ##now remove interface config in Vagrantfile for 1 node
-      ##if 1, 3, or 4 interfaces set deployment type
-      ##if 2 interfaces remove 2nd interface and set deployment type
-      if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
-        deployment_type="single_network"
-        if [ "$node_type" == "controller" ]; then
-            mac_string=config_nodes_${node}_private_mac
-            mac_addr=$(eval echo \$$mac_string)
-            if [ $mac_addr == "" ]; then
-              echo "${red} Unable to find private_mac for $node! ${reset}"
-              exit 1
-            fi
-        else
-            ##generate random mac
-            mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
-        fi
-        mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
-        if [ "$node_type" == "controller" ]; then
-          new_node_ip=${controllers_ip_arr[$controller_count]}
-          if [ ! "$new_node_ip" ]; then
-            echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
-            exit 1
-          fi
-          ((controller_count++))
-        else
-          next_private_ip=$(next_ip $next_private_ip)
-          if [ ! "$next_private_ip" ]; then
-            echo "{red}ERROR: Could not find private ip for $node ${reset}"
+      ## Add private interface
+      if [ "$node_type" == "controller" ]; then
+          mac_string=config_nodes_${node}_private_mac
+          mac_addr=$(eval echo \$$mac_string)
+          if [ $mac_addr == "" ]; then
+            echo "${red} Unable to find private_mac for $node! ${reset}"
             exit 1
           fi
-          new_node_ip=$next_private_ip
+      else
+          ##generate random mac
+          mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
+      fi
+      mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
+      if [ "$node_type" == "controller" ]; then
+        new_node_ip=${controllers_ip_arr[$controller_count]}
+        if [ ! "$new_node_ip" ]; then
+          echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
+          exit 1
         fi
-        sed -i 's/^.*eth_replace1.*$/  config.vm.network "private_network", virtualbox__intnet: "my_private_network", :mac => '\""$mac_addr"\"', ip: '\""$new_node_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
-        ##replace host_ip in vm_nodes_provision with private ip
-        sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
-        ##replace ping site
-        if [ ! -z "$ping_site" ]; then
-          sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
+        ((controller_count++))
+      else
+        next_private_ip=$(next_ip $next_private_ip)
+        if [ ! "$next_private_ip" ]; then
+          echo "{red}ERROR: Could not find private ip for $node ${reset}"
+          exit 1
         fi
-        ##find public ip info
-        mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
-        mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
-        this_public_ip=${public_ip_arr[$node]}
+        new_node_ip=$next_private_ip
+      fi
+      sed -i 's/^.*eth_replace1.*$/  config.vm.network "private_network", virtualbox__intnet: "my_private_network", :mac => '\""$mac_addr"\"', ip: '\""$new_node_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
+      ##replace host_ip in vm_nodes_provision with private ip
+      sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
+      ##replace ping site
+      if [ ! -z "$ping_site" ]; then
+        sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
+      fi
 
-        if [ -z "$enable_virtual_dhcp" ]; then
-          sed -i 's/^.*eth_replace2.*$/  config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"', ip: '\""$this_public_ip"\"', netmask: '\""$public_subnet_mask"\"'/' Vagrantfile
-        else
-          sed -i 's/^.*eth_replace2.*$/  config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
-        fi
-        remove_vagrant_network eth_replace3
-      elif [ "$if_counter" == 3 ]; then
-        deployment_type="three_network"
-        remove_vagrant_network eth_replace3
+      ##find public ip info and add public interface
+      mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
+      mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
+      this_public_ip=${public_ip_arr[$node]}
+
+      if [ -z "$enable_virtual_dhcp" ]; then
+        sed -i 's/^.*eth_replace2.*$/  config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"', ip: '\""$this_public_ip"\"', netmask: '\""$public_subnet_mask"\"'/' Vagrantfile
       else
-        deployment_type="multi_network"
+        sed -i 's/^.*eth_replace2.*$/  config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
       fi
+      remove_vagrant_network eth_replace3
+
       ##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
@@ -974,7 +1112,7 @@ start_virtual_nodes() {
     echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
     ##check puppet is complete
     ##ssh into foreman server, run check to verify puppet is complete
-    pushd /tmp/bgs_vagrant
+    pushd $vm_dir/foreman_vm
     if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
       echo "${red} Failed to validate puppet completion on nodes ${reset}"
       exit 1
@@ -984,7 +1122,7 @@ start_virtual_nodes() {
     popd
     ##add routes back to nodes
     for node in ${nodes}; do
-      pushd /tmp/$node
+      pushd $vm_dir/$node
       if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
         echo "${blue} Adding public route back to $node! ${reset}"
         vagrant ssh -c "route add default gw $this_default_gw"
@@ -1009,6 +1147,7 @@ main() {
   install_ansible
   install_vagrant
   clean_tmp
+  verify_vm_dir
   clone_bgs
   configure_network
   configure_virtual