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 ##finds last usable ip (broadcast minus 1) of a subnet from an IP and netmask
82 ## Warning: This function only works for IPv4 at the moment.
84 function find_last_ip_subnet {
85 IFS=. read -r i1 i2 i3 i4 <<< "$1"
86 IFS=. read -r m1 m2 m3 m4 <<< "$2"
87 IFS=. read -r s1 s2 s3 s4 <<< "$((i1 & m1)).$((i2 & m2)).$((i3 & m3)).$((i4 & m4))"
88 printf "%d.%d.%d.%d\n" "$((255 - $m1 + $s1))" "$((255 - $m2 + $s2))" "$((255 - $m3 + $s3))" "$((255 - $m4 + $s4 - 1))"
91 ##increments subnet by a value
94 function increment_subnet {
95 IFS=. read -r i1 i2 i3 i4 <<< "$1"
96 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 | $2))"
100 ##finds netmask of interface
102 ##returns long format 255.255.x.x
103 function find_netmask {
104 ifconfig $1 | grep -Eo 'netmask\s+[\.0-9]+' | awk '{print $2}'
107 ##finds short netmask of interface
109 ##returns short format, ex: /21
110 function find_short_netmask {
111 echo "/$(ip addr show $1 | grep -Eo '^\s+inet\s+[\/\.0-9]+' | awk '{print $2}' | cut -d / -f2)"
116 ##assumes a /24 subnet
118 baseaddr="$(echo $1 | cut -d. -f1-3)"
119 lsv="$(echo $1 | cut -d. -f4)"
120 if [ "$lsv" -ge 254 ]; then
127 ##removes the network interface config from Vagrantfile
129 ##assumes you are in the directory of Vagrantfile
130 function remove_vagrant_network {
131 sed -i 's/^.*'"$1"'.*$//' Vagrantfile
134 ##check if IP is in use
136 ##ping ip to get arp entry, then check arp
137 function is_ip_used {
138 ping -c 5 $1 > /dev/null 2>&1
139 arp -n | grep "$1 " | grep -iv incomplete > /dev/null 2>&1
142 ##find next usable IP
144 function next_usable_ip {
146 while [ "$new_ip" ]; do
147 if ! is_ip_used $new_ip; then
151 new_ip=$(next_ip $new_ip)
156 ##increment ip by value
157 ##params: ip, amount to increment by
158 ##increment_ip $next_private_ip 10
159 function increment_ip {
160 baseaddr="$(echo $1 | cut -d. -f1-3)"
161 lsv="$(echo $1 | cut -d. -f4)"
164 if [ "$lsv" -ge 254 ]; then
170 ##translates yaml into variables
171 ##params: filename, prefix (ex. "config_")
172 ##usage: parse_yaml opnfv_ksgen_settings.yml "config_"
175 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
176 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
177 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
179 indent = length($1)/2;
181 for (i in vname) {if (i > indent) {delete vname[i]}}
182 if (length($3) > 0) {
183 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
184 printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
189 ##translates the command line paramaters into variables
190 ##params: $@ the entire command line is passed
191 ##usage: parse_cmd_line() "$@"
193 if [[ ( $1 == "--help") || $1 == "-h" ]]; then
198 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
199 echo "Use -h to display help"
202 while [ "`echo $1 | cut -c1`" = "-" ]
218 -enable_virtual_dhcp)
219 enable_virtual_dhcp="TRUE"
241 if [ ! -z "$enable_virtual_dhcp" ] && [ ! -z "$static_ip_range" ]; then
242 echo -e "\n\n${red}ERROR: Incorrect Usage. Static IP range cannot be set when using DHCP!. Exiting${reset}\n\n"
246 if [ -z "$virtual" ]; then
247 if [ ! -z "$enable_virtual_dhcp" ]; then
248 echo -e "\n\n${red}ERROR: Incorrect Usage. enable_virtual_dhcp can only be set when using -virtual!. Exiting${reset}\n\n"
250 elif [ ! -z "$static_ip_range" ]; then
251 echo -e "\n\n${red}ERROR: Incorrect Usage. static_ip_range can only be set when using -virtual!. Exiting${reset}\n\n"
256 if [ -z "$floating_ip_count" ]; then
263 ##usage: disable_selinux()
268 ##Install the EPEL repository and additional packages
270 ##usage: install_EPEL()
272 # Install EPEL repo for access to many other yum repos
273 # Major version is pinned to force some consistency for Arno
274 yum install -y epel-release-7*
276 # Install other required packages
277 # Major versions are pinned to force some consistency for Arno
278 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
279 printf '%s\n' 'deploy.sh: Unable to install depdency packages' >&2
284 ##Download and install virtual box
286 ##usage: install_vbox()
288 ##install VirtualBox repo
289 if cat /etc/*release | grep -i "Fedora release"; then
290 vboxurl=http://download.virtualbox.org/virtualbox/rpm/fedora/\$releasever/\$basearch
292 vboxurl=http://download.virtualbox.org/virtualbox/rpm/el/\$releasever/\$basearch
295 cat > /etc/yum.repos.d/virtualbox.repo << EOM
297 name=Oracle Linux / RHEL / CentOS-\$releasever / \$basearch - VirtualBox
301 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
302 skip_if_unavailable = 1
307 if ! yum list installed | grep -i virtualbox; then
308 if ! yum -y install VirtualBox-4.3; then
309 printf '%s\n' 'deploy.sh: Unable to install virtualbox package' >&2
314 ##install kmod-VirtualBox
315 if ! lsmod | grep vboxdrv; then
316 sudo /etc/init.d/vboxdrv setup
317 if ! lsmod | grep vboxdrv; then
318 printf '%s\n' 'deploy.sh: Unable to install kernel module for virtualbox' >&2
322 printf '%s\n' 'deploy.sh: Skipping kernel module for virtualbox. Already Installed'
326 ##install Ansible using yum
328 ##usage: install_ansible()
330 if ! yum list installed | grep -i ansible; then
331 if ! yum -y install ansible-1*; then
332 printf '%s\n' 'deploy.sh: Unable to install Ansible package' >&2
338 ##install Vagrant RPM directly with the bintray.com site
340 ##usage: install_vagrant()
342 if ! rpm -qa | grep vagrant; then
343 if ! rpm -Uvh https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm; then
344 printf '%s\n' 'deploy.sh: Unable to install vagrant package' >&2
348 printf '%s\n' 'deploy.sh: Skipping Vagrant install as it is already installed.'
351 ##add centos 7 box to vagrant
352 if ! vagrant box list | grep chef/centos-7.0; then
353 if ! vagrant box add chef/centos-7.0 --provider virtualbox; then
354 printf '%s\n' 'deploy.sh: Unable to download centos7 box for Vagrant' >&2
358 printf '%s\n' 'deploy.sh: Skipping Vagrant box add as centos-7.0 is already installed.'
361 ##install workaround for centos7
362 if ! vagrant plugin list | grep vagrant-centos7_fix; then
363 if ! vagrant plugin install vagrant-centos7_fix; then
364 printf '%s\n' 'deploy.sh: Warning: unable to install vagrant centos7 workaround' >&2
367 printf '%s\n' 'deploy.sh: Skipping Vagrant plugin as centos7 workaround is already installed.'
372 ##remove bgs vagrant incase it wasn't cleaned up
376 rm -rf $vm_dir/foreman_vm
379 ##clone genesis and move to node vm dir
386 ##clone artifacts and move into foreman_vm dir
387 if ! GIT_SSL_NO_VERIFY=true git clone https://gerrit.opnfv.org/gerrit/genesis.git; then
388 printf '%s\n' 'deploy.sh: Unable to clone genesis repo' >&2
392 mv -f /tmp/genesis/foreman/ci $vm_dir/foreman_vm
396 ##validates the network settings and update VagrantFile with network settings
398 ##usage: configure_network()
399 configure_network() {
400 cd $vm_dir/foreman_vm
402 echo "${blue}Detecting network configuration...${reset}"
403 ##detect host 1 or 3 interface configuration
404 #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
405 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
407 if [ ! "$output" ]; then
408 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
412 ##virtual we only find 1 interface
413 if [ $virtual ]; then
414 ##find interface with default gateway
415 this_default_gw=$(ip route | grep default | awk '{print $3}')
416 echo "${blue}Default Gateway: $this_default_gw ${reset}"
417 this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
419 ##find interface IP, make sure its valid
420 interface_ip=$(find_ip $this_default_gw_interface)
421 if [ ! "$interface_ip" ]; then
422 echo "${red}Interface ${this_default_gw_interface} does not have an IP: $interface_ip ! Exiting ${reset}"
427 if [ ! -z "$static_ip_range" ]; then
428 new_ip=$(echo $static_ip_range | cut -d , -f1)
430 new_ip=$(next_usable_ip $interface_ip)
431 if [ ! "$new_ip" ]; then
432 echo "${red} Cannot find next IP on interface ${this_default_gw_interface} new_ip: $new_ip ! Exiting ${reset}"
436 interface=$this_default_gw_interface
437 public_interface=$interface
438 interface_arr[$interface]=2
439 interface_ip_arr[2]=$new_ip
440 subnet_mask=$(find_netmask $interface)
441 public_subnet_mask=$subnet_mask
442 public_short_subnet_mask=$(find_short_netmask $interface)
444 ##set that interface to be public
445 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
448 ##find number of interfaces with ip and substitute in VagrantFile
450 for interface in ${output}; do
452 if [ "$if_counter" -ge 4 ]; then
455 interface_ip=$(find_ip $interface)
456 if [ ! "$interface_ip" ]; then
459 new_ip=$(next_usable_ip $interface_ip)
460 if [ ! "$new_ip" ]; then
463 interface_arr[$interface]=$if_counter
464 interface_ip_arr[$if_counter]=$new_ip
465 subnet_mask=$(find_netmask $interface)
466 if [ "$if_counter" -eq 0 ]; then
467 admin_subnet_mask=$subnet_mask
468 elif [ "$if_counter" -eq 1 ]; then
469 private_subnet_mask=$subnet_mask
470 private_short_subnet_mask=$(find_short_netmask $interface)
471 elif [ "$if_counter" -eq 2 ]; then
472 public_subnet_mask=$subnet_mask
473 public_short_subnet_mask=$(find_short_netmask $interface)
474 elif [ "$if_counter" -eq 3 ]; then
475 storage_subnet_mask=$subnet_mask
477 echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
480 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
484 ##now remove interface config in Vagrantfile for 1 node
485 ##if 1, 3, or 4 interfaces set deployment type
486 ##if 2 interfaces remove 2nd interface and set deployment type
487 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
488 if [ $virtual ]; then
489 deployment_type="single_network"
490 echo "${blue}Single network detected for Virtual deployment...converting to three_network with internal networks! ${reset}"
491 private_internal_ip=155.1.2.2
492 admin_internal_ip=156.1.2.2
493 private_subnet_mask=255.255.255.0
494 private_short_subnet_mask=/24
495 interface_ip_arr[1]=$private_internal_ip
496 interface_ip_arr[0]=$admin_internal_ip
497 admin_subnet_mask=255.255.255.0
498 admin_short_subnet_mask=/24
499 sed -i 's/^.*eth_replace1.*$/ config.vm.network "private_network", virtualbox__intnet: "my_private_network", ip: '\""$private_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
500 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$admin_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
501 remove_vagrant_network eth_replace3
502 deployment_type=three_network
504 echo "${blue}Single network or 2 network detected for baremetal deployment. This is unsupported! Exiting. ${reset}"
507 elif [ "$if_counter" == 3 ]; then
508 deployment_type="three_network"
509 remove_vagrant_network eth_replace3
511 deployment_type="multi_network"
514 echo "${blue}Network detected: ${deployment_type}! ${reset}"
516 if [ $virtual ]; then
517 if [ -z "$enable_virtual_dhcp" ]; then
518 sed -i 's/^.*disable_dhcp_flag =.*$/ disable_dhcp_flag = true/' Vagrantfile
519 if [ $static_ip_range ]; then
520 ##verify static range is at least 20 IPs
521 static_ip_range_begin=$(echo $static_ip_range | cut -d , -f1)
522 static_ip_range_end=$(echo $static_ip_range | cut -d , -f2)
523 ##verify range is at least 20 ips
524 ##assumes less than 255 range pool
525 begin_octet=$(echo $static_ip_range_begin | cut -d . -f4)
526 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
527 ip_count=$((end_octet-begin_octet+1))
528 if [ "$ip_count" -lt 20 ]; then
529 echo "${red}Static range is less than 20 ips: ${ip_count}, exiting ${reset}"
532 echo "${blue}Static IP range is size $ip_count ${reset}"
538 if route | grep default; then
539 echo "${blue}Default Gateway Detected ${reset}"
540 host_default_gw=$(ip route | grep default | awk '{print $3}')
541 echo "${blue}Default Gateway: $host_default_gw ${reset}"
542 default_gw_interface=$(ip route get $host_default_gw | awk '{print $3}')
543 case "${interface_arr[$default_gw_interface]}" in
545 echo "${blue}Default Gateway Detected on Admin Interface!${reset}"
546 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
547 node_default_gw=$host_default_gw
550 echo "${red}Default Gateway Detected on Private Interface!${reset}"
551 echo "${red}Private subnet should be private and not have Internet access!${reset}"
555 echo "${blue}Default Gateway Detected on Public Interface!${reset}"
556 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
557 echo "${blue}Will setup NAT from Admin -> Public Network on VM!${reset}"
558 sed -i 's/^.*nat_flag =.*$/ nat_flag = true/' Vagrantfile
559 echo "${blue}Setting node gateway to be VM Admin IP${reset}"
560 node_default_gw=${interface_ip_arr[0]}
561 public_gateway=$default_gw
564 echo "${red}Default Gateway Detected on Storage Interface!${reset}"
565 echo "${red}Storage subnet should be private and not have Internet access!${reset}"
569 echo "${red}Unable to determine which interface default gateway is on..Exiting!${reset}"
575 defaultgw=`echo ${interface_ip_arr[0]} | cut -d. -f1-3`
577 defaultgw=$defaultgw$firstip
578 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
579 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
580 node_default_gw=$defaultgw
583 if [ $base_config ]; then
584 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
585 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
590 if [ $no_parse ]; then
591 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
595 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
596 ##Edit the ksgen settings appropriately
597 ##ksgen settings will be stored in /vagrant on the vagrant machine
598 ##if single node deployment all the variables will have the same ip
599 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
601 sed -i 's/^.*default_gw:.*$/default_gw:'" $node_default_gw"'/' opnfv_ksgen_settings.yml
603 ##replace private interface parameter
604 ##private interface will be of hosts, so we need to know the provisioned host interface name
605 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
606 ##replace IP for parameters with next IP that will be given to controller
607 if [ "$deployment_type" == "single_network" ]; then
608 ##we also need to assign IP addresses to nodes
609 ##for single node, foreman is managing the single network, so we can't reserve them
610 ##not supporting single network anymore for now
611 echo "{blue}Single Network type is unsupported right now. Please check your interface configuration. Exiting. ${reset}"
614 elif [[ "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
616 if [ "$deployment_type" == "three_network" ]; then
617 sed -i 's/^.*network_type:.*$/network_type: three_network/' opnfv_ksgen_settings.yml
620 sed -i 's/^.*deployment_type:.*$/ deployment_type: '"$deployment_type"'/' opnfv_ksgen_settings.yml
622 ##get ip addresses for private network on controllers to make dhcp entries
623 ##required for controllers_ip_array global param
624 next_private_ip=${interface_ip_arr[1]}
627 for node in controller1 controller2 controller3; do
628 next_private_ip=$(next_usable_ip $next_private_ip)
629 if [ ! "$next_private_ip" ]; then
630 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
633 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
634 controller_ip_array=$controller_ip_array$next_private_ip,
635 controllers_ip_arr[$control_count]=$next_private_ip
639 next_public_ip=${interface_ip_arr[2]}
640 foreman_ip=$next_public_ip
642 ##if no dhcp, find all the Admin IPs for nodes in advance
643 if [ $virtual ]; then
644 if [ -z "$enable_virtual_dhcp" ]; then
645 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
646 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'`
647 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
648 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
649 nodes=${controller_nodes}${compute_nodes}
650 next_admin_ip=${interface_ip_arr[0]}
652 for node in ${nodes}; do
653 next_admin_ip=$(next_ip $next_admin_ip)
654 if [ ! "$next_admin_ip" ]; then
655 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
658 admin_ip_arr[$node]=$next_admin_ip
659 sed -i 's/'"$node$type"'/'"$next_admin_ip"'/g' opnfv_ksgen_settings.yml
663 ##allocate node public IPs
664 for node in ${nodes}; do
665 next_public_ip=$(next_usable_ip $next_public_ip)
666 if [ ! "$next_public_ip" ]; then
667 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
670 public_ip_arr[$node]=$next_public_ip
675 ##replace global param for controllers_ip_array
676 controller_ip_array=${controller_ip_array%?}
677 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
679 ##now replace all the VIP variables. admin//private can be the same IP
680 ##we have to use IP's here that won't be allocated to hosts at provisioning time
681 ##therefore we increment the ip by 10 to make sure we have a safe buffer
682 next_private_ip=$(increment_ip $next_private_ip 10)
684 private_output=$(grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml)
685 if [ ! -z "$private_output" ]; then
686 while read -r line; do
687 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
688 next_private_ip=$(next_usable_ip $next_private_ip)
689 if [ ! "$next_private_ip" ]; then
690 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
693 done <<< "$private_output"
696 ##replace odl_control_ip (non-HA only)
697 odl_control_ip=${controllers_ip_arr[0]}
698 sed -i 's/^.*odl_control_ip:.*$/ odl_control_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
700 ##replace controller_ip (non-HA only)
701 sed -i 's/^.*controller_ip:.*$/ controller_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
703 ##replace foreman site
704 sed -i 's/^.*foreman_url:.*$/ foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
705 ##replace public vips
706 ##no need to do this if virtual and no dhcp
707 if [ ! -z "$enable_virtual_dhcp" ]; then
708 next_public_ip=$(increment_ip $next_public_ip 10)
710 next_public_ip=$(next_usable_ip $next_public_ip)
713 public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
714 if [ ! -z "$public_output" ]; then
715 while read -r line; do
716 if echo $line | grep horizon_public_vip; then
717 horizon_public_vip=$next_public_ip
719 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
720 next_public_ip=$(next_usable_ip $next_public_ip)
721 if [ ! "$next_public_ip" ]; then
722 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
725 done <<< "$public_output"
728 ##replace public_network param
729 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
730 sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
731 ##replace private_network param
732 private_subnet=$(find_subnet $next_private_ip $private_subnet_mask)
733 sed -i 's/^.*private_network:.*$/ private_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
734 ##replace storage_network
735 if [ "$deployment_type" == "three_network" ]; then
736 sed -i 's/^.*storage_network:.*$/ storage_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
738 next_storage_ip=${interface_ip_arr[3]}
739 storage_subnet=$(find_subnet $next_storage_ip $storage_subnet_mask)
740 sed -i 's/^.*storage_network:.*$/ storage_network:'" $storage_subnet"'/' opnfv_ksgen_settings.yml
743 ##replace public_subnet param
744 public_subnet=$public_subnet'\'$public_short_subnet_mask
745 sed -i 's/^.*public_subnet:.*$/ public_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
746 ##replace private_subnet param
747 private_subnet=$private_subnet'\'$private_short_subnet_mask
748 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"'/' opnfv_ksgen_settings.yml
750 ##replace public_dns param to be foreman server
751 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[2]}'/' opnfv_ksgen_settings.yml
753 ##replace public_gateway
754 if [ -z "$public_gateway" ]; then
755 ##if unset then we assume its the first IP in the public subnet
756 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
757 public_gateway=$(increment_subnet $public_subnet 1)
759 sed -i 's/^.*public_gateway:.*$/ public_gateway:'" $public_gateway"'/' opnfv_ksgen_settings.yml
761 ##we have to define an allocation range of the public subnet to give
762 ##to neutron to use as floating IPs
763 ##if static ip range, then we take the difference of the end range and current ip
764 ## to be the allocation pool
765 ##if not static ip, we will use the last 20 IP from the subnet
766 ## note that this is not a really good idea because the subnet must be at least a /27 for this to work...
767 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
768 if [ ! -z "$static_ip_range" ]; then
769 begin_octet=$(echo $next_public_ip | cut -d . -f4)
770 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
771 ip_diff=$((end_octet-begin_octet))
772 if [ $ip_diff -le 0 ]; then
773 echo "${red}ip range left for floating range is less than or equal to 0! $ipdiff ${reset}"
776 public_allocation_start=$(next_ip $next_public_ip)
777 public_allocation_end=$static_ip_range_end
778 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
781 last_ip_subnet=$(find_last_ip_subnet $next_public_ip $public_subnet_mask)
782 public_allocation_start=$(increment_subnet $public_subnet $(( $last_ip_subnet - $floating_ip_count )) )
783 public_allocation_end=$(increment_subnet $public_subnet $(( $last_ip_subnet )) )
784 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
785 echo "${blue}Foreman VM is up! ${reset}"
788 sed -i 's/^.*public_allocation_start:.*$/ public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
789 sed -i 's/^.*public_allocation_end:.*$/ public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
792 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
796 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
801 ##Configure bootstrap.sh to use the virtual Khaleesi playbook
803 ##usage: configure_virtual()
804 configure_virtual() {
805 if [ $virtual ]; then
806 echo "${blue} Virtual flag detected, setting Khaleesi playbook to be opnfv-vm.yml ${reset}"
807 sed -i 's/opnfv.yml/opnfv-vm.yml/' bootstrap.sh
811 ##Starts Foreman VM with Vagrant
813 ##usage: start_vagrant()
815 echo "${blue}Starting Vagrant! ${reset}"
818 if ! vagrant up; then
819 printf '%s\n' 'deploy.sh: Unable to complete Foreman VM install' >&2
822 echo "${blue}Foreman VM is up! ${reset}"
826 ##start the VM if this is a virtual installation
827 ##this function does nothing if baremetal servers are being used
829 ##usage: start_virtual_nodes()
830 start_virtual_nodes() {
831 if [ $virtual ]; then
834 echo "${blue}Setting VMs up... ${reset}"
835 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'`
836 ##due to ODL Helium bug of OVS connecting to ODL too early, we need controllers to install first
837 ##this is fix kind of assumes more than I would like to, but for now it should be OK as we always have
838 ##3 static controllers
839 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
840 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
841 nodes=${controller_nodes}${compute_nodes}
843 compute_wait_completed=false
845 for node in ${nodes}; do
848 ##remove VM nodes incase it wasn't cleaned up
852 ##clone genesis and move into node folder
853 if ! GIT_SSL_NO_VERIFY=true git clone https://gerrit.opnfv.org/gerrit/genesis.git; then
854 printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
858 mv -f /tmp/genesis/foreman/ci $vm_dir/$node
863 if [ $base_config ]; then
864 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
865 echo "${red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
870 ##parse yaml into variables
871 eval $(parse_yaml opnfv_ksgen_settings.yml "config_")
873 node_type=config_nodes_${node}_type
874 node_type=$(eval echo \$$node_type)
876 ##trozet test make compute nodes wait 20 minutes
877 if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
878 echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
879 compute_wait_completed=true
883 ##find number of interfaces with ip and substitute in VagrantFile
884 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
886 if [ ! "$output" ]; then
887 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
892 for interface in ${output}; do
894 if [ -z "$enable_virtual_dhcp" ]; then
895 if [ "$if_counter" -ge 1 ]; then
898 elif [ "$if_counter" -ge 4 ]; then
901 interface_ip=$(find_ip $interface)
902 if [ ! "$interface_ip" ]; then
905 case "${if_counter}" in
907 mac_string=config_nodes_${node}_mac_address
908 mac_addr=$(eval echo \$$mac_string)
909 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
910 if [ $mac_addr == "" ]; then
911 echo "${red} Unable to find mac_address for $node! ${reset}"
916 if [ "$node_type" == "controller" ]; then
917 mac_string=config_nodes_${node}_private_mac
918 mac_addr=$(eval echo \$$mac_string)
919 if [ $mac_addr == "" ]; then
920 echo "${red} Unable to find private_mac for $node! ${reset}"
924 ##generate random mac
925 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
927 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
930 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
931 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
934 this_admin_ip=${admin_ip_arr[$node]}
935 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
938 ##now remove interface config in Vagrantfile for 1 node
939 ##if 1, 3, or 4 interfaces set deployment type
940 ##if 2 interfaces remove 2nd interface and set deployment type
941 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
942 deployment_type="single_network"
943 if [ "$node_type" == "controller" ]; then
944 mac_string=config_nodes_${node}_private_mac
945 mac_addr=$(eval echo \$$mac_string)
946 if [ $mac_addr == "" ]; then
947 echo "${red} Unable to find private_mac for $node! ${reset}"
951 ##generate random mac
952 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
954 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
955 if [ "$node_type" == "controller" ]; then
956 new_node_ip=${controllers_ip_arr[$controller_count]}
957 if [ ! "$new_node_ip" ]; then
958 echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
961 ((controller_count++))
963 next_private_ip=$(next_ip $next_private_ip)
964 if [ ! "$next_private_ip" ]; then
965 echo "{red}ERROR: Could not find private ip for $node ${reset}"
968 new_node_ip=$next_private_ip
970 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
971 ##replace host_ip in vm_nodes_provision with private ip
972 sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
974 if [ ! -z "$ping_site" ]; then
975 sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
977 ##find public ip info
978 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
979 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
980 this_public_ip=${public_ip_arr[$node]}
982 if [ -z "$enable_virtual_dhcp" ]; then
983 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
985 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
987 remove_vagrant_network eth_replace3
988 elif [ "$if_counter" == 3 ]; then
989 deployment_type="three_network"
990 remove_vagrant_network eth_replace3
992 deployment_type="multi_network"
994 ##modify provisioning to do puppet install, config, and foreman check-in
995 ##substitute host_name and dns_server in the provisioning script
996 host_string=config_nodes_${node}_hostname
997 host_name=$(eval echo \$$host_string)
998 sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
999 ##dns server should be the foreman server
1000 sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
1001 ## remove bootstrap and NAT provisioning
1002 sed -i '/nat_setup.sh/d' Vagrantfile
1003 sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
1004 ## modify default_gw to be node_default_gw
1005 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
1006 ## modify VM memory to be 4gig
1007 ##if node type is controller
1008 if [ "$node_type" == "controller" ]; then
1009 sed -i 's/^.*vb.memory =.*$/ vb.memory = 4096/' Vagrantfile
1011 echo "${blue}Starting Vagrant Node $node! ${reset}"
1013 if ! vagrant up; then
1014 echo "${red} Unable to start $node ${reset}"
1017 echo "${blue} $node VM is up! ${reset}"
1020 echo "${blue} All VMs are UP! ${reset}"
1021 echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
1022 ##check puppet is complete
1023 ##ssh into foreman server, run check to verify puppet is complete
1024 pushd $vm_dir/foreman_vm
1025 if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
1026 echo "${red} Failed to validate puppet completion on nodes ${reset}"
1029 echo "{$blue} Puppet complete on all nodes! ${reset}"
1032 ##add routes back to nodes
1033 for node in ${nodes}; do
1035 if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
1036 echo "${blue} Adding public route back to $node! ${reset}"
1037 vagrant ssh -c "route add default gw $this_default_gw"
1041 if [ ! -z "$horizon_public_vip" ]; then
1042 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
1044 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${odl_control_ip} ${reset}"