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
625 public_short_subnet_mask=$(find_short_netmask $single_baremetal_nic)
628 ##find number of interfaces with ip and substitute in VagrantFile
630 for interface in ${output}; do
632 if [ "$if_counter" -ge 4 ]; then
635 interface_ip=$(find_ip $interface)
636 if [ ! "$interface_ip" ]; then
639 new_ip=$(next_usable_ip $interface_ip)
640 if [ ! "$new_ip" ]; then
643 interface_arr[$interface]=$if_counter
644 interface_ip_arr[$if_counter]=$new_ip
645 subnet_mask=$(find_netmask $interface)
646 if [ "$if_counter" -eq 0 ]; then
647 admin_subnet_mask=$subnet_mask
648 if ! verify_subnet_size $admin_subnet_mask 5; then
649 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}"
653 elif [ "$if_counter" -eq 1 ]; then
654 private_subnet_mask=$subnet_mask
655 private_short_subnet_mask=$(find_short_netmask $interface)
657 if ! verify_subnet_size $private_subnet_mask 15; then
658 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}"
661 elif [ "$if_counter" -eq 2 ]; then
662 public_subnet_mask=$subnet_mask
663 public_short_subnet_mask=$(find_short_netmask $interface)
665 if ! verify_subnet_size $public_subnet_mask 25; then
666 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}"
669 elif [ "$if_counter" -eq 3 ]; then
670 storage_subnet_mask=$subnet_mask
672 if ! verify_subnet_size $storage_subnet_mask 10; then
673 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}"
677 echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
680 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
686 ##now remove interface config in Vagrantfile for 1 node
687 ##if 1, 3, or 4 interfaces set deployment type
688 ##if 2 interfaces remove 2nd interface and set deployment type
689 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
690 if [ $virtual ]; then
691 deployment_type="single_network"
692 echo "${blue}Single network detected for Virtual deployment...converting to three_network with internal networks! ${reset}"
693 private_internal_ip=155.1.2.2
694 admin_internal_ip=156.1.2.2
695 private_subnet_mask=255.255.255.0
696 private_short_subnet_mask=/24
697 interface_ip_arr[1]=$private_internal_ip
698 interface_ip_arr[0]=$admin_internal_ip
699 admin_subnet_mask=255.255.255.0
700 admin_short_subnet_mask=/24
701 sed -i 's/^.*eth_replace1.*$/ config.vm.network "private_network", virtualbox__intnet: "my_private_network", ip: '\""$private_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
702 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$admin_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
703 remove_vagrant_network eth_replace3
704 deployment_type=three_network
705 elif [[ "$if_counter" == 1 ]]; then
706 echo "${blue}Single network detected for Baremetal deployment! ${reset}"
707 remove_vagrant_network eth_replace1
708 remove_vagrant_network eth_replace2
709 remove_vagrant_network eth_replace3
710 deployment_type="single_network"
712 echo "${blue}Single network or 2 network detected for baremetal deployment. This is unsupported! Exiting. ${reset}"
715 elif [ "$if_counter" == 3 ]; then
716 deployment_type="three_network"
717 remove_vagrant_network eth_replace3
719 deployment_type="multi_network"
722 echo "${blue}Network detected: ${deployment_type}! ${reset}"
724 if [ $virtual ]; then
725 if [ -z "$enable_virtual_dhcp" ]; then
726 sed -i 's/^.*disable_dhcp_flag =.*$/ disable_dhcp_flag = true/' Vagrantfile
727 if [ $static_ip_range ]; then
728 ##verify static range is at least 20 IPs
729 static_ip_range_begin=$(echo $static_ip_range | cut -d , -f1)
730 static_ip_range_end=$(echo $static_ip_range | cut -d , -f2)
731 ##verify range is at least 20 ips
732 ##assumes less than 255 range pool
733 begin_octet=$(echo $static_ip_range_begin | cut -d . -f4)
734 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
735 ip_count=$((end_octet-begin_octet+1))
736 if [ "$ip_count" -lt 20 ]; then
737 echo "${red}Static range is less than 20 ips: ${ip_count}, exiting ${reset}"
740 echo "${blue}Static IP range is size $ip_count ${reset}"
746 if route | grep default; then
747 echo "${blue}Default Gateway Detected ${reset}"
748 host_default_gw=$(ip route | grep default | awk '{print $3}')
749 echo "${blue}Default Gateway: $host_default_gw ${reset}"
750 default_gw_interface=$(ip route get $host_default_gw | awk '{print $3}')
751 case "${interface_arr[$default_gw_interface]}" in
753 echo "${blue}Default Gateway Detected on Admin Interface!${reset}"
754 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
755 node_default_gw=$host_default_gw
758 echo "${red}Default Gateway Detected on Private Interface!${reset}"
759 echo "${red}Private subnet should be private and not have Internet access!${reset}"
763 echo "${blue}Default Gateway Detected on Public Interface!${reset}"
764 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
765 echo "${blue}Will setup NAT from Admin -> Public Network on VM!${reset}"
766 sed -i 's/^.*nat_flag =.*$/ nat_flag = true/' Vagrantfile
767 echo "${blue}Setting node gateway to be VM Admin IP${reset}"
768 node_default_gw=${interface_ip_arr[0]}
769 public_gateway=$default_gw
772 echo "${red}Default Gateway Detected on Storage Interface!${reset}"
773 echo "${red}Storage subnet should be private and not have Internet access!${reset}"
777 echo "${red}Unable to determine which interface default gateway is on..Exiting!${reset}"
783 defaultgw=`echo ${interface_ip_arr[0]} | cut -d. -f1-3`
785 defaultgw=$defaultgw$firstip
786 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
787 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
788 node_default_gw=$defaultgw
791 if [ $base_config ]; then
792 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
793 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
798 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'`
799 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
800 echo "${blue}Controller nodes found in settings: ${controller_nodes}${reset}"
801 my_controller_array=( $controller_nodes )
802 num_control_nodes=${#my_controller_array[@]}
803 if [ "$num_control_nodes" -ne 3 ]; then
804 if cat opnfv_ksgen_settings.yml | grep ha_flag | grep true; then
805 echo "${red}Error: You must define exactly 3 control nodes when HA flag is true!${reset}"
809 echo "${blue}Number of Controller nodes detected: ${num_control_nodes}${reset}"
812 if [ $no_parse ]; then
813 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
817 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
818 ##Edit the ksgen settings appropriately
819 ##ksgen settings will be stored in /vagrant on the vagrant machine
820 ##if single node deployment all the variables will have the same ip
821 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
823 sed -i 's/^.*default_gw:.*$/default_gw:'" $node_default_gw"'/' opnfv_ksgen_settings.yml
825 ##replace private interface parameter
826 ##private interface will be of hosts, so we need to know the provisioned host interface name
827 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
828 ##replace IP for parameters with next IP that will be given to controller
830 if [[ "$deployment_type" == "single_network" || "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
832 if [ "$deployment_type" == "three_network" ]; then
833 sed -i 's/^.*network_type:.*$/network_type: three_network/' opnfv_ksgen_settings.yml
834 elif [ "$deployment_type" == "single_network" ]; then
835 sed -i 's/^.*network_type:.*$/network_type: single_network/' opnfv_ksgen_settings.yml
836 next_single_ip=${interface_ip_arr[0]}
837 foreman_ip=$next_single_ip
838 next_single_ip=$(next_usable_ip $next_single_ip)
841 sed -i 's/^.*deployment_type:.*$/ deployment_type: '"$deployment_type"'/' opnfv_ksgen_settings.yml
843 ##get ip addresses for private network on controllers to make dhcp entries
844 ##required for controllers_ip_array global param
845 if [ "$deployment_type" == "single_network" ]; then
846 next_private_ip=$next_single_ip
847 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
848 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'`
849 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
850 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
851 nodes=${controller_nodes}${compute_nodes}
852 next_admin_ip=${interface_ip_arr[0]}
856 for node in ${controller_nodes}; do
857 next_private_ip=$(next_usable_ip $next_private_ip)
858 if [ ! "$next_private_ip" ]; then
859 echo "${red} Unable to find an unused IP for $node ! ${reset}"
862 sed -i 's/'"$node$type1"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
863 sed -i 's/'"$node$type2"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
864 controller_ip_array=$controller_ip_array$next_private_ip,
865 controllers_ip_arr[$control_count]=$next_private_ip
870 for node in ${compute_nodes}; do
871 next_private_ip=$(next_usable_ip $next_private_ip)
872 if [ ! "$next_private_ip" ]; then
873 echo "${red} Unable to find an unused IP for $node ! ${reset}"
876 sed -i 's/'"$node$type1"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
881 next_private_ip=${interface_ip_arr[1]}
885 for node in controller1 controller2 controller3; do
886 next_private_ip=$(next_usable_ip $next_private_ip)
887 if [ ! "$next_private_ip" ]; then
888 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
891 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
892 controller_ip_array=$controller_ip_array$next_private_ip,
893 controllers_ip_arr[$control_count]=$next_private_ip
898 if [[ "$deployment_type" != "single_network" ]]; then
899 next_public_ip=${interface_ip_arr[2]}
900 foreman_ip=$next_public_ip
903 ##if no dhcp, find all the Admin IPs for nodes in advance
904 if [ $virtual ]; then
905 if [ -z "$enable_virtual_dhcp" ]; then
906 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
907 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'`
908 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
909 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
910 nodes=${controller_nodes}${compute_nodes}
911 next_admin_ip=${interface_ip_arr[0]}
913 for node in ${nodes}; do
914 next_admin_ip=$(next_ip $next_admin_ip)
915 if [ ! "$next_admin_ip" ]; then
916 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
919 admin_ip_arr[$node]=$next_admin_ip
920 sed -i 's/'"$node$type"'/'"$next_admin_ip"'/g' opnfv_ksgen_settings.yml
924 ##allocate node public IPs
925 for node in ${nodes}; do
926 next_public_ip=$(next_usable_ip $next_public_ip)
927 if [ ! "$next_public_ip" ]; then
928 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
931 public_ip_arr[$node]=$next_public_ip
936 ##replace global param for controllers_ip_array
937 controller_ip_array=${controller_ip_array%?}
938 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
940 ##now replace all the VIP variables. admin//private can be the same IP
941 ##we have to use IP's here that won't be allocated to hosts at provisioning time
942 ##therefore we increment the ip by 10 to make sure we have a safe buffer
943 next_private_ip=$(increment_ip $next_private_ip 10)
945 private_output=$(grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml)
946 if [ ! -z "$private_output" ]; then
947 while read -r line; do
948 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
949 next_private_ip=$(next_usable_ip $next_private_ip)
950 if [ ! "$next_private_ip" ]; then
951 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
954 done <<< "$private_output"
957 ##replace odl_control_ip (non-HA only)
958 odl_control_ip=${controllers_ip_arr[0]}
959 sed -i 's/^.*odl_control_ip:.*$/ odl_control_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
961 ##replace controller_ip (non-HA only)
962 sed -i 's/^.*controller_ip:.*$/ controller_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
964 ##replace foreman site
965 sed -i 's/^.*foreman_url:.*$/ foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
966 ##replace public vips
968 ##if single_network deployment we continue next_public_ip from next_private_ip
969 if [[ "$deployment_type" == "single_network" ]]; then
970 next_public_ip=$(next_usable_ip $next_private_ip)
972 ##no need to do this if no dhcp
973 if [[ -z "$enable_virtual_dhcp" && ! -z "$virtual" ]]; then
974 next_public_ip=$(next_usable_ip $next_public_ip)
976 next_public_ip=$(increment_ip $next_public_ip 10)
980 public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
981 if [ ! -z "$public_output" ]; then
982 while read -r line; do
983 if echo $line | grep horizon_public_vip; then
984 horizon_public_vip=$next_public_ip
986 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
987 next_public_ip=$(next_usable_ip $next_public_ip)
988 if [ ! "$next_public_ip" ]; then
989 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
992 done <<< "$public_output"
995 ##replace public_network param
996 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
997 sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
998 if [ "$deployment_type" == "single_network" ]; then
999 sed -i 's/^.*private_network:.*$/ private_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1001 ##replace private_network param
1002 private_subnet=$(find_subnet $next_private_ip $private_subnet_mask)
1003 sed -i 's/^.*private_network:.*$/ private_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
1006 ##replace storage_network
1007 if [ "$deployment_type" == "single_network" ]; then
1008 sed -i 's/^.*storage_network:.*$/ storage_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1009 elif [ "$deployment_type" == "three_network" ]; then
1010 sed -i 's/^.*storage_network:.*$/ storage_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
1012 next_storage_ip=${interface_ip_arr[3]}
1013 storage_subnet=$(find_subnet $next_storage_ip $storage_subnet_mask)
1014 sed -i 's/^.*storage_network:.*$/ storage_network:'" $storage_subnet"'/' opnfv_ksgen_settings.yml
1017 ##replace public_subnet param
1018 public_subnet=$public_subnet'\'$public_short_subnet_mask
1019 sed -i 's/^.*public_subnet:.*$/ public_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1020 if [ "$deployment_type" == "single_network" ]; then
1021 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
1023 ##replace private_subnet param
1024 private_subnet=$private_subnet'\'$private_short_subnet_mask
1025 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"'/' opnfv_ksgen_settings.yml
1028 ##replace public_dns param to be foreman server
1029 if [ "$deployment_type" == "single_network" ]; then
1030 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[0]}'/' opnfv_ksgen_settings.yml
1032 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[2]}'/' opnfv_ksgen_settings.yml
1035 ##replace public_gateway
1036 if [ -z "$public_gateway" ]; then
1037 if [ "$deployment_type" == "single_network" ]; then
1038 public_gateway=$node_default_gw
1040 ##if unset then we assume its the first IP in the public subnet
1041 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
1042 public_gateway=$(increment_subnet $public_subnet 1)
1045 sed -i 's/^.*public_gateway:.*$/ public_gateway:'" $public_gateway"'/' opnfv_ksgen_settings.yml
1047 ##we have to define an allocation range of the public subnet to give
1048 ##to neutron to use as floating IPs
1049 ##if static ip range, then we take the difference of the end range and current ip
1050 ## to be the allocation pool
1051 ##if not static ip, we will use the last 20 IP from the subnet
1052 ## note that this is not a really good idea because the subnet must be at least a /27 for this to work...
1053 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
1054 if [ ! -z "$static_ip_range" ]; then
1055 begin_octet=$(echo $next_public_ip | cut -d . -f4)
1056 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
1057 ip_diff=$((end_octet-begin_octet))
1058 if [ $ip_diff -le 0 ]; then
1059 echo "${red}ip range left for floating range is less than or equal to 0! $ipdiff ${reset}"
1062 public_allocation_start=$(next_ip $next_public_ip)
1063 public_allocation_end=$static_ip_range_end
1066 last_ip_subnet=$(find_last_ip_subnet $next_public_ip $public_subnet_mask)
1067 public_allocation_start=$(subtract_ip $last_ip_subnet $floating_ip_count )
1068 public_allocation_end=${last_ip_subnet}
1070 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
1072 sed -i 's/^.*public_allocation_start:.*$/ public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
1073 sed -i 's/^.*public_allocation_end:.*$/ public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
1076 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
1080 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
1085 ##Configure bootstrap.sh to use the virtual Khaleesi playbook
1087 ##usage: configure_virtual()
1088 configure_virtual() {
1089 if [ $virtual ]; then
1090 echo "${blue} Virtual flag detected, setting Khaleesi playbook to be opnfv-vm.yml ${reset}"
1091 sed -i 's/opnfv.yml/opnfv-vm.yml/' bootstrap.sh
1095 ##Starts Foreman VM with Vagrant
1097 ##usage: start_vagrant()
1099 echo "${blue}Starting Vagrant! ${reset}"
1102 if ! vagrant up; then
1103 printf '%s\n' 'deploy.sh: Unable to complete Foreman VM install' >&2
1106 echo "${blue}Foreman VM is up! ${reset}"
1110 ##start the VM if this is a virtual installation
1111 ##this function does nothing if baremetal servers are being used
1113 ##usage: start_virtual_nodes()
1114 start_virtual_nodes() {
1115 if [ $virtual ]; then
1118 echo "${blue}Setting VMs up... ${reset}"
1119 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'`
1120 ##due to ODL Helium bug of OVS connecting to ODL too early, we need controllers to install first
1121 ##this is fix kind of assumes more than I would like to, but for now it should be OK as we always have
1122 ##3 static controllers
1123 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
1124 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
1125 nodes=${controller_nodes}${compute_nodes}
1127 compute_wait_completed=false
1129 for node in ${nodes}; do
1131 ##remove VM nodes incase it wasn't cleaned up
1132 rm -rf $vm_dir/$node
1133 rm -rf /tmp/genesis/
1135 ##clone genesis and move into node folder
1136 clone_bgs $vm_dir/$node
1140 if [ $base_config ]; then
1141 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
1142 echo "${red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
1147 ##parse yaml into variables
1148 eval $(parse_yaml opnfv_ksgen_settings.yml "config_")
1150 node_type=config_nodes_${node}_type
1151 node_type=$(eval echo \$$node_type)
1153 ##modify memory and cpu
1154 node_memory=$(eval echo \${config_nodes_${node}_memory})
1155 node_vcpus=$(eval echo \${config_nodes_${node}_cpus})
1156 node_storage=$(eval echo \${config_nodes_${node}_disk})
1158 sed -i 's/^.*vb.memory =.*$/ vb.memory = '"$node_memory"'/' Vagrantfile
1159 sed -i 's/^.*vb.cpus =.*$/ vb.cpus = '"$node_vcpus"'/' Vagrantfile
1161 if ! resize_vagrant_disk $node_storage; then
1162 echo "${red}Error while resizing vagrant box to size $node_storage for $node! ${reset}"
1166 ##trozet test make compute nodes wait 20 minutes
1167 if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
1168 echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
1169 compute_wait_completed=true
1173 ## Add Admin interface
1174 mac_string=config_nodes_${node}_mac_address
1175 mac_addr=$(eval echo \$$mac_string)
1176 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1177 if [ $mac_addr == "" ]; then
1178 echo "${red} Unable to find mac_address for $node! ${reset}"
1181 this_admin_ip=${admin_ip_arr[$node]}
1182 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
1184 ## Add private interface
1185 if [ "$node_type" == "controller" ]; then
1186 mac_string=config_nodes_${node}_private_mac
1187 mac_addr=$(eval echo \$$mac_string)
1188 if [ $mac_addr == "" ]; then
1189 echo "${red} Unable to find private_mac for $node! ${reset}"
1193 ##generate random mac
1194 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1196 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1197 if [ "$node_type" == "controller" ]; then
1198 new_node_ip=${controllers_ip_arr[$controller_count]}
1199 if [ ! "$new_node_ip" ]; then
1200 echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
1203 ((controller_count++))
1205 next_private_ip=$(next_ip $next_private_ip)
1206 if [ ! "$next_private_ip" ]; then
1207 echo "{red}ERROR: Could not find private ip for $node ${reset}"
1210 new_node_ip=$next_private_ip
1212 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
1213 ##replace host_ip in vm_nodes_provision with private ip
1214 sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
1216 if [ ! -z "$ping_site" ]; then
1217 sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
1220 ##find public ip info and add public interface
1221 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1222 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1223 this_public_ip=${public_ip_arr[$node]}
1225 if [ -z "$enable_virtual_dhcp" ]; then
1226 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
1228 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
1230 remove_vagrant_network eth_replace3
1232 ##modify provisioning to do puppet install, config, and foreman check-in
1233 ##substitute host_name and dns_server in the provisioning script
1234 host_string=config_nodes_${node}_short_name
1235 short_host_name=$(eval echo \$$host_string)
1236 ##substitute domain_name
1237 domain_name=$config_domain_name
1238 sed -i 's/^domain_name=REPLACE/domain_name='$domain_name'/' vm_nodes_provision.sh
1239 host_name=${short_host_name}.${domain_name}
1240 sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
1241 ##dns server should be the foreman server
1242 sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
1243 ## remove bootstrap and NAT provisioning
1244 sed -i '/nat_setup.sh/d' Vagrantfile
1245 sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
1246 ## modify default_gw to be node_default_gw
1247 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
1248 echo "${blue}Starting Vagrant Node $node! ${reset}"
1250 if ! vagrant up; then
1251 echo "${red} Unable to start $node ${reset}"
1254 echo "${blue} $node VM is up! ${reset}"
1257 echo "${blue} All VMs are UP! ${reset}"
1258 echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
1259 ##check puppet is complete
1260 ##ssh into foreman server, run check to verify puppet is complete
1261 pushd $vm_dir/foreman_vm
1262 if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
1263 echo "${red} Failed to validate puppet completion on nodes ${reset}"
1266 echo "{$blue} Puppet complete on all nodes! ${reset}"
1269 ##add routes back to nodes
1270 for node in ${nodes}; do
1272 if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
1273 echo "${blue} Adding public route back to $node! ${reset}"
1274 vagrant ssh -c "route add default gw $this_default_gw"
1275 vagrant ssh -c "route delete default gw 10.0.2.2"
1279 if [ ! -z "$horizon_public_vip" ]; then
1280 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
1282 ##Find public IP of controller
1283 for node in ${nodes}; do
1284 node_type=config_nodes_${node}_type
1285 node_type=$(eval echo \$$node_type)
1286 if [ "$node_type" == "controller" ]; then
1288 horizon_ip=`vagrant ssh -c "ifconfig enp0s10" | grep -Eo "inet [0-9\.]+" | awk {'print $2'}`
1293 if [ -z "$horizon_ip" ]; then
1294 echo "${red}Warn: Unable to determine horizon IP, please login to your controller node to find it${reset}"
1296 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_ip} ${reset}"
1301 ##check to make sure nodes are powered off
1302 ##this function does nothing if virtual
1304 ##usage: check_baremetal_nodes()
1305 check_baremetal_nodes() {
1306 if [ $virtual ]; then
1307 echo "${blue}Skipping Baremetal node power status check as deployment is virtual ${reset}"
1309 echo "${blue}Checking Baremetal nodes power state... ${reset}"
1310 if [ ! -z "$base_config" ]; then
1312 # Major version is pinned to force some consistency for Arno
1313 if ! yum list installed | grep -i ipmitool; then
1314 echo "${blue}Installing ipmitool...${reset}"
1315 if ! yum -y install ipmitool-1*; then
1316 echo "${red}Failed to install ipmitool!${reset}"
1321 ###find all the bmc IPs and number of nodes
1323 output=`grep bmc_ip $base_config | grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+'`
1324 for line in ${output} ; do
1325 bmc_ip[$node_counter]=$line
1329 max_nodes=$((node_counter-1))
1331 ###find bmc_users per node
1333 output=`grep bmc_user $base_config | sed 's/\s*bmc_user:\s*//'`
1334 for line in ${output} ; do
1335 bmc_user[$node_counter]=$line
1339 ###find bmc_pass per node
1341 output=`grep bmc_pass $base_config | sed 's/\s*bmc_pass:\s*//'`
1342 for line in ${output} ; do
1343 bmc_pass[$node_counter]=$line
1347 for mynode in `seq 0 $max_nodes`; do
1348 echo "${blue}Node: ${bmc_ip[$mynode]} ${bmc_user[$mynode]} ${bmc_pass[$mynode]} ${reset}"
1349 ipmi_output=`ipmitool -I lanplus -P ${bmc_pass[$mynode]} -U ${bmc_user[$mynode]} -H ${bmc_ip[$mynode]} chassis status \
1350 | grep "System Power" | cut -d ':' -f2 | tr -d [:blank:]`
1351 if [ "$ipmi_output" == "on" ]; then
1352 echo "${red}Error: Node is powered on: ${bmc_ip[$mynode]} ${reset}"
1353 echo "${red}Please run clean.sh before running deploy! ${reset}"
1355 elif [ "$ipmi_output" == "off" ]; then
1356 echo "${blue}Node: ${bmc_ip[$mynode]} is powered off${reset}"
1358 echo "${red}Warning: Unable to detect node power state: ${bmc_ip[$mynode]} ${reset}"
1362 echo "${red}base_config was not provided for a baremetal install! Exiting${reset}"
1368 ##resizes vagrant disk (cannot shrink)
1369 ##params: size in GB
1370 ##usage: resize_vagrant_disk 100
1371 resize_vagrant_disk() {
1372 if [[ "$1" < 40 ]]; then
1373 echo "${blue}Warn: Requested disk size cannot be less than 40, using 40 as new size${reset}"
1379 if ! vagrant box list | grep opnfv; then
1380 vagrant box remove -f opnfv/centos-7.0
1381 if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
1382 echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
1387 pushd $vagrant_box_dir
1389 # Close medium to make sure we can modify it
1390 vboxmanage closemedium disk $vagrant_box_vmdk
1392 cur_size=$(vboxmanage showhdinfo $vagrant_box_vmdk | grep -i capacity | grep -Eo [0-9]+)
1393 cur_size_gb=$((cur_size / 1024))
1395 if [ "$cur_size_gb" -eq "$new_size_gb" ]; then
1396 echo "${blue}Info: Disk size already ${cur_size_gb} ${reset}"
1399 elif [[ "$new_size_gb" < "$cur_size_gb" ]] ; then
1400 echo "${blue}Info: Requested disk is less than ${cur_size_gb} ${reset}"
1401 echo "${blue}Re-adding vagrant box${reset}"
1402 if vagrant box list | grep opnfv; then
1404 vagrant box remove -f opnfv/centos-7.0
1405 if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
1406 echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
1409 pushd $vagrant_box_dir
1413 new_size=$((new_size_gb * 1024))
1414 if ! vboxmanage clonehd $vagrant_box_vmdk tmp-disk.vdi --format vdi; then
1415 echo "${red}Error: Unable to clone ${vagrant_box_vmdk}${reset}"
1420 if ! vboxmanage modifyhd tmp-disk.vdi --resize $new_size; then
1421 echo "${red}Error: Unable modify tmp-disk.vdi to ${new_size}${reset}"
1426 if ! vboxmanage clonehd tmp-disk.vdi resized-disk.vmdk --format vmdk; then
1427 echo "${red}Error: Unable clone tmp-disk.vdi to vmdk${reset}"
1432 vboxmanage closemedium disk tmp-disk.vdi --delete
1433 rm -f tmp-disk.vdi $vagrant_box_vmdk
1434 cp -f resized-disk.vmdk $vagrant_box_vmdk
1435 vboxmanage closemedium disk resized-disk.vmdk --delete
1444 check_baremetal_nodes
1451 clone_bgs $vm_dir/foreman_vm