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
32 vagrant_box_dir=~/.vagrant.d/boxes/opnfv-VAGRANTSLASH-centos-7.0/1.0.0/virtualbox/
33 vagrant_box_vmdk=box-disk1.vmdk
40 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
41 echo -e "\n${green}Make sure you have the latest kernel installed before running this script! (yum update kernel +reboot)${reset}\n"
42 echo -e "\nUsage:\n$0 [arguments] \n"
43 echo -e "\n -no_parse : No variable parsing into config. Flag. \n"
44 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"
45 echo -e "\n -virtual : Node virtualization instead of baremetal. Flag. \n"
46 echo -e "\n -enable_virtual_dhcp : Run dhcp server instead of using static IPs. Use this with -virtual only. \n"
47 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"
48 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"
49 echo -e "\n -floating_ip_count : number of IP address from the public range to be used for floating IP. Default is 20.\n"
50 echo -e "\n -admin_nic : Baremetal NIC for the admin network. Required if other "nic" arguments are used. \
51 Not applicable with -virtual. Example: -admin_nic em1"
52 echo -e "\n -private_nic : Baremetal NIC for the private network. Required if other "nic" arguments are used. \
53 Not applicable with -virtual. Example: -private_nic em2"
54 echo -e "\n -public_nic : Baremetal NIC for the public network. Required if other "nic" arguments are used. \
55 Can also be used with -virtual. Example: -public_nic em3"
56 echo -e "\n -storage_nic : Baremetal NIC for the storage network. Optional. Not applicable with -virtual. \
57 Private NIC will be used for storage if not specified. Example: -storage_nic em4"
58 echo -e "\n -single_baremetal_nic : Baremetal NIC for the all in one network. Optional. Not applicable with -virtual. \
59 Example: -single_baremetal_nic em1"
62 ##verify vm dir exists
64 function verify_vm_dir {
65 if [ -d "$vm_dir" ]; then
66 echo -e "\n\n${red}ERROR: VM Directory: $vm_dir already exists. Environment not clean. Please use clean.sh. Exiting${reset}\n\n"
74 if [ ! -d $vm_dir ]; then
75 echo -e "\n\n${red}ERROR: Unable to create VM Directory: $vm_dir Exiting${reset}\n\n"
80 ##find ip of interface
81 ##params: interface name
83 ip addr show $1 | grep -Eo '^\s+inet\s+[\.0-9]+' | awk '{print $2}'
86 ##finds subnet of ip and netmask
88 function find_subnet {
89 IFS=. read -r i1 i2 i3 i4 <<< "$1"
90 IFS=. read -r m1 m2 m3 m4 <<< "$2"
91 printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
94 ##verify subnet has at least n IPs
95 ##params: subnet mask, n IPs
96 function verify_subnet_size {
97 IFS=. read -r i1 i2 i3 i4 <<< "$1"
100 ##this function assumes you would never need more than 254
101 ##we check here to make sure
102 if [ "$num_ips_required" -ge 254 ]; then
103 echo -e "\n\n${red}ERROR: allocating more than 254 IPs is unsupported...Exiting${reset}\n\n"
107 ##we just return if 3rd octet is not 255
108 ##because we know the subnet is big enough
109 if [ "$i3" -ne 255 ]; then
111 elif [ $((254-$i4)) -ge "$num_ips_required" ]; then
114 echo -e "\n\n${red}ERROR: Subnet is too small${reset}\n\n"
119 ##finds last usable ip (broadcast minus 1) of a subnet from an IP and netmask
120 ## Warning: This function only works for IPv4 at the moment.
121 ##params: ip, netmask
122 function find_last_ip_subnet {
123 IFS=. read -r i1 i2 i3 i4 <<< "$1"
124 IFS=. read -r m1 m2 m3 m4 <<< "$2"
125 IFS=. read -r s1 s2 s3 s4 <<< "$((i1 & m1)).$((i2 & m2)).$((i3 & m3)).$((i4 & m4))"
126 printf "%d.%d.%d.%d\n" "$((255 - $m1 + $s1))" "$((255 - $m2 + $s2))" "$((255 - $m3 + $s3))" "$((255 - $m4 + $s4 - 1))"
129 ##increments subnet by a value
132 function increment_subnet {
133 IFS=. read -r i1 i2 i3 i4 <<< "$1"
134 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 | $2))"
138 ##finds netmask of interface
140 ##returns long format 255.255.x.x
141 function find_netmask {
142 ifconfig $1 | grep -Eo 'netmask\s+[\.0-9]+' | awk '{print $2}'
145 ##finds short netmask of interface
147 ##returns short format, ex: /21
148 function find_short_netmask {
149 echo "/$(ip addr show $1 | grep -Eo '^\s+inet\s+[\/\.0-9]+' | awk '{print $2}' | cut -d / -f2)"
154 ##assumes a /24 subnet
156 baseaddr="$(echo $1 | cut -d. -f1-3)"
157 lsv="$(echo $1 | cut -d. -f4)"
158 if [ "$lsv" -ge 254 ]; then
165 ##subtracts a value from an IP address
166 ##params: last ip, ip_count
167 ##assumes ip_count is less than the last octect of the address
169 IFS=. read -r i1 i2 i3 i4 <<< "$1"
171 if [ $i4 -lt $ip_count ]; then
172 echo -e "\n\n${red}ERROR: Can't subtract $ip_count from IP address $1 Exiting${reset}\n\n"
175 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 - $ip_count ))"
178 ##removes the network interface config from Vagrantfile
180 ##assumes you are in the directory of Vagrantfile
181 function remove_vagrant_network {
182 sed -i 's/^.*'"$1"'.*$//' Vagrantfile
185 ##check if IP is in use
187 ##ping ip to get arp entry, then check arp
188 function is_ip_used {
189 ping -c 5 $1 > /dev/null 2>&1
190 arp -n | grep "$1 " | grep -iv incomplete > /dev/null 2>&1
193 ##find next usable IP
195 function next_usable_ip {
197 while [ "$new_ip" ]; do
198 if ! is_ip_used $new_ip; then
202 new_ip=$(next_ip $new_ip)
207 ##increment ip by value
208 ##params: ip, amount to increment by
209 ##increment_ip $next_private_ip 10
210 function increment_ip {
211 baseaddr="$(echo $1 | cut -d. -f1-3)"
212 lsv="$(echo $1 | cut -d. -f4)"
215 if [ "$lsv" -ge 254 ]; then
221 ##translates yaml into variables
222 ##params: filename, prefix (ex. "config_")
223 ##usage: parse_yaml opnfv_ksgen_settings.yml "config_"
226 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
227 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
228 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
230 indent = length($1)/2;
232 for (i in vname) {if (i > indent) {delete vname[i]}}
233 if (length($3) > 0) {
234 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
235 printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
240 ##translates the command line paramaters into variables
241 ##params: $@ the entire command line is passed
242 ##usage: parse_cmd_line() "$@"
244 if [[ ( $1 == "--help") || $1 == "-h" ]]; then
249 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
250 echo "Use -h to display help"
253 while [ "`echo $1 | cut -c1`" = "-" ]
269 -enable_virtual_dhcp)
270 enable_virtual_dhcp="TRUE"
305 -single_baremetal_nic)
306 single_baremetal_nic=$2
316 if [ ! -z "$enable_virtual_dhcp" ] && [ ! -z "$static_ip_range" ]; then
317 echo -e "\n\n${red}ERROR: Incorrect Usage. Static IP range cannot be set when using DHCP!. Exiting${reset}\n\n"
321 if [ -z "$virtual" ]; then
322 if [ ! -z "$enable_virtual_dhcp" ]; then
323 echo -e "\n\n${red}ERROR: Incorrect Usage. enable_virtual_dhcp can only be set when using -virtual!. Exiting${reset}\n\n"
325 elif [ ! -z "$static_ip_range" ]; then
326 echo -e "\n\n${red}ERROR: Incorrect Usage. static_ip_range can only be set when using -virtual!. Exiting${reset}\n\n"
331 if [ -z "$floating_ip_count" ]; then
336 if [[ $nic_arg_flag -eq 1 ]]; then
337 if [ ! -z "$single_baremetal_nic" ]; then
338 echo "${red}Please do not specify other nic types along with single_baremetal_nic!${reset}"
342 if [ -z "$virtual" ]; then
343 for nic_type in admin_nic private_nic public_nic; do
344 eval "nic_value=\$$nic_type"
345 if [ -z "$nic_value" ]; then
346 echo "${red}$nic_type is empty or not defined. Required when other nic args are given!${reset}"
349 interface_ip=$(find_ip $nic_value)
350 if [ ! "$interface_ip" ]; then
351 echo "${red}$nic_value does not have an IP address! Exiting... ${reset}"
356 ##if virtual only public_nic should be specified
357 for nic_type in admin_nic private_nic storage_nic single_baremetal_nic; do
358 eval "nic_value=\$$nic_type"
359 if [ ! -z "$nic_value" ]; then
360 echo "${red}$nic_type is not a valid argument using -virtual. Please only specify public_nic!${reset}"
365 interface_ip=$(find_ip $public_nic)
366 if [ ! "$interface_ip" ]; then
367 echo "${red}Public NIC: $public_nic does not have an IP address! Exiting... ${reset}"
371 elif [ ! -z "$single_baremetal_nic" ]; then
372 interface_ip=$(find_ip $single_baremetal_nic)
373 if [ ! "$interface_ip" ]; then
374 echo "${red}Single Baremetal NIC: $single_baremetal_nic does not have an IP address! Exiting... ${reset}"
382 ##usage: disable_selinux()
387 ##Install the EPEL repository and additional packages
389 ##usage: install_EPEL()
391 # Install EPEL repo for access to many other yum repos
392 # Major version is pinned to force some consistency for Arno
393 yum install -y epel-release-7*
395 # Install other required packages
396 # Major versions are pinned to force some consistency for Arno
397 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
398 printf '%s\n' 'deploy.sh: Unable to install depdency packages' >&2
403 ##Download and install virtual box
405 ##usage: install_vbox()
407 ##install VirtualBox repo
408 if cat /etc/*release | grep -i "Fedora release"; then
409 vboxurl=http://download.virtualbox.org/virtualbox/rpm/fedora/\$releasever/\$basearch
411 vboxurl=http://download.virtualbox.org/virtualbox/rpm/el/\$releasever/\$basearch
414 cat > /etc/yum.repos.d/virtualbox.repo << EOM
416 name=Oracle Linux / RHEL / CentOS-\$releasever / \$basearch - VirtualBox
420 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
421 skip_if_unavailable = 1
426 if ! yum list installed | grep -i virtualbox; then
427 if ! yum -y install VirtualBox-4.3; then
428 printf '%s\n' 'deploy.sh: Unable to install virtualbox package' >&2
433 ##install kmod-VirtualBox
434 if ! lsmod | grep vboxdrv; then
435 sudo /etc/init.d/vboxdrv setup
436 if ! lsmod | grep vboxdrv; then
437 printf '%s\n' 'deploy.sh: Unable to install kernel module for virtualbox' >&2
441 printf '%s\n' 'deploy.sh: Skipping kernel module for virtualbox. Already Installed'
445 ##install Ansible using yum
447 ##usage: install_ansible()
449 if ! yum list installed | grep -i ansible; then
450 if ! yum -y install ansible-1*; then
451 printf '%s\n' 'deploy.sh: Unable to install Ansible package' >&2
457 ##install Vagrant RPM directly with the bintray.com site
459 ##usage: install_vagrant()
461 if ! rpm -qa | grep vagrant; then
462 if ! rpm -Uvh https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm; then
463 printf '%s\n' 'deploy.sh: Unable to install vagrant package' >&2
467 printf '%s\n' 'deploy.sh: Skipping Vagrant install as it is already installed.'
470 ##add centos 7 box to vagrant
471 if ! vagrant box list | grep opnfv/centos-7.0; then
472 if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
473 printf '%s\n' 'deploy.sh: Unable to download centos7 box for Vagrant' >&2
477 printf '%s\n' 'deploy.sh: Skipping Vagrant box add as centos-7.0 is already installed.'
480 ##install workaround for centos7
481 if ! vagrant plugin list | grep vagrant-centos7_fix; then
482 if ! vagrant plugin install vagrant-centos7_fix; then
483 printf '%s\n' 'deploy.sh: Warning: unable to install vagrant centos7 workaround' >&2
486 printf '%s\n' 'deploy.sh: Skipping Vagrant plugin as centos7 workaround is already installed.'
491 ##remove bgs vagrant incase it wasn't cleaned up
495 rm -rf $vm_dir/foreman_vm
498 ##clone genesis and move to node vm dir
499 ##params: destination directory
500 ##usage: clone_bgs /tmp/myvm/
502 script_dir="`dirname "$script"`"
503 cp -fr $script_dir/ $1
504 cp -fr $script_dir/../../common/puppet-opnfv $1
507 ##validates the network settings and update VagrantFile with network settings
509 ##usage: configure_network()
510 configure_network() {
511 cd $vm_dir/foreman_vm
513 ##if nic_arg_flag is set, then we don't figure out
515 if [[ $nic_arg_flag -eq 1 ]]; then
516 echo "${blue}Static Network Interfaces Defined. Updating Vagrantfile...${reset}"
517 if [ $virtual ]; then
518 nic_list="$public_nic"
519 elif [ -z "$storage_nic" ]; then
520 echo "${blue}storage_nic not defined, will combine storage into private VLAN ${reset}"
521 nic_list="$admin_nic $private_nic $public_nic"
523 nic_list="$admin_nic $private_nic $public_nic $storage_nic"
525 nic_array=( $nic_list )
527 elif [ ! -z "$single_baremetal_nic" ]; then
528 output=$single_baremetal_nic
530 echo "${blue}Detecting network configuration...${reset}"
531 ##detect host 1 or 3 interface configuration
532 #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
533 #output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | cut -d " " -f10`
534 output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | awk {'print $9'}`
537 if [ ! "$output" ]; then
538 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
542 ##virtual we only find 1 interface
543 if [ $virtual ]; then
544 if [ ! -z "${nic_array[0]}" ]; then
545 echo "${blue}Public Interface specified: ${nic_array[0]}${reset}"
546 this_default_gw_interface=${nic_array[0]}
548 ##find interface with default gateway
549 this_default_gw=$(ip route | grep default | awk '{print $3}')
550 echo "${blue}Default Gateway: $this_default_gw ${reset}"
551 this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
554 ##find interface IP, make sure its valid
555 interface_ip=$(find_ip $this_default_gw_interface)
556 if [ ! "$interface_ip" ]; then
557 echo "${red}Interface ${this_default_gw_interface} does not have an IP: $interface_ip ! Exiting ${reset}"
562 if [ ! -z "$static_ip_range" ]; then
563 new_ip=$(echo $static_ip_range | cut -d , -f1)
564 subnet_mask=$(find_netmask $this_default_gw_interface)
565 host_subnet=$(find_subnet $interface_ip $subnet_mask)
566 ip_range_subnet=$(find_subnet $new_ip $subnet_mask)
567 if [ "$ip_range_subnet" != "$host_subnet" ]; then
568 echo "${red}static_ip_range: ${static_ip_range} is not in the same subnet as your default gateway interface: ${host_subnet}. Please use a correct range!${reset}"
572 new_ip=$(next_usable_ip $interface_ip)
573 if [ ! "$new_ip" ]; then
574 echo "${red} Cannot find next IP on interface ${this_default_gw_interface} new_ip: $new_ip ! Exiting ${reset}"
578 interface=$this_default_gw_interface
579 public_interface=$interface
580 interface_arr[$interface]=2
581 interface_ip_arr[2]=$new_ip
582 subnet_mask=$(find_netmask $interface)
583 public_subnet_mask=$subnet_mask
584 public_short_subnet_mask=$(find_short_netmask $interface)
586 if ! verify_subnet_size $public_subnet_mask 25; then
587 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}"
591 ##set that interface to be public
592 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
595 if [ ! -z $single_baremetal_nic ]; then
596 interface_ip=$(find_ip $single_baremetal_nic)
597 if [ ! "$interface_ip" ]; then
598 echo "${red}Unable to determine IP address of $single_baremetal_nic. Exiting...${reset}"
601 subnet_mask=$(find_netmask $single_baremetal_nic)
602 public_subnet_mask=$subnet_mask
603 if ! verify_subnet_size $public_subnet_mask 50; then
604 echo "${red} Not enough IPs in subnet: $interface_ip $subnet_mask. Need at least 50 IPs. Please resize subnet! Exiting ${reset}"
608 new_ip=$(next_usable_ip $interface_ip)
609 if [ ! "$new_ip" ]; then
610 echo "${red}Unable to allocate new IP address: $interface_ip $subnet_mask Exiting...${reset}"
614 this_default_gw=$(ip route | grep default | awk '{print $3}')
615 echo "${blue}Default Gateway: $this_default_gw ${reset}"
616 this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
617 if [ "$this_default_gw_interface" != "$single_baremetal_nic" ]; then
618 echo "${red}Error: Your default gateway interface: $this_default_gw_interface does not \
619 match the baremetal nic you provided: ${single_baremetal_nic}. Exiting...${reset}"
622 sed -i 's/^.*eth_replace0.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$single_baremetal_nic"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
623 interface_ip_arr[0]=$new_ip
624 interface_arr[$single_baremetal_nic]=0
626 admin_subnet_mask=$subnet_mask
627 public_short_subnet_mask=$(find_short_netmask $single_baremetal_nic)
630 ##find number of interfaces with ip and substitute in VagrantFile
632 for interface in ${output}; do
634 if [ "$if_counter" -ge 4 ]; then
637 interface_ip=$(find_ip $interface)
638 if [ ! "$interface_ip" ]; then
641 new_ip=$(next_usable_ip $interface_ip)
642 if [ ! "$new_ip" ]; then
645 interface_arr[$interface]=$if_counter
646 interface_ip_arr[$if_counter]=$new_ip
647 subnet_mask=$(find_netmask $interface)
648 if [ "$if_counter" -eq 0 ]; then
649 admin_subnet_mask=$subnet_mask
651 if ! verify_subnet_size $admin_subnet_mask 5; then
652 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}"
656 elif [ "$if_counter" -eq 1 ]; then
657 private_subnet_mask=$subnet_mask
658 private_short_subnet_mask=$(find_short_netmask $interface)
660 if ! verify_subnet_size $private_subnet_mask 15; then
661 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}"
664 elif [ "$if_counter" -eq 2 ]; then
665 public_subnet_mask=$subnet_mask
666 public_short_subnet_mask=$(find_short_netmask $interface)
668 if ! verify_subnet_size $public_subnet_mask 25; then
669 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}"
672 elif [ "$if_counter" -eq 3 ]; then
673 storage_subnet_mask=$subnet_mask
675 if ! verify_subnet_size $storage_subnet_mask 10; then
676 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}"
680 echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
683 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
689 ##now remove interface config in Vagrantfile for 1 node
690 ##if 1, 3, or 4 interfaces set deployment type
691 ##if 2 interfaces remove 2nd interface and set deployment type
692 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
693 if [ $virtual ]; then
694 deployment_type="single_network"
695 echo "${blue}Single network detected for Virtual deployment...converting to three_network with internal networks! ${reset}"
696 private_internal_ip=155.1.2.2
697 admin_internal_ip=156.1.2.2
698 private_subnet_mask=255.255.255.0
699 private_short_subnet_mask=/24
700 interface_ip_arr[1]=$private_internal_ip
701 interface_ip_arr[0]=$admin_internal_ip
702 admin_subnet_mask=255.255.255.0
703 admin_short_subnet_mask=/24
704 sed -i 's/^.*eth_replace1.*$/ config.vm.network "private_network", virtualbox__intnet: "my_private_network", ip: '\""$private_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
705 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$admin_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
706 remove_vagrant_network eth_replace3
707 deployment_type=three_network
708 elif [[ "$if_counter" == 1 ]]; then
709 echo "${blue}Single network detected for Baremetal deployment! ${reset}"
710 remove_vagrant_network eth_replace1
711 remove_vagrant_network eth_replace2
712 remove_vagrant_network eth_replace3
713 deployment_type="single_network"
715 echo "${blue}Single network or 2 network detected for baremetal deployment. This is unsupported! Exiting. ${reset}"
718 elif [ "$if_counter" == 3 ]; then
719 deployment_type="three_network"
720 remove_vagrant_network eth_replace3
722 deployment_type="multi_network"
725 echo "${blue}Network detected: ${deployment_type}! ${reset}"
727 if [ $virtual ]; then
728 if [ -z "$enable_virtual_dhcp" ]; then
729 sed -i 's/^.*disable_dhcp_flag =.*$/ disable_dhcp_flag = true/' Vagrantfile
730 if [ $static_ip_range ]; then
731 ##verify static range is at least 20 IPs
732 static_ip_range_begin=$(echo $static_ip_range | cut -d , -f1)
733 static_ip_range_end=$(echo $static_ip_range | cut -d , -f2)
734 ##verify range is at least 20 ips
735 ##assumes less than 255 range pool
736 begin_octet=$(echo $static_ip_range_begin | cut -d . -f4)
737 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
738 ip_count=$((end_octet-begin_octet+1))
739 if [ "$ip_count" -lt 20 ]; then
740 echo "${red}Static range is less than 20 ips: ${ip_count}, exiting ${reset}"
743 echo "${blue}Static IP range is size $ip_count ${reset}"
749 if route | grep default; then
750 echo "${blue}Default Gateway Detected ${reset}"
751 host_default_gw=$(ip route | grep default | awk '{print $3}')
752 echo "${blue}Default Gateway: $host_default_gw ${reset}"
753 default_gw_interface=$(ip route get $host_default_gw | awk '{print $3}')
754 case "${interface_arr[$default_gw_interface]}" in
756 echo "${blue}Default Gateway Detected on Admin Interface!${reset}"
757 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
758 node_default_gw=$host_default_gw
761 echo "${red}Default Gateway Detected on Private Interface!${reset}"
762 echo "${red}Private subnet should be private and not have Internet access!${reset}"
766 echo "${blue}Default Gateway Detected on Public Interface!${reset}"
767 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
768 echo "${blue}Will setup NAT from Admin -> Public Network on VM!${reset}"
769 sed -i 's/^.*nat_flag =.*$/ nat_flag = true/' Vagrantfile
770 echo "${blue}Setting node gateway to be VM Admin IP${reset}"
771 node_default_gw=${interface_ip_arr[0]}
772 public_gateway=$host_default_gw
775 echo "${red}Default Gateway Detected on Storage Interface!${reset}"
776 echo "${red}Storage subnet should be private and not have Internet access!${reset}"
780 echo "${red}Unable to determine which interface default gateway is on..Exiting!${reset}"
786 defaultgw=`echo ${interface_ip_arr[0]} | cut -d. -f1-3`
788 defaultgw=$defaultgw$firstip
789 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
790 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
791 node_default_gw=$defaultgw
794 if [ $base_config ]; then
795 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
796 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
801 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'`
802 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
803 echo "${blue}Controller nodes found in settings: ${controller_nodes}${reset}"
804 my_controller_array=( $controller_nodes )
805 num_control_nodes=${#my_controller_array[@]}
806 if [ "$num_control_nodes" -ne 3 ]; then
807 if cat opnfv_ksgen_settings.yml | grep ha_flag | grep true; then
808 echo "${red}Error: You must define exactly 3 control nodes when HA flag is true!${reset}"
812 echo "${blue}Number of Controller nodes detected: ${num_control_nodes}${reset}"
815 if [ $no_parse ]; then
816 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
820 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
821 ##Edit the ksgen settings appropriately
822 ##ksgen settings will be stored in /vagrant on the vagrant machine
823 ##if single node deployment all the variables will have the same ip
824 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
826 sed -i 's/^.*default_gw:.*$/default_gw:'" $node_default_gw"'/' opnfv_ksgen_settings.yml
828 ##replace private interface parameter
829 ##private interface will be of hosts, so we need to know the provisioned host interface name
830 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
831 ##replace IP for parameters with next IP that will be given to controller
833 if [[ "$deployment_type" == "single_network" || "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
835 if [ "$deployment_type" == "three_network" ]; then
836 sed -i 's/^.*network_type:.*$/network_type: three_network/' opnfv_ksgen_settings.yml
837 elif [ "$deployment_type" == "single_network" ]; then
838 sed -i 's/^.*network_type:.*$/network_type: single_network/' opnfv_ksgen_settings.yml
839 next_single_ip=${interface_ip_arr[0]}
840 foreman_ip=$next_single_ip
841 next_single_ip=$(next_usable_ip $next_single_ip)
844 sed -i 's/^.*deployment_type:.*$/ deployment_type: '"$deployment_type"'/' opnfv_ksgen_settings.yml
846 ##get ip addresses for private network on controllers to make dhcp entries
847 ##required for controllers_ip_array global param
848 if [ "$deployment_type" == "single_network" ]; then
849 next_private_ip=$next_single_ip
850 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
851 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'`
852 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
853 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
854 nodes=${controller_nodes}${compute_nodes}
855 next_admin_ip=${interface_ip_arr[0]}
859 for node in ${controller_nodes}; do
860 next_private_ip=$(next_usable_ip $next_private_ip)
861 if [ ! "$next_private_ip" ]; then
862 echo "${red} Unable to find an unused IP for $node ! ${reset}"
865 sed -i 's/'"$node$type1"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
866 sed -i 's/'"$node$type2"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
867 controller_ip_array=$controller_ip_array$next_private_ip,
868 controllers_ip_arr[$control_count]=$next_private_ip
873 for node in ${compute_nodes}; do
874 next_private_ip=$(next_usable_ip $next_private_ip)
875 if [ ! "$next_private_ip" ]; then
876 echo "${red} Unable to find an unused IP for $node ! ${reset}"
879 sed -i 's/'"$node$type1"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
884 next_private_ip=${interface_ip_arr[1]}
888 for node in controller1 controller2 controller3; do
889 next_private_ip=$(next_usable_ip $next_private_ip)
890 if [ ! "$next_private_ip" ]; then
891 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
894 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
895 controller_ip_array=$controller_ip_array$next_private_ip,
896 controllers_ip_arr[$control_count]=$next_private_ip
901 if [[ "$deployment_type" != "single_network" ]]; then
902 next_public_ip=${interface_ip_arr[2]}
903 foreman_ip=$next_public_ip
906 ##if no dhcp, find all the Admin IPs for nodes in advance
907 if [ $virtual ]; then
908 if [ -z "$enable_virtual_dhcp" ]; then
909 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
910 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'`
911 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
912 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
913 nodes=${controller_nodes}${compute_nodes}
914 next_admin_ip=${interface_ip_arr[0]}
916 for node in ${nodes}; do
917 next_admin_ip=$(next_ip $next_admin_ip)
918 if [ ! "$next_admin_ip" ]; then
919 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
922 admin_ip_arr[$node]=$next_admin_ip
923 sed -i 's/'"$node$type"'/'"$next_admin_ip"'/g' opnfv_ksgen_settings.yml
927 ##allocate node public IPs
928 for node in ${nodes}; do
929 next_public_ip=$(next_usable_ip $next_public_ip)
930 if [ ! "$next_public_ip" ]; then
931 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
934 public_ip_arr[$node]=$next_public_ip
939 ##replace global param for controllers_ip_array
940 controller_ip_array=${controller_ip_array%?}
941 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
943 ##now replace all the VIP variables. admin//private can be the same IP
944 ##we have to use IP's here that won't be allocated to hosts at provisioning time
945 ##therefore we increment the ip by 10 to make sure we have a safe buffer
946 next_private_ip=$(increment_ip $next_private_ip 10)
948 private_output=$(grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml)
949 if [ ! -z "$private_output" ]; then
950 while read -r line; do
951 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
952 next_private_ip=$(next_usable_ip $next_private_ip)
953 if [ ! "$next_private_ip" ]; then
954 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
957 done <<< "$private_output"
960 ##replace odl_control_ip (non-HA only)
961 odl_control_ip=${controllers_ip_arr[0]}
962 sed -i 's/^.*odl_control_ip:.*$/ odl_control_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
964 ##replace controller_ip (non-HA only)
965 sed -i 's/^.*controller_ip:.*$/ controller_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
967 ##replace foreman site
968 sed -i 's/^.*foreman_url:.*$/ foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
969 ##replace public vips
971 ##if single_network deployment we continue next_public_ip from next_private_ip
972 if [[ "$deployment_type" == "single_network" ]]; then
973 next_public_ip=$(next_usable_ip $next_private_ip)
975 ##no need to do this if no dhcp
976 if [[ -z "$enable_virtual_dhcp" && ! -z "$virtual" ]]; then
977 next_public_ip=$(next_usable_ip $next_public_ip)
979 next_public_ip=$(increment_ip $next_public_ip 10)
983 public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
984 if [ ! -z "$public_output" ]; then
985 while read -r line; do
986 if echo $line | grep horizon_public_vip; then
987 horizon_public_vip=$next_public_ip
989 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
990 next_public_ip=$(next_usable_ip $next_public_ip)
991 if [ ! "$next_public_ip" ]; then
992 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
995 done <<< "$public_output"
998 ##replace admin_network param for bare metal deployments
999 if [[ -z "$virtual" && -z "$single_network" ]]; then
1000 admin_subnet=$(find_subnet $admin_ip $admin_subnet_mask)
1001 sed -i 's/^.*admin_network:.*$/ admin_network:'" $admin_subnet"'/' opnfv_ksgen_settings.yml
1003 sed -i 's/^.*admin_network:.*$/ admin_network:'" \"false\""'/' opnfv_ksgen_settings.yml
1005 ##replace public_network param
1006 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
1007 sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1008 if [ "$deployment_type" == "single_network" ]; then
1009 sed -i 's/^.*private_network:.*$/ private_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1011 ##replace private_network param
1012 private_subnet=$(find_subnet $next_private_ip $private_subnet_mask)
1013 sed -i 's/^.*private_network:.*$/ private_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
1016 ##replace storage_network
1017 if [ "$deployment_type" == "single_network" ]; then
1018 sed -i 's/^.*storage_network:.*$/ storage_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1019 elif [ "$deployment_type" == "three_network" ]; then
1020 sed -i 's/^.*storage_network:.*$/ storage_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
1022 next_storage_ip=${interface_ip_arr[3]}
1023 storage_subnet=$(find_subnet $next_storage_ip $storage_subnet_mask)
1024 sed -i 's/^.*storage_network:.*$/ storage_network:'" $storage_subnet"'/' opnfv_ksgen_settings.yml
1027 ##replace public_subnet param
1028 public_subnet=$public_subnet'\'$public_short_subnet_mask
1029 sed -i 's/^.*public_subnet:.*$/ public_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1030 if [ "$deployment_type" == "single_network" ]; then
1031 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1033 ##replace private_subnet param
1034 private_subnet=$private_subnet'\'$private_short_subnet_mask
1035 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"'/' opnfv_ksgen_settings.yml
1038 ##replace public_dns param to be foreman server
1039 if [ "$deployment_type" == "single_network" ]; then
1040 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[0]}'/' opnfv_ksgen_settings.yml
1042 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[2]}'/' opnfv_ksgen_settings.yml
1045 ##replace public_gateway
1046 if [ -z "$public_gateway" ]; then
1047 if [ "$deployment_type" == "single_network" ]; then
1048 public_gateway=$node_default_gw
1050 ##if unset then we assume its the first IP in the public subnet
1051 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
1052 public_gateway=$(increment_subnet $public_subnet 1)
1055 sed -i 's/^.*public_gateway:.*$/ public_gateway:'" $public_gateway"'/' opnfv_ksgen_settings.yml
1057 ##we have to define an allocation range of the public subnet to give
1058 ##to neutron to use as floating IPs
1059 ##if static ip range, then we take the difference of the end range and current ip
1060 ## to be the allocation pool
1061 ##if not static ip, we will use the last 20 IP from the subnet
1062 ## note that this is not a really good idea because the subnet must be at least a /27 for this to work...
1063 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
1064 if [ ! -z "$static_ip_range" ]; then
1065 begin_octet=$(echo $next_public_ip | cut -d . -f4)
1066 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
1067 ip_diff=$((end_octet-begin_octet))
1068 if [ $ip_diff -le 0 ]; then
1069 echo "${red}ip range left for floating range is less than or equal to 0! $ipdiff ${reset}"
1072 public_allocation_start=$(next_ip $next_public_ip)
1073 public_allocation_end=$static_ip_range_end
1076 last_ip_subnet=$(find_last_ip_subnet $next_public_ip $public_subnet_mask)
1077 public_allocation_start=$(subtract_ip $last_ip_subnet $floating_ip_count )
1078 public_allocation_end=${last_ip_subnet}
1080 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
1082 sed -i 's/^.*public_allocation_start:.*$/ public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
1083 sed -i 's/^.*public_allocation_end:.*$/ public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
1086 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
1090 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
1095 ##Configure bootstrap.sh to use the virtual Khaleesi playbook
1097 ##usage: configure_virtual()
1098 configure_virtual() {
1099 if [ $virtual ]; then
1100 echo "${blue} Virtual flag detected, setting Khaleesi playbook to be opnfv-vm.yml ${reset}"
1101 sed -i 's/opnfv.yml/opnfv-vm.yml/' bootstrap.sh
1105 ##Starts Foreman VM with Vagrant
1107 ##usage: start_vagrant()
1109 echo "${blue}Starting Vagrant! ${reset}"
1112 if ! vagrant up; then
1113 printf '%s\n' 'deploy.sh: Unable to complete Foreman VM install' >&2
1116 echo "${blue}Foreman VM is up! ${reset}"
1120 ##start the VM if this is a virtual installation
1121 ##this function does nothing if baremetal servers are being used
1123 ##usage: start_virtual_nodes()
1124 start_virtual_nodes() {
1125 if [ $virtual ]; then
1128 echo "${blue}Setting VMs up... ${reset}"
1129 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'`
1130 ##due to ODL Helium bug of OVS connecting to ODL too early, we need controllers to install first
1131 ##this is fix kind of assumes more than I would like to, but for now it should be OK as we always have
1132 ##3 static controllers
1133 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
1134 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
1135 nodes=${controller_nodes}${compute_nodes}
1137 compute_wait_completed=false
1139 for node in ${nodes}; do
1141 ##remove VM nodes incase it wasn't cleaned up
1142 rm -rf $vm_dir/$node
1143 rm -rf /tmp/genesis/
1145 ##clone genesis and move into node folder
1146 clone_bgs $vm_dir/$node
1150 if [ $base_config ]; then
1151 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
1152 echo "${red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
1157 ##parse yaml into variables
1158 eval $(parse_yaml opnfv_ksgen_settings.yml "config_")
1160 node_type=config_nodes_${node}_type
1161 node_type=$(eval echo \$$node_type)
1163 ##modify memory and cpu
1164 node_memory=$(eval echo \${config_nodes_${node}_memory})
1165 node_vcpus=$(eval echo \${config_nodes_${node}_cpus})
1166 node_storage=$(eval echo \${config_nodes_${node}_disk})
1168 sed -i 's/^.*vb.memory =.*$/ vb.memory = '"$node_memory"'/' Vagrantfile
1169 sed -i 's/^.*vb.cpus =.*$/ vb.cpus = '"$node_vcpus"'/' Vagrantfile
1171 if ! resize_vagrant_disk $node_storage; then
1172 echo "${red}Error while resizing vagrant box to size $node_storage for $node! ${reset}"
1176 ##trozet test make compute nodes wait 20 minutes
1177 if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
1178 echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
1179 compute_wait_completed=true
1183 ## Add Admin interface
1184 mac_string=config_nodes_${node}_mac_address
1185 mac_addr=$(eval echo \$$mac_string)
1186 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1187 if [ $mac_addr == "" ]; then
1188 echo "${red} Unable to find mac_address for $node! ${reset}"
1191 this_admin_ip=${admin_ip_arr[$node]}
1192 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$this_admin_ip"\"', netmask: '\""$admin_subnet_mask"\"', :mac => '\""$mac_addr"\"'/' Vagrantfile
1194 ## Add private interface
1195 if [ "$node_type" == "controller" ]; then
1196 mac_string=config_nodes_${node}_private_mac
1197 mac_addr=$(eval echo \$$mac_string)
1198 if [ $mac_addr == "" ]; then
1199 echo "${red} Unable to find private_mac for $node! ${reset}"
1203 ##generate random mac
1204 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1206 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1207 if [ "$node_type" == "controller" ]; then
1208 new_node_ip=${controllers_ip_arr[$controller_count]}
1209 if [ ! "$new_node_ip" ]; then
1210 echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
1213 ((controller_count++))
1215 next_private_ip=$(next_ip $next_private_ip)
1216 if [ ! "$next_private_ip" ]; then
1217 echo "{red}ERROR: Could not find private ip for $node ${reset}"
1220 new_node_ip=$next_private_ip
1222 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
1223 ##replace host_ip in vm_nodes_provision with private ip
1224 sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
1226 if [ ! -z "$ping_site" ]; then
1227 sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
1230 ##find public ip info and add public interface
1231 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1232 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1233 this_public_ip=${public_ip_arr[$node]}
1235 if [ -z "$enable_virtual_dhcp" ]; then
1236 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
1238 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
1240 remove_vagrant_network eth_replace3
1242 ##modify provisioning to do puppet install, config, and foreman check-in
1243 ##substitute host_name and dns_server in the provisioning script
1244 host_string=config_nodes_${node}_short_name
1245 short_host_name=$(eval echo \$$host_string)
1246 ##substitute domain_name
1247 domain_name=$config_domain_name
1248 sed -i 's/^domain_name=REPLACE/domain_name='$domain_name'/' vm_nodes_provision.sh
1249 host_name=${short_host_name}.${domain_name}
1250 sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
1251 ##dns server should be the foreman server
1252 sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
1253 ## remove bootstrap and NAT provisioning
1254 sed -i '/nat_setup.sh/d' Vagrantfile
1255 sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
1256 ## modify default_gw to be node_default_gw
1257 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
1258 echo "${blue}Starting Vagrant Node $node! ${reset}"
1260 if ! vagrant up; then
1261 echo "${red} Unable to start $node ${reset}"
1264 echo "${blue} $node VM is up! ${reset}"
1267 echo "${blue} All VMs are UP! ${reset}"
1268 echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
1269 ##check puppet is complete
1270 ##ssh into foreman server, run check to verify puppet is complete
1271 pushd $vm_dir/foreman_vm
1272 if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
1273 echo "${red} Failed to validate puppet completion on nodes ${reset}"
1276 echo "{$blue} Puppet complete on all nodes! ${reset}"
1279 ##add routes back to nodes
1280 for node in ${nodes}; do
1282 if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
1283 echo "${blue} Adding public route back to $node! ${reset}"
1284 vagrant ssh -c "route add default gw $this_default_gw"
1285 vagrant ssh -c "route delete default gw 10.0.2.2"
1289 if [ ! -z "$horizon_public_vip" ]; then
1290 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
1292 ##Find public IP of controller
1293 for node in ${nodes}; do
1294 node_type=config_nodes_${node}_type
1295 node_type=$(eval echo \$$node_type)
1296 if [ "$node_type" == "controller" ]; then
1298 horizon_ip=`vagrant ssh -c "ifconfig enp0s10" | grep -Eo "inet [0-9\.]+" | awk {'print $2'}`
1303 if [ -z "$horizon_ip" ]; then
1304 echo "${red}Warn: Unable to determine horizon IP, please login to your controller node to find it${reset}"
1306 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_ip} ${reset}"
1311 ##check to make sure nodes are powered off
1312 ##this function does nothing if virtual
1314 ##usage: check_baremetal_nodes()
1315 check_baremetal_nodes() {
1316 if [ $virtual ]; then
1317 echo "${blue}Skipping Baremetal node power status check as deployment is virtual ${reset}"
1319 echo "${blue}Checking Baremetal nodes power state... ${reset}"
1320 if [ ! -z "$base_config" ]; then
1322 # Major version is pinned to force some consistency for Arno
1323 if ! yum list installed | grep -i ipmitool; then
1324 echo "${blue}Installing ipmitool...${reset}"
1325 if ! yum -y install ipmitool-1*; then
1326 echo "${red}Failed to install ipmitool!${reset}"
1331 ###find all the bmc IPs and number of nodes
1333 output=`grep bmc_ip $base_config | grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+'`
1334 for line in ${output} ; do
1335 bmc_ip[$node_counter]=$line
1339 max_nodes=$((node_counter-1))
1341 ###find bmc_users per node
1343 output=`grep bmc_user $base_config | sed 's/\s*bmc_user:\s*//'`
1344 for line in ${output} ; do
1345 bmc_user[$node_counter]=$line
1349 ###find bmc_pass per node
1351 output=`grep bmc_pass $base_config | sed 's/\s*bmc_pass:\s*//'`
1352 for line in ${output} ; do
1353 bmc_pass[$node_counter]=$line
1357 for mynode in `seq 0 $max_nodes`; do
1358 echo "${blue}Node: ${bmc_ip[$mynode]} ${bmc_user[$mynode]} ${bmc_pass[$mynode]} ${reset}"
1359 ipmi_output=`ipmitool -I lanplus -P ${bmc_pass[$mynode]} -U ${bmc_user[$mynode]} -H ${bmc_ip[$mynode]} chassis status \
1360 | grep "System Power" | cut -d ':' -f2 | tr -d [:blank:]`
1361 if [ "$ipmi_output" == "on" ]; then
1362 echo "${red}Error: Node is powered on: ${bmc_ip[$mynode]} ${reset}"
1363 echo "${red}Please run clean.sh before running deploy! ${reset}"
1365 elif [ "$ipmi_output" == "off" ]; then
1366 echo "${blue}Node: ${bmc_ip[$mynode]} is powered off${reset}"
1368 echo "${red}Warning: Unable to detect node power state: ${bmc_ip[$mynode]} ${reset}"
1372 echo "${red}base_config was not provided for a baremetal install! Exiting${reset}"
1378 ##resizes vagrant disk (cannot shrink)
1379 ##params: size in GB
1380 ##usage: resize_vagrant_disk 100
1381 resize_vagrant_disk() {
1382 if [[ "$1" < 40 ]]; then
1383 echo "${blue}Warn: Requested disk size cannot be less than 40, using 40 as new size${reset}"
1389 if ! vagrant box list | grep opnfv; then
1390 vagrant box remove -f opnfv/centos-7.0
1391 if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
1392 echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
1397 pushd $vagrant_box_dir
1399 # Close medium to make sure we can modify it
1400 vboxmanage closemedium disk $vagrant_box_vmdk
1402 cur_size=$(vboxmanage showhdinfo $vagrant_box_vmdk | grep -i capacity | grep -Eo [0-9]+)
1403 cur_size_gb=$((cur_size / 1024))
1405 if [ "$cur_size_gb" -eq "$new_size_gb" ]; then
1406 echo "${blue}Info: Disk size already ${cur_size_gb} ${reset}"
1409 elif [[ "$new_size_gb" < "$cur_size_gb" ]] ; then
1410 echo "${blue}Info: Requested disk is less than ${cur_size_gb} ${reset}"
1411 echo "${blue}Re-adding vagrant box${reset}"
1412 if vagrant box list | grep opnfv; then
1414 vagrant box remove -f opnfv/centos-7.0
1415 if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
1416 echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
1419 pushd $vagrant_box_dir
1423 new_size=$((new_size_gb * 1024))
1424 if ! vboxmanage clonehd $vagrant_box_vmdk tmp-disk.vdi --format vdi; then
1425 echo "${red}Error: Unable to clone ${vagrant_box_vmdk}${reset}"
1430 if ! vboxmanage modifyhd tmp-disk.vdi --resize $new_size; then
1431 echo "${red}Error: Unable modify tmp-disk.vdi to ${new_size}${reset}"
1436 if ! vboxmanage clonehd tmp-disk.vdi resized-disk.vmdk --format vmdk; then
1437 echo "${red}Error: Unable clone tmp-disk.vdi to vmdk${reset}"
1442 vboxmanage closemedium disk tmp-disk.vdi --delete
1443 rm -f tmp-disk.vdi $vagrant_box_vmdk
1444 cp -f resized-disk.vmdk $vagrant_box_vmdk
1445 vboxmanage closemedium disk resized-disk.vmdk --delete
1454 check_baremetal_nodes
1461 clone_bgs $vm_dir/foreman_vm