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
418 ##params: destination directory
419 ##usage: clone_bgs /tmp/myvm/
422 script_dir="`dirname "$script"`"
423 cp -fr $script_dir/ $1
424 cp -fr $script_dir/../../common/puppet-opnfv $1
427 ##validates the network settings and update VagrantFile with network settings
429 ##usage: configure_network()
430 configure_network() {
431 cd $vm_dir/foreman_vm
433 echo "${blue}Detecting network configuration...${reset}"
434 ##detect host 1 or 3 interface configuration
435 #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
436 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
438 if [ ! "$output" ]; then
439 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
443 ##virtual we only find 1 interface
444 if [ $virtual ]; then
445 ##find interface with default gateway
446 this_default_gw=$(ip route | grep default | awk '{print $3}')
447 echo "${blue}Default Gateway: $this_default_gw ${reset}"
448 this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
450 ##find interface IP, make sure its valid
451 interface_ip=$(find_ip $this_default_gw_interface)
452 if [ ! "$interface_ip" ]; then
453 echo "${red}Interface ${this_default_gw_interface} does not have an IP: $interface_ip ! Exiting ${reset}"
458 if [ ! -z "$static_ip_range" ]; then
459 new_ip=$(echo $static_ip_range | cut -d , -f1)
461 new_ip=$(next_usable_ip $interface_ip)
462 if [ ! "$new_ip" ]; then
463 echo "${red} Cannot find next IP on interface ${this_default_gw_interface} new_ip: $new_ip ! Exiting ${reset}"
467 interface=$this_default_gw_interface
468 public_interface=$interface
469 interface_arr[$interface]=2
470 interface_ip_arr[2]=$new_ip
471 subnet_mask=$(find_netmask $interface)
472 public_subnet_mask=$subnet_mask
473 public_short_subnet_mask=$(find_short_netmask $interface)
475 if ! verify_subnet_size $public_subnet_mask 25; then
476 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}"
480 ##set that interface to be public
481 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
484 ##find number of interfaces with ip and substitute in VagrantFile
486 for interface in ${output}; do
488 if [ "$if_counter" -ge 4 ]; then
491 interface_ip=$(find_ip $interface)
492 if [ ! "$interface_ip" ]; then
495 new_ip=$(next_usable_ip $interface_ip)
496 if [ ! "$new_ip" ]; then
499 interface_arr[$interface]=$if_counter
500 interface_ip_arr[$if_counter]=$new_ip
501 subnet_mask=$(find_netmask $interface)
502 if [ "$if_counter" -eq 0 ]; then
503 admin_subnet_mask=$subnet_mask
504 if ! verify_subnet_size $admin_subnet_mask 5; then
505 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}"
509 elif [ "$if_counter" -eq 1 ]; then
510 private_subnet_mask=$subnet_mask
511 private_short_subnet_mask=$(find_short_netmask $interface)
513 if ! verify_subnet_size $private_subnet_mask 15; then
514 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}"
517 elif [ "$if_counter" -eq 2 ]; then
518 public_subnet_mask=$subnet_mask
519 public_short_subnet_mask=$(find_short_netmask $interface)
521 if ! verify_subnet_size $public_subnet_mask 25; then
522 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}"
525 elif [ "$if_counter" -eq 3 ]; then
526 storage_subnet_mask=$subnet_mask
528 if ! verify_subnet_size $storage_subnet_mask 10; then
529 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}"
533 echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
536 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
540 ##now remove interface config in Vagrantfile for 1 node
541 ##if 1, 3, or 4 interfaces set deployment type
542 ##if 2 interfaces remove 2nd interface and set deployment type
543 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
544 if [ $virtual ]; then
545 deployment_type="single_network"
546 echo "${blue}Single network detected for Virtual deployment...converting to three_network with internal networks! ${reset}"
547 private_internal_ip=155.1.2.2
548 admin_internal_ip=156.1.2.2
549 private_subnet_mask=255.255.255.0
550 private_short_subnet_mask=/24
551 interface_ip_arr[1]=$private_internal_ip
552 interface_ip_arr[0]=$admin_internal_ip
553 admin_subnet_mask=255.255.255.0
554 admin_short_subnet_mask=/24
555 sed -i 's/^.*eth_replace1.*$/ config.vm.network "private_network", virtualbox__intnet: "my_private_network", ip: '\""$private_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
556 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$admin_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
557 remove_vagrant_network eth_replace3
558 deployment_type=three_network
560 echo "${blue}Single network or 2 network detected for baremetal deployment. This is unsupported! Exiting. ${reset}"
563 elif [ "$if_counter" == 3 ]; then
564 deployment_type="three_network"
565 remove_vagrant_network eth_replace3
567 deployment_type="multi_network"
570 echo "${blue}Network detected: ${deployment_type}! ${reset}"
572 if [ $virtual ]; then
573 if [ -z "$enable_virtual_dhcp" ]; then
574 sed -i 's/^.*disable_dhcp_flag =.*$/ disable_dhcp_flag = true/' Vagrantfile
575 if [ $static_ip_range ]; then
576 ##verify static range is at least 20 IPs
577 static_ip_range_begin=$(echo $static_ip_range | cut -d , -f1)
578 static_ip_range_end=$(echo $static_ip_range | cut -d , -f2)
579 ##verify range is at least 20 ips
580 ##assumes less than 255 range pool
581 begin_octet=$(echo $static_ip_range_begin | cut -d . -f4)
582 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
583 ip_count=$((end_octet-begin_octet+1))
584 if [ "$ip_count" -lt 20 ]; then
585 echo "${red}Static range is less than 20 ips: ${ip_count}, exiting ${reset}"
588 echo "${blue}Static IP range is size $ip_count ${reset}"
594 if route | grep default; then
595 echo "${blue}Default Gateway Detected ${reset}"
596 host_default_gw=$(ip route | grep default | awk '{print $3}')
597 echo "${blue}Default Gateway: $host_default_gw ${reset}"
598 default_gw_interface=$(ip route get $host_default_gw | awk '{print $3}')
599 case "${interface_arr[$default_gw_interface]}" in
601 echo "${blue}Default Gateway Detected on Admin Interface!${reset}"
602 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
603 node_default_gw=$host_default_gw
606 echo "${red}Default Gateway Detected on Private Interface!${reset}"
607 echo "${red}Private subnet should be private and not have Internet access!${reset}"
611 echo "${blue}Default Gateway Detected on Public Interface!${reset}"
612 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
613 echo "${blue}Will setup NAT from Admin -> Public Network on VM!${reset}"
614 sed -i 's/^.*nat_flag =.*$/ nat_flag = true/' Vagrantfile
615 echo "${blue}Setting node gateway to be VM Admin IP${reset}"
616 node_default_gw=${interface_ip_arr[0]}
617 public_gateway=$default_gw
620 echo "${red}Default Gateway Detected on Storage Interface!${reset}"
621 echo "${red}Storage subnet should be private and not have Internet access!${reset}"
625 echo "${red}Unable to determine which interface default gateway is on..Exiting!${reset}"
631 defaultgw=`echo ${interface_ip_arr[0]} | cut -d. -f1-3`
633 defaultgw=$defaultgw$firstip
634 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
635 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
636 node_default_gw=$defaultgw
639 if [ $base_config ]; then
640 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
641 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
646 if [ $no_parse ]; then
647 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
651 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
652 ##Edit the ksgen settings appropriately
653 ##ksgen settings will be stored in /vagrant on the vagrant machine
654 ##if single node deployment all the variables will have the same ip
655 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
657 sed -i 's/^.*default_gw:.*$/default_gw:'" $node_default_gw"'/' opnfv_ksgen_settings.yml
659 ##replace private interface parameter
660 ##private interface will be of hosts, so we need to know the provisioned host interface name
661 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
662 ##replace IP for parameters with next IP that will be given to controller
663 if [ "$deployment_type" == "single_network" ]; then
664 ##we also need to assign IP addresses to nodes
665 ##for single node, foreman is managing the single network, so we can't reserve them
666 ##not supporting single network anymore for now
667 echo "{blue}Single Network type is unsupported right now. Please check your interface configuration. Exiting. ${reset}"
670 elif [[ "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
672 if [ "$deployment_type" == "three_network" ]; then
673 sed -i 's/^.*network_type:.*$/network_type: three_network/' opnfv_ksgen_settings.yml
676 sed -i 's/^.*deployment_type:.*$/ deployment_type: '"$deployment_type"'/' opnfv_ksgen_settings.yml
678 ##get ip addresses for private network on controllers to make dhcp entries
679 ##required for controllers_ip_array global param
680 next_private_ip=${interface_ip_arr[1]}
683 for node in controller1 controller2 controller3; do
684 next_private_ip=$(next_usable_ip $next_private_ip)
685 if [ ! "$next_private_ip" ]; then
686 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
689 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
690 controller_ip_array=$controller_ip_array$next_private_ip,
691 controllers_ip_arr[$control_count]=$next_private_ip
695 next_public_ip=${interface_ip_arr[2]}
696 foreman_ip=$next_public_ip
698 ##if no dhcp, find all the Admin IPs for nodes in advance
699 if [ $virtual ]; then
700 if [ -z "$enable_virtual_dhcp" ]; then
701 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
702 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'`
703 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
704 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
705 nodes=${controller_nodes}${compute_nodes}
706 next_admin_ip=${interface_ip_arr[0]}
708 for node in ${nodes}; do
709 next_admin_ip=$(next_ip $next_admin_ip)
710 if [ ! "$next_admin_ip" ]; then
711 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
714 admin_ip_arr[$node]=$next_admin_ip
715 sed -i 's/'"$node$type"'/'"$next_admin_ip"'/g' opnfv_ksgen_settings.yml
719 ##allocate node public IPs
720 for node in ${nodes}; do
721 next_public_ip=$(next_usable_ip $next_public_ip)
722 if [ ! "$next_public_ip" ]; then
723 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
726 public_ip_arr[$node]=$next_public_ip
731 ##replace global param for controllers_ip_array
732 controller_ip_array=${controller_ip_array%?}
733 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
735 ##now replace all the VIP variables. admin//private can be the same IP
736 ##we have to use IP's here that won't be allocated to hosts at provisioning time
737 ##therefore we increment the ip by 10 to make sure we have a safe buffer
738 next_private_ip=$(increment_ip $next_private_ip 10)
740 private_output=$(grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml)
741 if [ ! -z "$private_output" ]; then
742 while read -r line; do
743 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
744 next_private_ip=$(next_usable_ip $next_private_ip)
745 if [ ! "$next_private_ip" ]; then
746 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
749 done <<< "$private_output"
752 ##replace odl_control_ip (non-HA only)
753 odl_control_ip=${controllers_ip_arr[0]}
754 sed -i 's/^.*odl_control_ip:.*$/ odl_control_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
756 ##replace controller_ip (non-HA only)
757 sed -i 's/^.*controller_ip:.*$/ controller_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
759 ##replace foreman site
760 sed -i 's/^.*foreman_url:.*$/ foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
761 ##replace public vips
762 ##no need to do this if no dhcp
763 if [[ -z "$enable_virtual_dhcp" && ! -z "$virtual" ]]; then
764 next_public_ip=$(next_usable_ip $next_public_ip)
766 next_public_ip=$(increment_ip $next_public_ip 10)
769 public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
770 if [ ! -z "$public_output" ]; then
771 while read -r line; do
772 if echo $line | grep horizon_public_vip; then
773 horizon_public_vip=$next_public_ip
775 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
776 next_public_ip=$(next_usable_ip $next_public_ip)
777 if [ ! "$next_public_ip" ]; then
778 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
781 done <<< "$public_output"
784 ##replace public_network param
785 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
786 sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
787 ##replace private_network param
788 private_subnet=$(find_subnet $next_private_ip $private_subnet_mask)
789 sed -i 's/^.*private_network:.*$/ private_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
790 ##replace storage_network
791 if [ "$deployment_type" == "three_network" ]; then
792 sed -i 's/^.*storage_network:.*$/ storage_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
794 next_storage_ip=${interface_ip_arr[3]}
795 storage_subnet=$(find_subnet $next_storage_ip $storage_subnet_mask)
796 sed -i 's/^.*storage_network:.*$/ storage_network:'" $storage_subnet"'/' opnfv_ksgen_settings.yml
799 ##replace public_subnet param
800 public_subnet=$public_subnet'\'$public_short_subnet_mask
801 sed -i 's/^.*public_subnet:.*$/ public_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
802 ##replace private_subnet param
803 private_subnet=$private_subnet'\'$private_short_subnet_mask
804 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"'/' opnfv_ksgen_settings.yml
806 ##replace public_dns param to be foreman server
807 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[2]}'/' opnfv_ksgen_settings.yml
809 ##replace public_gateway
810 if [ -z "$public_gateway" ]; then
811 ##if unset then we assume its the first IP in the public subnet
812 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
813 public_gateway=$(increment_subnet $public_subnet 1)
815 sed -i 's/^.*public_gateway:.*$/ public_gateway:'" $public_gateway"'/' opnfv_ksgen_settings.yml
817 ##we have to define an allocation range of the public subnet to give
818 ##to neutron to use as floating IPs
819 ##if static ip range, then we take the difference of the end range and current ip
820 ## to be the allocation pool
821 ##if not static ip, we will use the last 20 IP from the subnet
822 ## note that this is not a really good idea because the subnet must be at least a /27 for this to work...
823 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
824 if [ ! -z "$static_ip_range" ]; then
825 begin_octet=$(echo $next_public_ip | cut -d . -f4)
826 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
827 ip_diff=$((end_octet-begin_octet))
828 if [ $ip_diff -le 0 ]; then
829 echo "${red}ip range left for floating range is less than or equal to 0! $ipdiff ${reset}"
832 public_allocation_start=$(next_ip $next_public_ip)
833 public_allocation_end=$static_ip_range_end
836 last_ip_subnet=$(find_last_ip_subnet $next_public_ip $public_subnet_mask)
837 public_allocation_start=$(subtract_ip $last_ip_subnet $floating_ip_count )
838 public_allocation_end=${last_ip_subnet}
840 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
842 sed -i 's/^.*public_allocation_start:.*$/ public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
843 sed -i 's/^.*public_allocation_end:.*$/ public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
846 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
850 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
855 ##Configure bootstrap.sh to use the virtual Khaleesi playbook
857 ##usage: configure_virtual()
858 configure_virtual() {
859 if [ $virtual ]; then
860 echo "${blue} Virtual flag detected, setting Khaleesi playbook to be opnfv-vm.yml ${reset}"
861 sed -i 's/opnfv.yml/opnfv-vm.yml/' bootstrap.sh
865 ##Starts Foreman VM with Vagrant
867 ##usage: start_vagrant()
869 echo "${blue}Starting Vagrant! ${reset}"
872 if ! vagrant up; then
873 printf '%s\n' 'deploy.sh: Unable to complete Foreman VM install' >&2
876 echo "${blue}Foreman VM is up! ${reset}"
880 ##start the VM if this is a virtual installation
881 ##this function does nothing if baremetal servers are being used
883 ##usage: start_virtual_nodes()
884 start_virtual_nodes() {
885 if [ $virtual ]; then
888 echo "${blue}Setting VMs up... ${reset}"
889 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'`
890 ##due to ODL Helium bug of OVS connecting to ODL too early, we need controllers to install first
891 ##this is fix kind of assumes more than I would like to, but for now it should be OK as we always have
892 ##3 static controllers
893 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
894 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
895 nodes=${controller_nodes}${compute_nodes}
897 compute_wait_completed=false
899 for node in ${nodes}; do
902 ##remove VM nodes incase it wasn't cleaned up
906 ##clone genesis and move into node folder
907 clone_bgs $vm_dir/$node
911 if [ $base_config ]; then
912 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
913 echo "${red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
918 ##parse yaml into variables
919 eval $(parse_yaml opnfv_ksgen_settings.yml "config_")
921 node_type=config_nodes_${node}_type
922 node_type=$(eval echo \$$node_type)
924 ##trozet test make compute nodes wait 20 minutes
925 if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
926 echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
927 compute_wait_completed=true
931 ##find number of interfaces with ip and substitute in VagrantFile
932 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
934 if [ ! "$output" ]; then
935 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
940 for interface in ${output}; do
942 if [ -z "$enable_virtual_dhcp" ]; then
943 if [ "$if_counter" -ge 1 ]; then
946 elif [ "$if_counter" -ge 4 ]; then
949 interface_ip=$(find_ip $interface)
950 if [ ! "$interface_ip" ]; then
953 case "${if_counter}" in
955 mac_string=config_nodes_${node}_mac_address
956 mac_addr=$(eval echo \$$mac_string)
957 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
958 if [ $mac_addr == "" ]; then
959 echo "${red} Unable to find mac_address for $node! ${reset}"
964 if [ "$node_type" == "controller" ]; then
965 mac_string=config_nodes_${node}_private_mac
966 mac_addr=$(eval echo \$$mac_string)
967 if [ $mac_addr == "" ]; then
968 echo "${red} Unable to find private_mac for $node! ${reset}"
972 ##generate random mac
973 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
975 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
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')
982 this_admin_ip=${admin_ip_arr[$node]}
983 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
986 ##now remove interface config in Vagrantfile for 1 node
987 ##if 1, 3, or 4 interfaces set deployment type
988 ##if 2 interfaces remove 2nd interface and set deployment type
989 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
990 deployment_type="single_network"
991 if [ "$node_type" == "controller" ]; then
992 mac_string=config_nodes_${node}_private_mac
993 mac_addr=$(eval echo \$$mac_string)
994 if [ $mac_addr == "" ]; then
995 echo "${red} Unable to find private_mac for $node! ${reset}"
999 ##generate random mac
1000 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1002 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1003 if [ "$node_type" == "controller" ]; then
1004 new_node_ip=${controllers_ip_arr[$controller_count]}
1005 if [ ! "$new_node_ip" ]; then
1006 echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
1009 ((controller_count++))
1011 next_private_ip=$(next_ip $next_private_ip)
1012 if [ ! "$next_private_ip" ]; then
1013 echo "{red}ERROR: Could not find private ip for $node ${reset}"
1016 new_node_ip=$next_private_ip
1018 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
1019 ##replace host_ip in vm_nodes_provision with private ip
1020 sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
1022 if [ ! -z "$ping_site" ]; then
1023 sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
1025 ##find public ip info
1026 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1027 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1028 this_public_ip=${public_ip_arr[$node]}
1030 if [ -z "$enable_virtual_dhcp" ]; then
1031 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
1033 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
1035 remove_vagrant_network eth_replace3
1036 elif [ "$if_counter" == 3 ]; then
1037 deployment_type="three_network"
1038 remove_vagrant_network eth_replace3
1040 deployment_type="multi_network"
1042 ##modify provisioning to do puppet install, config, and foreman check-in
1043 ##substitute host_name and dns_server in the provisioning script
1044 host_string=config_nodes_${node}_hostname
1045 host_name=$(eval echo \$$host_string)
1046 sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
1047 ##dns server should be the foreman server
1048 sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
1049 ## remove bootstrap and NAT provisioning
1050 sed -i '/nat_setup.sh/d' Vagrantfile
1051 sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
1052 ## modify default_gw to be node_default_gw
1053 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
1054 ## modify VM memory to be 4gig
1055 ##if node type is controller
1056 if [ "$node_type" == "controller" ]; then
1057 sed -i 's/^.*vb.memory =.*$/ vb.memory = 4096/' Vagrantfile
1059 echo "${blue}Starting Vagrant Node $node! ${reset}"
1061 if ! vagrant up; then
1062 echo "${red} Unable to start $node ${reset}"
1065 echo "${blue} $node VM is up! ${reset}"
1068 echo "${blue} All VMs are UP! ${reset}"
1069 echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
1070 ##check puppet is complete
1071 ##ssh into foreman server, run check to verify puppet is complete
1072 pushd $vm_dir/foreman_vm
1073 if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
1074 echo "${red} Failed to validate puppet completion on nodes ${reset}"
1077 echo "{$blue} Puppet complete on all nodes! ${reset}"
1080 ##add routes back to nodes
1081 for node in ${nodes}; do
1083 if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
1084 echo "${blue} Adding public route back to $node! ${reset}"
1085 vagrant ssh -c "route add default gw $this_default_gw"
1089 if [ ! -z "$horizon_public_vip" ]; then
1090 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
1092 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${odl_control_ip} ${reset}"
1108 clone_bgs $vm_dir/foreman_vm