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
37 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
38 echo -e "\n${green}Make sure you have the latest kernel installed before running this script! (yum update kernel +reboot)${reset}\n"
39 echo -e "\nUsage:\n$0 [arguments] \n"
40 echo -e "\n -no_parse : No variable parsing into config. Flag. \n"
41 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"
42 echo -e "\n -virtual : Node virtualization instead of baremetal. Flag. \n"
43 echo -e "\n -enable_virtual_dhcp : Run dhcp server instead of using static IPs. Use this with -virtual only. \n"
44 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"
45 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 echo -e "\n -floating_ip_count : number of IP address from the public range to be used for floating IP. Default is 20.\n"
49 ##verify vm dir exists
51 function verify_vm_dir {
52 if [ -d "$vm_dir" ]; then
53 echo -e "\n\n${red}ERROR: VM Directory: $vm_dir already exists. Environment not clean. Please use clean.sh. Exiting${reset}\n\n"
61 if [ ! -d $vm_dir ]; then
62 echo -e "\n\n${red}ERROR: Unable to create VM Directory: $vm_dir Exiting${reset}\n\n"
67 ##find ip of interface
68 ##params: interface name
70 ip addr show $1 | grep -Eo '^\s+inet\s+[\.0-9]+' | awk '{print $2}'
73 ##finds subnet of ip and netmask
75 function find_subnet {
76 IFS=. read -r i1 i2 i3 i4 <<< "$1"
77 IFS=. read -r m1 m2 m3 m4 <<< "$2"
78 printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
81 ##verify subnet has at least n IPs
82 ##params: subnet mask, n IPs
83 function verify_subnet_size {
84 IFS=. read -r i1 i2 i3 i4 <<< "$1"
87 ##this function assumes you would never need more than 254
88 ##we check here to make sure
89 if [ "$num_ips_required" -ge 254 ]; then
90 echo -e "\n\n${red}ERROR: allocating more than 254 IPs is unsupported...Exiting${reset}\n\n"
94 ##we just return if 3rd octet is not 255
95 ##because we know the subnet is big enough
96 if [ "$i3" -ne 255 ]; then
98 elif [ $((254-$i4)) -ge "$num_ips_required" ]; then
101 echo -e "\n\n${red}ERROR: Subnet is too small${reset}\n\n"
106 ##finds last usable ip (broadcast minus 1) of a subnet from an IP and netmask
107 ## Warning: This function only works for IPv4 at the moment.
108 ##params: ip, netmask
109 function find_last_ip_subnet {
110 IFS=. read -r i1 i2 i3 i4 <<< "$1"
111 IFS=. read -r m1 m2 m3 m4 <<< "$2"
112 IFS=. read -r s1 s2 s3 s4 <<< "$((i1 & m1)).$((i2 & m2)).$((i3 & m3)).$((i4 & m4))"
113 printf "%d.%d.%d.%d\n" "$((255 - $m1 + $s1))" "$((255 - $m2 + $s2))" "$((255 - $m3 + $s3))" "$((255 - $m4 + $s4 - 1))"
116 ##increments subnet by a value
119 function increment_subnet {
120 IFS=. read -r i1 i2 i3 i4 <<< "$1"
121 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 | $2))"
125 ##finds netmask of interface
127 ##returns long format 255.255.x.x
128 function find_netmask {
129 ifconfig $1 | grep -Eo 'netmask\s+[\.0-9]+' | awk '{print $2}'
132 ##finds short netmask of interface
134 ##returns short format, ex: /21
135 function find_short_netmask {
136 echo "/$(ip addr show $1 | grep -Eo '^\s+inet\s+[\/\.0-9]+' | awk '{print $2}' | cut -d / -f2)"
141 ##assumes a /24 subnet
143 baseaddr="$(echo $1 | cut -d. -f1-3)"
144 lsv="$(echo $1 | cut -d. -f4)"
145 if [ "$lsv" -ge 254 ]; then
152 ##subtracts a value from an IP address
153 ##params: last ip, ip_count
154 ##assumes ip_count is less than the last octect of the address
156 IFS=. read -r i1 i2 i3 i4 <<< "$1"
158 if [ $i4 -lt $ip_count ]; then
159 echo -e "\n\n${red}ERROR: Can't subtract $ip_count from IP address $1 Exiting${reset}\n\n"
162 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 - $ip_count ))"
165 ##removes the network interface config from Vagrantfile
167 ##assumes you are in the directory of Vagrantfile
168 function remove_vagrant_network {
169 sed -i 's/^.*'"$1"'.*$//' Vagrantfile
172 ##check if IP is in use
174 ##ping ip to get arp entry, then check arp
175 function is_ip_used {
176 ping -c 5 $1 > /dev/null 2>&1
177 arp -n | grep "$1 " | grep -iv incomplete > /dev/null 2>&1
180 ##find next usable IP
182 function next_usable_ip {
184 while [ "$new_ip" ]; do
185 if ! is_ip_used $new_ip; then
189 new_ip=$(next_ip $new_ip)
194 ##increment ip by value
195 ##params: ip, amount to increment by
196 ##increment_ip $next_private_ip 10
197 function increment_ip {
198 baseaddr="$(echo $1 | cut -d. -f1-3)"
199 lsv="$(echo $1 | cut -d. -f4)"
202 if [ "$lsv" -ge 254 ]; then
208 ##translates yaml into variables
209 ##params: filename, prefix (ex. "config_")
210 ##usage: parse_yaml opnfv_ksgen_settings.yml "config_"
213 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
214 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
215 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
217 indent = length($1)/2;
219 for (i in vname) {if (i > indent) {delete vname[i]}}
220 if (length($3) > 0) {
221 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
222 printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
227 ##translates the command line paramaters into variables
228 ##params: $@ the entire command line is passed
229 ##usage: parse_cmd_line() "$@"
231 if [[ ( $1 == "--help") || $1 == "-h" ]]; then
236 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
237 echo "Use -h to display help"
240 while [ "`echo $1 | cut -c1`" = "-" ]
256 -enable_virtual_dhcp)
257 enable_virtual_dhcp="TRUE"
279 if [ ! -z "$enable_virtual_dhcp" ] && [ ! -z "$static_ip_range" ]; then
280 echo -e "\n\n${red}ERROR: Incorrect Usage. Static IP range cannot be set when using DHCP!. Exiting${reset}\n\n"
284 if [ -z "$virtual" ]; then
285 if [ ! -z "$enable_virtual_dhcp" ]; then
286 echo -e "\n\n${red}ERROR: Incorrect Usage. enable_virtual_dhcp can only be set when using -virtual!. Exiting${reset}\n\n"
288 elif [ ! -z "$static_ip_range" ]; then
289 echo -e "\n\n${red}ERROR: Incorrect Usage. static_ip_range can only be set when using -virtual!. Exiting${reset}\n\n"
294 if [ -z "$floating_ip_count" ]; then
301 ##usage: disable_selinux()
306 ##Install the EPEL repository and additional packages
308 ##usage: install_EPEL()
310 # Install EPEL repo for access to many other yum repos
311 # Major version is pinned to force some consistency for Arno
312 yum install -y epel-release-7*
314 # Install other required packages
315 # Major versions are pinned to force some consistency for Arno
316 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
317 printf '%s\n' 'deploy.sh: Unable to install depdency packages' >&2
322 ##Download and install virtual box
324 ##usage: install_vbox()
326 ##install VirtualBox repo
327 if cat /etc/*release | grep -i "Fedora release"; then
328 vboxurl=http://download.virtualbox.org/virtualbox/rpm/fedora/\$releasever/\$basearch
330 vboxurl=http://download.virtualbox.org/virtualbox/rpm/el/\$releasever/\$basearch
333 cat > /etc/yum.repos.d/virtualbox.repo << EOM
335 name=Oracle Linux / RHEL / CentOS-\$releasever / \$basearch - VirtualBox
339 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
340 skip_if_unavailable = 1
345 if ! yum list installed | grep -i virtualbox; then
346 if ! yum -y install VirtualBox-4.3; then
347 printf '%s\n' 'deploy.sh: Unable to install virtualbox package' >&2
352 ##install kmod-VirtualBox
353 if ! lsmod | grep vboxdrv; then
354 sudo /etc/init.d/vboxdrv setup
355 if ! lsmod | grep vboxdrv; then
356 printf '%s\n' 'deploy.sh: Unable to install kernel module for virtualbox' >&2
360 printf '%s\n' 'deploy.sh: Skipping kernel module for virtualbox. Already Installed'
364 ##install Ansible using yum
366 ##usage: install_ansible()
368 if ! yum list installed | grep -i ansible; then
369 if ! yum -y install ansible-1*; then
370 printf '%s\n' 'deploy.sh: Unable to install Ansible package' >&2
376 ##install Vagrant RPM directly with the bintray.com site
378 ##usage: install_vagrant()
380 if ! rpm -qa | grep vagrant; then
381 if ! rpm -Uvh https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm; then
382 printf '%s\n' 'deploy.sh: Unable to install vagrant package' >&2
386 printf '%s\n' 'deploy.sh: Skipping Vagrant install as it is already installed.'
389 ##add centos 7 box to vagrant
390 if ! vagrant box list | grep chef/centos-7.0; then
391 if ! vagrant box add chef/centos-7.0 --provider virtualbox; then
392 printf '%s\n' 'deploy.sh: Unable to download centos7 box for Vagrant' >&2
396 printf '%s\n' 'deploy.sh: Skipping Vagrant box add as centos-7.0 is already installed.'
399 ##install workaround for centos7
400 if ! vagrant plugin list | grep vagrant-centos7_fix; then
401 if ! vagrant plugin install vagrant-centos7_fix; then
402 printf '%s\n' 'deploy.sh: Warning: unable to install vagrant centos7 workaround' >&2
405 printf '%s\n' 'deploy.sh: Skipping Vagrant plugin as centos7 workaround is already installed.'
410 ##remove bgs vagrant incase it wasn't cleaned up
414 rm -rf $vm_dir/foreman_vm
417 ##clone genesis and move to node vm dir
424 ##clone artifacts and move into foreman_vm dir
425 if ! GIT_SSL_NO_VERIFY=true git clone https://gerrit.opnfv.org/gerrit/genesis.git; then
426 printf '%s\n' 'deploy.sh: Unable to clone genesis repo' >&2
430 mv -f /tmp/genesis/foreman/ci $vm_dir/foreman_vm
434 ##validates the network settings and update VagrantFile with network settings
436 ##usage: configure_network()
437 configure_network() {
438 cd $vm_dir/foreman_vm
440 echo "${blue}Detecting network configuration...${reset}"
441 ##detect host 1 or 3 interface configuration
442 #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
443 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
445 if [ ! "$output" ]; then
446 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
450 ##virtual we only find 1 interface
451 if [ $virtual ]; then
452 ##find interface with default gateway
453 this_default_gw=$(ip route | grep default | awk '{print $3}')
454 echo "${blue}Default Gateway: $this_default_gw ${reset}"
455 this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
457 ##find interface IP, make sure its valid
458 interface_ip=$(find_ip $this_default_gw_interface)
459 if [ ! "$interface_ip" ]; then
460 echo "${red}Interface ${this_default_gw_interface} does not have an IP: $interface_ip ! Exiting ${reset}"
465 if [ ! -z "$static_ip_range" ]; then
466 new_ip=$(echo $static_ip_range | cut -d , -f1)
468 new_ip=$(next_usable_ip $interface_ip)
469 if [ ! "$new_ip" ]; then
470 echo "${red} Cannot find next IP on interface ${this_default_gw_interface} new_ip: $new_ip ! Exiting ${reset}"
474 interface=$this_default_gw_interface
475 public_interface=$interface
476 interface_arr[$interface]=2
477 interface_ip_arr[2]=$new_ip
478 subnet_mask=$(find_netmask $interface)
479 public_subnet_mask=$subnet_mask
480 public_short_subnet_mask=$(find_short_netmask $interface)
482 if ! verify_subnet_size $public_subnet_mask 25; then
483 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}"
487 ##set that interface to be public
488 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
491 ##find number of interfaces with ip and substitute in VagrantFile
493 for interface in ${output}; do
495 if [ "$if_counter" -ge 4 ]; then
498 interface_ip=$(find_ip $interface)
499 if [ ! "$interface_ip" ]; then
502 new_ip=$(next_usable_ip $interface_ip)
503 if [ ! "$new_ip" ]; then
506 interface_arr[$interface]=$if_counter
507 interface_ip_arr[$if_counter]=$new_ip
508 subnet_mask=$(find_netmask $interface)
509 if [ "$if_counter" -eq 0 ]; then
510 admin_subnet_mask=$subnet_mask
511 if ! verify_subnet_size $admin_subnet_mask 5; then
512 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}"
516 elif [ "$if_counter" -eq 1 ]; then
517 private_subnet_mask=$subnet_mask
518 private_short_subnet_mask=$(find_short_netmask $interface)
520 if ! verify_subnet_size $private_subnet_mask 15; then
521 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}"
524 elif [ "$if_counter" -eq 2 ]; then
525 public_subnet_mask=$subnet_mask
526 public_short_subnet_mask=$(find_short_netmask $interface)
528 if ! verify_subnet_size $public_subnet_mask 25; then
529 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}"
532 elif [ "$if_counter" -eq 3 ]; then
533 storage_subnet_mask=$subnet_mask
535 if ! verify_subnet_size $storage_subnet_mask 10; then
536 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}"
540 echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
543 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
547 ##now remove interface config in Vagrantfile for 1 node
548 ##if 1, 3, or 4 interfaces set deployment type
549 ##if 2 interfaces remove 2nd interface and set deployment type
550 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
551 if [ $virtual ]; then
552 deployment_type="single_network"
553 echo "${blue}Single network detected for Virtual deployment...converting to three_network with internal networks! ${reset}"
554 private_internal_ip=155.1.2.2
555 admin_internal_ip=156.1.2.2
556 private_subnet_mask=255.255.255.0
557 private_short_subnet_mask=/24
558 interface_ip_arr[1]=$private_internal_ip
559 interface_ip_arr[0]=$admin_internal_ip
560 admin_subnet_mask=255.255.255.0
561 admin_short_subnet_mask=/24
562 sed -i 's/^.*eth_replace1.*$/ config.vm.network "private_network", virtualbox__intnet: "my_private_network", ip: '\""$private_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
563 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$admin_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
564 remove_vagrant_network eth_replace3
565 deployment_type=three_network
567 echo "${blue}Single network or 2 network detected for baremetal deployment. This is unsupported! Exiting. ${reset}"
570 elif [ "$if_counter" == 3 ]; then
571 deployment_type="three_network"
572 remove_vagrant_network eth_replace3
574 deployment_type="multi_network"
577 echo "${blue}Network detected: ${deployment_type}! ${reset}"
579 if [ $virtual ]; then
580 if [ -z "$enable_virtual_dhcp" ]; then
581 sed -i 's/^.*disable_dhcp_flag =.*$/ disable_dhcp_flag = true/' Vagrantfile
582 if [ $static_ip_range ]; then
583 ##verify static range is at least 20 IPs
584 static_ip_range_begin=$(echo $static_ip_range | cut -d , -f1)
585 static_ip_range_end=$(echo $static_ip_range | cut -d , -f2)
586 ##verify range is at least 20 ips
587 ##assumes less than 255 range pool
588 begin_octet=$(echo $static_ip_range_begin | cut -d . -f4)
589 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
590 ip_count=$((end_octet-begin_octet+1))
591 if [ "$ip_count" -lt 20 ]; then
592 echo "${red}Static range is less than 20 ips: ${ip_count}, exiting ${reset}"
595 echo "${blue}Static IP range is size $ip_count ${reset}"
601 if route | grep default; then
602 echo "${blue}Default Gateway Detected ${reset}"
603 host_default_gw=$(ip route | grep default | awk '{print $3}')
604 echo "${blue}Default Gateway: $host_default_gw ${reset}"
605 default_gw_interface=$(ip route get $host_default_gw | awk '{print $3}')
606 case "${interface_arr[$default_gw_interface]}" in
608 echo "${blue}Default Gateway Detected on Admin Interface!${reset}"
609 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
610 node_default_gw=$host_default_gw
613 echo "${red}Default Gateway Detected on Private Interface!${reset}"
614 echo "${red}Private subnet should be private and not have Internet access!${reset}"
618 echo "${blue}Default Gateway Detected on Public Interface!${reset}"
619 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
620 echo "${blue}Will setup NAT from Admin -> Public Network on VM!${reset}"
621 sed -i 's/^.*nat_flag =.*$/ nat_flag = true/' Vagrantfile
622 echo "${blue}Setting node gateway to be VM Admin IP${reset}"
623 node_default_gw=${interface_ip_arr[0]}
624 public_gateway=$default_gw
627 echo "${red}Default Gateway Detected on Storage Interface!${reset}"
628 echo "${red}Storage subnet should be private and not have Internet access!${reset}"
632 echo "${red}Unable to determine which interface default gateway is on..Exiting!${reset}"
638 defaultgw=`echo ${interface_ip_arr[0]} | cut -d. -f1-3`
640 defaultgw=$defaultgw$firstip
641 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
642 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
643 node_default_gw=$defaultgw
646 if [ $base_config ]; then
647 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
648 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
653 if [ $no_parse ]; then
654 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
658 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
659 ##Edit the ksgen settings appropriately
660 ##ksgen settings will be stored in /vagrant on the vagrant machine
661 ##if single node deployment all the variables will have the same ip
662 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
664 sed -i 's/^.*default_gw:.*$/default_gw:'" $node_default_gw"'/' opnfv_ksgen_settings.yml
666 ##replace private interface parameter
667 ##private interface will be of hosts, so we need to know the provisioned host interface name
668 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
669 ##replace IP for parameters with next IP that will be given to controller
670 if [ "$deployment_type" == "single_network" ]; then
671 ##we also need to assign IP addresses to nodes
672 ##for single node, foreman is managing the single network, so we can't reserve them
673 ##not supporting single network anymore for now
674 echo "{blue}Single Network type is unsupported right now. Please check your interface configuration. Exiting. ${reset}"
677 elif [[ "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
679 if [ "$deployment_type" == "three_network" ]; then
680 sed -i 's/^.*network_type:.*$/network_type: three_network/' opnfv_ksgen_settings.yml
683 sed -i 's/^.*deployment_type:.*$/ deployment_type: '"$deployment_type"'/' opnfv_ksgen_settings.yml
685 ##get ip addresses for private network on controllers to make dhcp entries
686 ##required for controllers_ip_array global param
687 next_private_ip=${interface_ip_arr[1]}
690 for node in controller1 controller2 controller3; do
691 next_private_ip=$(next_usable_ip $next_private_ip)
692 if [ ! "$next_private_ip" ]; then
693 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
696 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
697 controller_ip_array=$controller_ip_array$next_private_ip,
698 controllers_ip_arr[$control_count]=$next_private_ip
702 next_public_ip=${interface_ip_arr[2]}
703 foreman_ip=$next_public_ip
705 ##if no dhcp, find all the Admin IPs for nodes in advance
706 if [ $virtual ]; then
707 if [ -z "$enable_virtual_dhcp" ]; then
708 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
709 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'`
710 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
711 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
712 nodes=${controller_nodes}${compute_nodes}
713 next_admin_ip=${interface_ip_arr[0]}
715 for node in ${nodes}; do
716 next_admin_ip=$(next_ip $next_admin_ip)
717 if [ ! "$next_admin_ip" ]; then
718 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
721 admin_ip_arr[$node]=$next_admin_ip
722 sed -i 's/'"$node$type"'/'"$next_admin_ip"'/g' opnfv_ksgen_settings.yml
726 ##allocate node public IPs
727 for node in ${nodes}; do
728 next_public_ip=$(next_usable_ip $next_public_ip)
729 if [ ! "$next_public_ip" ]; then
730 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
733 public_ip_arr[$node]=$next_public_ip
738 ##replace global param for controllers_ip_array
739 controller_ip_array=${controller_ip_array%?}
740 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
742 ##now replace all the VIP variables. admin//private can be the same IP
743 ##we have to use IP's here that won't be allocated to hosts at provisioning time
744 ##therefore we increment the ip by 10 to make sure we have a safe buffer
745 next_private_ip=$(increment_ip $next_private_ip 10)
747 private_output=$(grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml)
748 if [ ! -z "$private_output" ]; then
749 while read -r line; do
750 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
751 next_private_ip=$(next_usable_ip $next_private_ip)
752 if [ ! "$next_private_ip" ]; then
753 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
756 done <<< "$private_output"
759 ##replace odl_control_ip (non-HA only)
760 odl_control_ip=${controllers_ip_arr[0]}
761 sed -i 's/^.*odl_control_ip:.*$/ odl_control_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
763 ##replace controller_ip (non-HA only)
764 sed -i 's/^.*controller_ip:.*$/ controller_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
766 ##replace foreman site
767 sed -i 's/^.*foreman_url:.*$/ foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
768 ##replace public vips
769 ##no need to do this if no dhcp
770 if [[ -z "$enable_virtual_dhcp" && ! -z "$virtual" ]]; then
771 next_public_ip=$(next_usable_ip $next_public_ip)
773 next_public_ip=$(increment_ip $next_public_ip 10)
776 public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
777 if [ ! -z "$public_output" ]; then
778 while read -r line; do
779 if echo $line | grep horizon_public_vip; then
780 horizon_public_vip=$next_public_ip
782 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
783 next_public_ip=$(next_usable_ip $next_public_ip)
784 if [ ! "$next_public_ip" ]; then
785 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
788 done <<< "$public_output"
791 ##replace public_network param
792 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
793 sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
794 ##replace private_network param
795 private_subnet=$(find_subnet $next_private_ip $private_subnet_mask)
796 sed -i 's/^.*private_network:.*$/ private_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
797 ##replace storage_network
798 if [ "$deployment_type" == "three_network" ]; then
799 sed -i 's/^.*storage_network:.*$/ storage_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
801 next_storage_ip=${interface_ip_arr[3]}
802 storage_subnet=$(find_subnet $next_storage_ip $storage_subnet_mask)
803 sed -i 's/^.*storage_network:.*$/ storage_network:'" $storage_subnet"'/' opnfv_ksgen_settings.yml
806 ##replace public_subnet param
807 public_subnet=$public_subnet'\'$public_short_subnet_mask
808 sed -i 's/^.*public_subnet:.*$/ public_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
809 ##replace private_subnet param
810 private_subnet=$private_subnet'\'$private_short_subnet_mask
811 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"'/' opnfv_ksgen_settings.yml
813 ##replace public_dns param to be foreman server
814 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[2]}'/' opnfv_ksgen_settings.yml
816 ##replace public_gateway
817 if [ -z "$public_gateway" ]; then
818 ##if unset then we assume its the first IP in the public subnet
819 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
820 public_gateway=$(increment_subnet $public_subnet 1)
822 sed -i 's/^.*public_gateway:.*$/ public_gateway:'" $public_gateway"'/' opnfv_ksgen_settings.yml
824 ##we have to define an allocation range of the public subnet to give
825 ##to neutron to use as floating IPs
826 ##if static ip range, then we take the difference of the end range and current ip
827 ## to be the allocation pool
828 ##if not static ip, we will use the last 20 IP from the subnet
829 ## note that this is not a really good idea because the subnet must be at least a /27 for this to work...
830 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
831 if [ ! -z "$static_ip_range" ]; then
832 begin_octet=$(echo $next_public_ip | cut -d . -f4)
833 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
834 ip_diff=$((end_octet-begin_octet))
835 if [ $ip_diff -le 0 ]; then
836 echo "${red}ip range left for floating range is less than or equal to 0! $ipdiff ${reset}"
839 public_allocation_start=$(next_ip $next_public_ip)
840 public_allocation_end=$static_ip_range_end
843 last_ip_subnet=$(find_last_ip_subnet $next_public_ip $public_subnet_mask)
844 public_allocation_start=$(subtract_ip $last_ip_subnet $floating_ip_count )
845 public_allocation_end=${last_ip_subnet}
847 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
849 sed -i 's/^.*public_allocation_start:.*$/ public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
850 sed -i 's/^.*public_allocation_end:.*$/ public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
853 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
857 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
862 ##Configure bootstrap.sh to use the virtual Khaleesi playbook
864 ##usage: configure_virtual()
865 configure_virtual() {
866 if [ $virtual ]; then
867 echo "${blue} Virtual flag detected, setting Khaleesi playbook to be opnfv-vm.yml ${reset}"
868 sed -i 's/opnfv.yml/opnfv-vm.yml/' bootstrap.sh
872 ##Starts Foreman VM with Vagrant
874 ##usage: start_vagrant()
876 echo "${blue}Starting Vagrant! ${reset}"
879 if ! vagrant up; then
880 printf '%s\n' 'deploy.sh: Unable to complete Foreman VM install' >&2
883 echo "${blue}Foreman VM is up! ${reset}"
887 ##start the VM if this is a virtual installation
888 ##this function does nothing if baremetal servers are being used
890 ##usage: start_virtual_nodes()
891 start_virtual_nodes() {
892 if [ $virtual ]; then
895 echo "${blue}Setting VMs up... ${reset}"
896 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'`
897 ##due to ODL Helium bug of OVS connecting to ODL too early, we need controllers to install first
898 ##this is fix kind of assumes more than I would like to, but for now it should be OK as we always have
899 ##3 static controllers
900 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
901 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
902 nodes=${controller_nodes}${compute_nodes}
904 compute_wait_completed=false
906 for node in ${nodes}; do
909 ##remove VM nodes incase it wasn't cleaned up
913 ##clone genesis and move into node folder
914 if ! GIT_SSL_NO_VERIFY=true git clone https://gerrit.opnfv.org/gerrit/genesis.git; then
915 printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
919 mv -f /tmp/genesis/foreman/ci $vm_dir/$node
924 if [ $base_config ]; then
925 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
926 echo "${red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
931 ##parse yaml into variables
932 eval $(parse_yaml opnfv_ksgen_settings.yml "config_")
934 node_type=config_nodes_${node}_type
935 node_type=$(eval echo \$$node_type)
937 ##trozet test make compute nodes wait 20 minutes
938 if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
939 echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
940 compute_wait_completed=true
944 ##find number of interfaces with ip and substitute in VagrantFile
945 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
947 if [ ! "$output" ]; then
948 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
953 for interface in ${output}; do
955 if [ -z "$enable_virtual_dhcp" ]; then
956 if [ "$if_counter" -ge 1 ]; then
959 elif [ "$if_counter" -ge 4 ]; then
962 interface_ip=$(find_ip $interface)
963 if [ ! "$interface_ip" ]; then
966 case "${if_counter}" in
968 mac_string=config_nodes_${node}_mac_address
969 mac_addr=$(eval echo \$$mac_string)
970 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
971 if [ $mac_addr == "" ]; then
972 echo "${red} Unable to find mac_address for $node! ${reset}"
977 if [ "$node_type" == "controller" ]; then
978 mac_string=config_nodes_${node}_private_mac
979 mac_addr=$(eval echo \$$mac_string)
980 if [ $mac_addr == "" ]; then
981 echo "${red} Unable to find private_mac for $node! ${reset}"
985 ##generate random mac
986 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
988 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
991 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
992 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
995 this_admin_ip=${admin_ip_arr[$node]}
996 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
999 ##now remove interface config in Vagrantfile for 1 node
1000 ##if 1, 3, or 4 interfaces set deployment type
1001 ##if 2 interfaces remove 2nd interface and set deployment type
1002 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
1003 deployment_type="single_network"
1004 if [ "$node_type" == "controller" ]; then
1005 mac_string=config_nodes_${node}_private_mac
1006 mac_addr=$(eval echo \$$mac_string)
1007 if [ $mac_addr == "" ]; then
1008 echo "${red} Unable to find private_mac for $node! ${reset}"
1012 ##generate random mac
1013 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1015 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1016 if [ "$node_type" == "controller" ]; then
1017 new_node_ip=${controllers_ip_arr[$controller_count]}
1018 if [ ! "$new_node_ip" ]; then
1019 echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
1022 ((controller_count++))
1024 next_private_ip=$(next_ip $next_private_ip)
1025 if [ ! "$next_private_ip" ]; then
1026 echo "{red}ERROR: Could not find private ip for $node ${reset}"
1029 new_node_ip=$next_private_ip
1031 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
1032 ##replace host_ip in vm_nodes_provision with private ip
1033 sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
1035 if [ ! -z "$ping_site" ]; then
1036 sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
1038 ##find public ip info
1039 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1040 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1041 this_public_ip=${public_ip_arr[$node]}
1043 if [ -z "$enable_virtual_dhcp" ]; then
1044 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
1046 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
1048 remove_vagrant_network eth_replace3
1049 elif [ "$if_counter" == 3 ]; then
1050 deployment_type="three_network"
1051 remove_vagrant_network eth_replace3
1053 deployment_type="multi_network"
1055 ##modify provisioning to do puppet install, config, and foreman check-in
1056 ##substitute host_name and dns_server in the provisioning script
1057 host_string=config_nodes_${node}_hostname
1058 host_name=$(eval echo \$$host_string)
1059 sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
1060 ##dns server should be the foreman server
1061 sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
1062 ## remove bootstrap and NAT provisioning
1063 sed -i '/nat_setup.sh/d' Vagrantfile
1064 sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
1065 ## modify default_gw to be node_default_gw
1066 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
1067 ## modify VM memory to be 4gig
1068 ##if node type is controller
1069 if [ "$node_type" == "controller" ]; then
1070 sed -i 's/^.*vb.memory =.*$/ vb.memory = 4096/' Vagrantfile
1072 echo "${blue}Starting Vagrant Node $node! ${reset}"
1074 if ! vagrant up; then
1075 echo "${red} Unable to start $node ${reset}"
1078 echo "${blue} $node VM is up! ${reset}"
1081 echo "${blue} All VMs are UP! ${reset}"
1082 echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
1083 ##check puppet is complete
1084 ##ssh into foreman server, run check to verify puppet is complete
1085 pushd $vm_dir/foreman_vm
1086 if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
1087 echo "${red} Failed to validate puppet completion on nodes ${reset}"
1090 echo "{$blue} Puppet complete on all nodes! ${reset}"
1093 ##add routes back to nodes
1094 for node in ${nodes}; do
1096 if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
1097 echo "${blue} Adding public route back to $node! ${reset}"
1098 vagrant ssh -c "route add default gw $this_default_gw"
1102 if [ ! -z "$horizon_public_vip" ]; then
1103 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
1105 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${odl_control_ip} ${reset}"