3 #Deploy script to install provisioning server for Foreman/QuickStack
4 #author: Tim Rozet (trozet@redhat.com)
6 #Uses Vagrant and VirtualBox
7 #VagrantFile uses bootsrap.sh which Installs Khaleesi
8 #Khaleesi will install and configure Foreman/QuickStack
11 #Supports 3 or 4 network interface configuration
12 #Target system must be RPM based
13 #Ensure the host's kernel is up to date (yum update)
14 #Provisioned nodes expected to have following order of network connections (note: not all have to exist, but order is maintained):
16 #eth1- private network (+storage network in 3 NIC config)
18 #eth3- storage network
19 #script assumes /24 subnet mask
27 declare -A interface_arr
28 declare -A controllers_ip_arr
29 declare -A admin_ip_arr
30 declare -A public_ip_arr
35 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
36 echo -e "\n${green}Make sure you have the latest kernel installed before running this script! (yum update kernel +reboot)${reset}\n"
37 echo -e "\nUsage:\n$0 [arguments] \n"
38 echo -e "\n -no_parse : No variable parsing into config. Flag. \n"
39 echo -e "\n -base_config : Full path of settings file to parse. Optional. Will provide a new base settings file rather than the default. Example: -base_config /opt/myinventory.yml \n"
40 echo -e "\n -virtual : Node virtualization instead of baremetal. Flag. \n"
41 echo -e "\n -enable_virtual_dhcp : Run dhcp server instead of using static IPs. Use this with -virtual only. \n"
42 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"
43 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"
46 ##find ip of interface
47 ##params: interface name
49 ip addr show $1 | grep -Eo '^\s+inet\s+[\.0-9]+' | awk '{print $2}'
52 ##finds subnet of ip and netmask
54 function find_subnet {
55 IFS=. read -r i1 i2 i3 i4 <<< "$1"
56 IFS=. read -r m1 m2 m3 m4 <<< "$2"
57 printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
60 ##increments subnet by a value
63 function increment_subnet {
64 IFS=. read -r i1 i2 i3 i4 <<< "$1"
65 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 | $2))"
69 ##finds netmask of interface
71 ##returns long format 255.255.x.x
72 function find_netmask {
73 ifconfig $1 | grep -Eo 'netmask\s+[\.0-9]+' | awk '{print $2}'
76 ##finds short netmask of interface
78 ##returns short format, ex: /21
79 function find_short_netmask {
80 echo "/$(ip addr show $1 | grep -Eo '^\s+inet\s+[\/\.0-9]+' | awk '{print $2}' | cut -d / -f2)"
85 ##assumes a /24 subnet
87 baseaddr="$(echo $1 | cut -d. -f1-3)"
88 lsv="$(echo $1 | cut -d. -f4)"
89 if [ "$lsv" -ge 254 ]; then
96 ##removes the network interface config from Vagrantfile
98 ##assumes you are in the directory of Vagrantfile
99 function remove_vagrant_network {
100 sed -i 's/^.*'"$1"'.*$//' Vagrantfile
103 ##check if IP is in use
105 ##ping ip to get arp entry, then check arp
106 function is_ip_used {
107 ping -c 5 $1 > /dev/null 2>&1
108 arp -n | grep "$1 " | grep -iv incomplete > /dev/null 2>&1
111 ##find next usable IP
113 function next_usable_ip {
115 while [ "$new_ip" ]; do
116 if ! is_ip_used $new_ip; then
120 new_ip=$(next_ip $new_ip)
125 ##increment ip by value
126 ##params: ip, amount to increment by
127 ##increment_ip $next_private_ip 10
128 function increment_ip {
129 baseaddr="$(echo $1 | cut -d. -f1-3)"
130 lsv="$(echo $1 | cut -d. -f4)"
133 if [ "$lsv" -ge 254 ]; then
139 ##translates yaml into variables
140 ##params: filename, prefix (ex. "config_")
141 ##usage: parse_yaml opnfv_ksgen_settings.yml "config_"
144 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
145 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
146 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
148 indent = length($1)/2;
150 for (i in vname) {if (i > indent) {delete vname[i]}}
151 if (length($3) > 0) {
152 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
153 printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
158 ##translates the command line paramaters into variables
159 ##params: $@ the entire command line is passed
160 ##usage: parse_cmd_line() "$@"
162 if [[ ( $1 == "--help") || $1 == "-h" ]]; then
167 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
168 echo "Use -h to display help"
171 while [ "`echo $1 | cut -c1`" = "-" ]
187 -enable_virtual_dhcp)
188 enable_virtual_dhcp="TRUE"
206 if [ ! -z "$enable_virtual_dhcp" ] && [ ! -z "$static_ip_range" ]; then
207 echo -e "\n\n${red}ERROR: Incorrect Usage. Static IP range cannot be set when using DHCP!. Exiting${reset}\n\n"
211 if [ -z "$virtual" ]; then
212 if [ ! -z "$enable_virtual_dhcp" ]; then
213 echo -e "\n\n${red}ERROR: Incorrect Usage. enable_virtual_dhcp can only be set when using -virtual!. Exiting${reset}\n\n"
215 elif [ ! -z "$static_ip_range" ]; then
216 echo -e "\n\n${red}ERROR: Incorrect Usage. static_ip_range can only be set when using -virtual!. Exiting${reset}\n\n"
224 ##usage: disable_selinux()
229 ##Install the EPEL repository and additional packages
231 ##usage: install_EPEL()
233 # Install EPEL repo for access to many other yum repos
234 # Major version is pinned to force some consistency for Arno
235 yum install -y epel-release-7*
237 # Install other required packages
238 # Major versions are pinned to force some consistency for Arno
239 if ! yum install -y binutils-2* gcc-4* make-3* patch-2* libgomp-4* glibc-headers-2* glibc-devel-2* kernel-headers-3* kernel-devel-3* dkms-2* psmisc-22*; then
240 printf '%s\n' 'deploy.sh: Unable to install depdency packages' >&2
245 ##Download and install virtual box
247 ##usage: install_vbox()
249 ##install VirtualBox repo
250 if cat /etc/*release | grep -i "Fedora release"; then
251 vboxurl=http://download.virtualbox.org/virtualbox/rpm/fedora/\$releasever/\$basearch
253 vboxurl=http://download.virtualbox.org/virtualbox/rpm/el/\$releasever/\$basearch
256 cat > /etc/yum.repos.d/virtualbox.repo << EOM
258 name=Oracle Linux / RHEL / CentOS-\$releasever / \$basearch - VirtualBox
262 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
263 skip_if_unavailable = 1
268 if ! yum list installed | grep -i virtualbox; then
269 if ! yum -y install VirtualBox-4.3; then
270 printf '%s\n' 'deploy.sh: Unable to install virtualbox package' >&2
275 ##install kmod-VirtualBox
276 if ! lsmod | grep vboxdrv; then
277 sudo /etc/init.d/vboxdrv setup
278 if ! lsmod | grep vboxdrv; then
279 printf '%s\n' 'deploy.sh: Unable to install kernel module for virtualbox' >&2
283 printf '%s\n' 'deploy.sh: Skipping kernel module for virtualbox. Already Installed'
287 ##install Ansible using yum
289 ##usage: install_ansible()
291 if ! yum list installed | grep -i ansible; then
292 if ! yum -y install ansible-1*; then
293 printf '%s\n' 'deploy.sh: Unable to install Ansible package' >&2
299 ##install Vagrant RPM directly with the bintray.com site
301 ##usage: install_vagrant()
303 if ! rpm -qa | grep vagrant; then
304 if ! rpm -Uvh https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm; then
305 printf '%s\n' 'deploy.sh: Unable to install vagrant package' >&2
309 printf '%s\n' 'deploy.sh: Skipping Vagrant install as it is already installed.'
312 ##add centos 7 box to vagrant
313 if ! vagrant box list | grep chef/centos-7.0; then
314 if ! vagrant box add chef/centos-7.0 --provider virtualbox; then
315 printf '%s\n' 'deploy.sh: Unable to download centos7 box for Vagrant' >&2
319 printf '%s\n' 'deploy.sh: Skipping Vagrant box add as centos-7.0 is already installed.'
322 ##install workaround for centos7
323 if ! vagrant plugin list | grep vagrant-centos7_fix; then
324 if ! vagrant plugin install vagrant-centos7_fix; then
325 printf '%s\n' 'deploy.sh: Warning: unable to install vagrant centos7 workaround' >&2
328 printf '%s\n' 'deploy.sh: Skipping Vagrant plugin as centos7 workaround is already installed.'
333 ##remove bgs vagrant incase it wasn't cleaned up
337 rm -rf /tmp/bgs_vagrant
340 ##clone bgs vagrant version 1.0 using git
346 ##will change this to be opnfv repo when commit is done
347 if ! git clone -b v1.0 https://github.com/trozet/bgs_vagrant.git; then
348 printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
353 ##validates the network settings and update VagrantFile with network settings
355 ##usage: configure_network()
356 configure_network() {
359 echo "${blue}Detecting network configuration...${reset}"
360 ##detect host 1 or 3 interface configuration
361 #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
362 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
364 if [ ! "$output" ]; then
365 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
369 ##virtual we only find 1 interface
370 if [ $virtual ]; then
371 ##find interface with default gateway
372 this_default_gw=$(ip route | grep default | awk '{print $3}')
373 echo "${blue}Default Gateway: $this_default_gw ${reset}"
374 this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
376 ##find interface IP, make sure its valid
377 interface_ip=$(find_ip $this_default_gw_interface)
378 if [ ! "$interface_ip" ]; then
379 echo "${red}Interface ${this_default_gw_interface} does not have an IP: $interface_ip ! Exiting ${reset}"
384 if [ ! -z "$static_ip_range" ]; then
385 new_ip=$(echo $static_ip_range | cut -d , -f1)
387 new_ip=$(next_usable_ip $interface_ip)
388 if [ ! "$new_ip" ]; then
389 echo "${red} Cannot find next IP on interface ${this_default_gw_interface} new_ip: $new_ip ! Exiting ${reset}"
393 interface=$this_default_gw_interface
394 public_interface=$interface
395 interface_arr[$interface]=2
396 interface_ip_arr[2]=$new_ip
397 subnet_mask=$(find_netmask $interface)
398 public_subnet_mask=$subnet_mask
399 public_short_subnet_mask=$(find_short_netmask $interface)
401 ##set that interface to be public
402 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
405 ##find number of interfaces with ip and substitute in VagrantFile
407 for interface in ${output}; do
409 if [ "$if_counter" -ge 4 ]; then
412 interface_ip=$(find_ip $interface)
413 if [ ! "$interface_ip" ]; then
416 new_ip=$(next_usable_ip $interface_ip)
417 if [ ! "$new_ip" ]; then
420 interface_arr[$interface]=$if_counter
421 interface_ip_arr[$if_counter]=$new_ip
422 subnet_mask=$(find_netmask $interface)
423 if [ "$if_counter" -eq 0 ]; then
424 admin_subnet_mask=$subnet_mask
425 elif [ "$if_counter" -eq 1 ]; then
426 private_subnet_mask=$subnet_mask
427 private_short_subnet_mask=$(find_short_netmask $interface)
428 elif [ "$if_counter" -eq 2 ]; then
429 public_subnet_mask=$subnet_mask
430 public_short_subnet_mask=$(find_short_netmask $interface)
431 elif [ "$if_counter" -eq 3 ]; then
432 storage_subnet_mask=$subnet_mask
434 echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
437 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
441 ##now remove interface config in Vagrantfile for 1 node
442 ##if 1, 3, or 4 interfaces set deployment type
443 ##if 2 interfaces remove 2nd interface and set deployment type
444 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
445 if [ $virtual ]; then
446 deployment_type="single_network"
447 echo "${blue}Single network detected for Virtual deployment...converting to three_network with internal networks! ${reset}"
448 private_internal_ip=155.1.2.2
449 admin_internal_ip=156.1.2.2
450 private_subnet_mask=255.255.255.0
451 private_short_subnet_mask=/24
452 interface_ip_arr[1]=$private_internal_ip
453 interface_ip_arr[0]=$admin_internal_ip
454 admin_subnet_mask=255.255.255.0
455 admin_short_subnet_mask=/24
456 sed -i 's/^.*eth_replace1.*$/ config.vm.network "private_network", virtualbox__intnet: "my_private_network", ip: '\""$private_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
457 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$admin_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
458 remove_vagrant_network eth_replace3
459 deployment_type=three_network
461 echo "${blue}Single network or 2 network detected for baremetal deployment. This is unsupported! Exiting. ${reset}"
464 elif [ "$if_counter" == 3 ]; then
465 deployment_type="three_network"
466 remove_vagrant_network eth_replace3
468 deployment_type="multi_network"
471 echo "${blue}Network detected: ${deployment_type}! ${reset}"
473 if [ $virtual ]; then
474 if [ -z "$enable_virtual_dhcp" ]; then
475 sed -i 's/^.*disable_dhcp_flag =.*$/ disable_dhcp_flag = true/' Vagrantfile
476 if [ $static_ip_range ]; then
477 ##verify static range is at least 20 IPs
478 static_ip_range_begin=$(echo $static_ip_range | cut -d , -f1)
479 static_ip_range_end=$(echo $static_ip_range | cut -d , -f2)
480 ##verify range is at least 20 ips
481 ##assumes less than 255 range pool
482 begin_octet=$(echo $static_ip_range_begin | cut -d . -f4)
483 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
484 ip_count=$((end_octet-begin_octet+1))
485 if [ "$ip_count" -lt 20 ]; then
486 echo "${red}Static range is less than 20 ips: ${ip_count}, exiting ${reset}"
489 echo "${blue}Static IP range is size $ip_count ${reset}"
495 if route | grep default; then
496 echo "${blue}Default Gateway Detected ${reset}"
497 host_default_gw=$(ip route | grep default | awk '{print $3}')
498 echo "${blue}Default Gateway: $host_default_gw ${reset}"
499 default_gw_interface=$(ip route get $host_default_gw | awk '{print $3}')
500 case "${interface_arr[$default_gw_interface]}" in
502 echo "${blue}Default Gateway Detected on Admin Interface!${reset}"
503 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
504 node_default_gw=$host_default_gw
507 echo "${red}Default Gateway Detected on Private Interface!${reset}"
508 echo "${red}Private subnet should be private and not have Internet access!${reset}"
512 echo "${blue}Default Gateway Detected on Public Interface!${reset}"
513 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
514 echo "${blue}Will setup NAT from Admin -> Public Network on VM!${reset}"
515 sed -i 's/^.*nat_flag =.*$/ nat_flag = true/' Vagrantfile
516 echo "${blue}Setting node gateway to be VM Admin IP${reset}"
517 node_default_gw=${interface_ip_arr[0]}
518 public_gateway=$default_gw
521 echo "${red}Default Gateway Detected on Storage Interface!${reset}"
522 echo "${red}Storage subnet should be private and not have Internet access!${reset}"
526 echo "${red}Unable to determine which interface default gateway is on..Exiting!${reset}"
532 defaultgw=`echo ${interface_ip_arr[0]} | cut -d. -f1-3`
534 defaultgw=$defaultgw$firstip
535 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
536 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
537 node_default_gw=$defaultgw
540 if [ $base_config ]; then
541 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
542 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
547 if [ $no_parse ]; then
548 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
552 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
553 ##Edit the ksgen settings appropriately
554 ##ksgen settings will be stored in /vagrant on the vagrant machine
555 ##if single node deployment all the variables will have the same ip
556 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
558 sed -i 's/^.*default_gw:.*$/default_gw:'" $node_default_gw"'/' opnfv_ksgen_settings.yml
560 ##replace private interface parameter
561 ##private interface will be of hosts, so we need to know the provisioned host interface name
562 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
563 ##replace IP for parameters with next IP that will be given to controller
564 if [ "$deployment_type" == "single_network" ]; then
565 ##we also need to assign IP addresses to nodes
566 ##for single node, foreman is managing the single network, so we can't reserve them
567 ##not supporting single network anymore for now
568 echo "{blue}Single Network type is unsupported right now. Please check your interface configuration. Exiting. ${reset}"
571 elif [[ "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
573 if [ "$deployment_type" == "three_network" ]; then
574 sed -i 's/^.*network_type:.*$/network_type: three_network/' opnfv_ksgen_settings.yml
577 sed -i 's/^.*deployment_type:.*$/ deployment_type: '"$deployment_type"'/' opnfv_ksgen_settings.yml
579 ##get ip addresses for private network on controllers to make dhcp entries
580 ##required for controllers_ip_array global param
581 next_private_ip=${interface_ip_arr[1]}
584 for node in controller1 controller2 controller3; do
585 next_private_ip=$(next_usable_ip $next_private_ip)
586 if [ ! "$next_private_ip" ]; then
587 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
590 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
591 controller_ip_array=$controller_ip_array$next_private_ip,
592 controllers_ip_arr[$control_count]=$next_private_ip
596 next_public_ip=${interface_ip_arr[2]}
597 foreman_ip=$next_public_ip
599 ##if no dhcp, find all the Admin IPs for nodes in advance
600 if [ $virtual ]; then
601 if [ -z "$enable_virtual_dhcp" ]; then
602 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
603 nodes=`sed -nr '/nodes:/{:start /workaround/!{N;b start};//p}' opnfv_ksgen_settings.yml | sed -n '/^ [A-Za-z0-9]\+:$/p' | sed 's/\s*//g' | sed 's/://g'`
604 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
605 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
606 nodes=${controller_nodes}${compute_nodes}
607 next_admin_ip=${interface_ip_arr[0]}
609 for node in ${nodes}; do
610 next_admin_ip=$(next_ip $next_admin_ip)
611 if [ ! "$next_admin_ip" ]; then
612 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
615 admin_ip_arr[$node]=$next_admin_ip
616 sed -i 's/'"$node$type"'/'"$next_admin_ip"'/g' opnfv_ksgen_settings.yml
620 ##allocate node public IPs
621 for node in ${nodes}; do
622 next_public_ip=$(next_usable_ip $next_public_ip)
623 if [ ! "$next_public_ip" ]; then
624 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
627 public_ip_arr[$node]=$next_public_ip
632 ##replace global param for controllers_ip_array
633 controller_ip_array=${controller_ip_array%?}
634 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
636 ##now replace all the VIP variables. admin//private can be the same IP
637 ##we have to use IP's here that won't be allocated to hosts at provisioning time
638 ##therefore we increment the ip by 10 to make sure we have a safe buffer
639 next_private_ip=$(increment_ip $next_private_ip 10)
641 private_output=$(grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml)
642 if [ ! -z "$private_output" ]; then
643 while read -r line; do
644 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
645 next_private_ip=$(next_usable_ip $next_private_ip)
646 if [ ! "$next_private_ip" ]; then
647 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
650 done <<< "$private_output"
653 ##replace odl_control_ip (non-HA only)
654 odl_control_ip=${controllers_ip_arr[0]}
655 sed -i 's/^.*odl_control_ip:.*$/ odl_control_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
657 ##replace controller_ip (non-HA only)
658 sed -i 's/^.*controller_ip:.*$/ controller_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
660 ##replace foreman site
661 sed -i 's/^.*foreman_url:.*$/ foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
662 ##replace public vips
663 ##no need to do this if virtual and no dhcp
664 if [ ! -z "$enable_virtual_dhcp" ]; then
665 next_public_ip=$(increment_ip $next_public_ip 10)
667 next_public_ip=$(next_usable_ip $next_public_ip)
670 public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
671 if [ ! -z "$public_output" ]; then
672 while read -r line; do
673 if echo $line | grep horizon_public_vip; then
674 horizon_public_vip=$next_public_ip
676 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
677 next_public_ip=$(next_usable_ip $next_public_ip)
678 if [ ! "$next_public_ip" ]; then
679 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
682 done <<< "$public_output"
685 ##replace public_network param
686 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
687 sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
688 ##replace private_network param
689 private_subnet=$(find_subnet $next_private_ip $private_subnet_mask)
690 sed -i 's/^.*private_network:.*$/ private_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
691 ##replace storage_network
692 if [ "$deployment_type" == "three_network" ]; then
693 sed -i 's/^.*storage_network:.*$/ storage_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
695 next_storage_ip=${interface_ip_arr[3]}
696 storage_subnet=$(find_subnet $next_storage_ip $storage_subnet_mask)
697 sed -i 's/^.*storage_network:.*$/ storage_network:'" $storage_subnet"'/' opnfv_ksgen_settings.yml
700 ##replace public_subnet param
701 public_subnet=$public_subnet'\'$public_short_subnet_mask
702 sed -i 's/^.*public_subnet:.*$/ public_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
703 ##replace private_subnet param
704 private_subnet=$private_subnet'\'$private_short_subnet_mask
705 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"'/' opnfv_ksgen_settings.yml
707 ##replace public_dns param to be foreman server
708 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[2]}'/' opnfv_ksgen_settings.yml
710 ##replace public_gateway
711 if [ -z "$public_gateway" ]; then
712 ##if unset then we assume its the first IP in the public subnet
713 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
714 public_gateway=$(increment_subnet $public_subnet 1)
716 sed -i 's/^.*public_gateway:.*$/ public_gateway:'" $public_gateway"'/' opnfv_ksgen_settings.yml
718 ##we have to define an allocation range of the public subnet to give
719 ##to neutron to use as floating IPs
720 ##we should control this subnet, so this range should work .150-200
721 ##but generally this is a bad idea and we are assuming at least a /24 subnet here
722 ##if static ip range, then we take the difference of the end range and current ip
723 ## to be the allocation pool
724 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
725 if [ ! -z "$static_ip_range" ]; then
726 begin_octet=$(echo $next_public_ip | cut -d . -f4)
727 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
728 ip_diff=$((end_octet-begin_octet))
729 if [ $ip_diff -le 0 ]; then
730 echo "${red}ip range left for floating range is less than or equal to 0! $ipdiff ${reset}"
733 public_allocation_start=$(next_ip $next_public_ip)
734 public_allocation_end=$static_ip_range_end
735 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
738 public_allocation_start=$(increment_subnet $public_subnet 150)
739 public_allocation_end=$(increment_subnet $public_subnet 200)
740 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
741 echo "${blue}Foreman VM is up! ${reset}"
744 sed -i 's/^.*public_allocation_start:.*$/ public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
745 sed -i 's/^.*public_allocation_end:.*$/ public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
748 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
752 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
757 ##Configure bootstrap.sh to use the virtual Khaleesi playbook
759 ##usage: configure_virtual()
760 configure_virtual() {
761 if [ $virtual ]; then
762 echo "${blue} Virtual flag detected, setting Khaleesi playbook to be opnfv-vm.yml ${reset}"
763 sed -i 's/opnfv.yml/opnfv-vm.yml/' bootstrap.sh
767 ##Starts Foreman VM with Vagrant
769 ##usage: start_vagrant()
771 echo "${blue}Starting Vagrant! ${reset}"
774 if ! vagrant up; then
775 printf '%s\n' 'deploy.sh: Unable to start vagrant' >&2
778 echo "${blue}Foreman VM is up! ${reset}"
782 ##start the VM if this is a virtual installation
783 ##this function does nothing if baremetal servers are being used
785 ##usage: start_virtual_nodes()
786 start_virtual_nodes() {
787 if [ $virtual ]; then
790 echo "${blue}Setting VMs up... ${reset}"
791 nodes=`sed -nr '/nodes:/{:start /workaround/!{N;b start};//p}' opnfv_ksgen_settings.yml | sed -n '/^ [A-Za-z0-9]\+:$/p' | sed 's/\s*//g' | sed 's/://g'`
792 ##due to ODL Helium bug of OVS connecting to ODL too early, we need controllers to install first
793 ##this is fix kind of assumes more than I would like to, but for now it should be OK as we always have
794 ##3 static controllers
795 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
796 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
797 nodes=${controller_nodes}${compute_nodes}
799 compute_wait_completed=false
801 for node in ${nodes}; do
804 ##remove VM nodes incase it wasn't cleaned up
808 ##will change this to be opnfv repo when commit is done
809 if ! git clone https://github.com/trozet/bgs_vagrant.git $node; then
810 printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
816 if [ $base_config ]; then
817 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
818 echo "${red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
823 ##parse yaml into variables
824 eval $(parse_yaml opnfv_ksgen_settings.yml "config_")
826 node_type=config_nodes_${node}_type
827 node_type=$(eval echo \$$node_type)
829 ##trozet test make compute nodes wait 20 minutes
830 if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
831 echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
832 compute_wait_completed=true
836 ##find number of interfaces with ip and substitute in VagrantFile
837 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
839 if [ ! "$output" ]; then
840 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
845 for interface in ${output}; do
847 if [ -z "$enable_virtual_dhcp" ]; then
848 if [ "$if_counter" -ge 1 ]; then
851 elif [ "$if_counter" -ge 4 ]; then
854 interface_ip=$(find_ip $interface)
855 if [ ! "$interface_ip" ]; then
858 case "${if_counter}" in
860 mac_string=config_nodes_${node}_mac_address
861 mac_addr=$(eval echo \$$mac_string)
862 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
863 if [ $mac_addr == "" ]; then
864 echo "${red} Unable to find mac_address for $node! ${reset}"
869 if [ "$node_type" == "controller" ]; then
870 mac_string=config_nodes_${node}_private_mac
871 mac_addr=$(eval echo \$$mac_string)
872 if [ $mac_addr == "" ]; then
873 echo "${red} Unable to find private_mac for $node! ${reset}"
877 ##generate random mac
878 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
880 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
883 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
884 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
887 this_admin_ip=${admin_ip_arr[$node]}
888 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
891 ##now remove interface config in Vagrantfile for 1 node
892 ##if 1, 3, or 4 interfaces set deployment type
893 ##if 2 interfaces remove 2nd interface and set deployment type
894 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
895 deployment_type="single_network"
896 if [ "$node_type" == "controller" ]; then
897 mac_string=config_nodes_${node}_private_mac
898 mac_addr=$(eval echo \$$mac_string)
899 if [ $mac_addr == "" ]; then
900 echo "${red} Unable to find private_mac for $node! ${reset}"
904 ##generate random mac
905 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
907 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
908 if [ "$node_type" == "controller" ]; then
909 new_node_ip=${controllers_ip_arr[$controller_count]}
910 if [ ! "$new_node_ip" ]; then
911 echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
914 ((controller_count++))
916 next_private_ip=$(next_ip $next_private_ip)
917 if [ ! "$next_private_ip" ]; then
918 echo "{red}ERROR: Could not find private ip for $node ${reset}"
921 new_node_ip=$next_private_ip
923 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
924 ##replace host_ip in vm_nodes_provision with private ip
925 sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
927 if [ ! -z "$ping_site" ]; then
928 sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
930 ##find public ip info
931 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
932 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
933 this_public_ip=${public_ip_arr[$node]}
935 if [ -z "$enable_virtual_dhcp" ]; then
936 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
938 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
940 remove_vagrant_network eth_replace3
941 elif [ "$if_counter" == 3 ]; then
942 deployment_type="three_network"
943 remove_vagrant_network eth_replace3
945 deployment_type="multi_network"
947 ##modify provisioning to do puppet install, config, and foreman check-in
948 ##substitute host_name and dns_server in the provisioning script
949 host_string=config_nodes_${node}_hostname
950 host_name=$(eval echo \$$host_string)
951 sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
952 ##dns server should be the foreman server
953 sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
954 ## remove bootstrap and NAT provisioning
955 sed -i '/nat_setup.sh/d' Vagrantfile
956 sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
957 ## modify default_gw to be node_default_gw
958 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
959 ## modify VM memory to be 4gig
960 ##if node type is controller
961 if [ "$node_type" == "controller" ]; then
962 sed -i 's/^.*vb.memory =.*$/ vb.memory = 4096/' Vagrantfile
964 echo "${blue}Starting Vagrant Node $node! ${reset}"
966 if ! vagrant up; then
967 echo "${red} Unable to start $node ${reset}"
970 echo "${blue} $node VM is up! ${reset}"
973 echo "${blue} All VMs are UP! ${reset}"
974 echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
975 ##check puppet is complete
976 ##ssh into foreman server, run check to verify puppet is complete
977 pushd /tmp/bgs_vagrant
978 if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
979 echo "${red} Failed to validate puppet completion on nodes ${reset}"
982 echo "{$blue} Puppet complete on all nodes! ${reset}"
985 ##add routes back to nodes
986 for node in ${nodes}; do
988 if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
989 echo "${blue} Adding public route back to $node! ${reset}"
990 vagrant ssh -c "route add default gw $this_default_gw"
994 if [ ! -z "$horizon_public_vip" ]; then
995 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
997 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${odl_control_ip} ${reset}"