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"
60 ##verify vm dir exists
62 function verify_vm_dir {
63 if [ -d "$vm_dir" ]; then
64 echo -e "\n\n${red}ERROR: VM Directory: $vm_dir already exists. Environment not clean. Please use clean.sh. Exiting${reset}\n\n"
72 if [ ! -d $vm_dir ]; then
73 echo -e "\n\n${red}ERROR: Unable to create VM Directory: $vm_dir Exiting${reset}\n\n"
78 ##find ip of interface
79 ##params: interface name
81 ip addr show $1 | grep -Eo '^\s+inet\s+[\.0-9]+' | awk '{print $2}'
84 ##finds subnet of ip and netmask
86 function find_subnet {
87 IFS=. read -r i1 i2 i3 i4 <<< "$1"
88 IFS=. read -r m1 m2 m3 m4 <<< "$2"
89 printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
92 ##verify subnet has at least n IPs
93 ##params: subnet mask, n IPs
94 function verify_subnet_size {
95 IFS=. read -r i1 i2 i3 i4 <<< "$1"
98 ##this function assumes you would never need more than 254
99 ##we check here to make sure
100 if [ "$num_ips_required" -ge 254 ]; then
101 echo -e "\n\n${red}ERROR: allocating more than 254 IPs is unsupported...Exiting${reset}\n\n"
105 ##we just return if 3rd octet is not 255
106 ##because we know the subnet is big enough
107 if [ "$i3" -ne 255 ]; then
109 elif [ $((254-$i4)) -ge "$num_ips_required" ]; then
112 echo -e "\n\n${red}ERROR: Subnet is too small${reset}\n\n"
117 ##finds last usable ip (broadcast minus 1) of a subnet from an IP and netmask
118 ## Warning: This function only works for IPv4 at the moment.
119 ##params: ip, netmask
120 function find_last_ip_subnet {
121 IFS=. read -r i1 i2 i3 i4 <<< "$1"
122 IFS=. read -r m1 m2 m3 m4 <<< "$2"
123 IFS=. read -r s1 s2 s3 s4 <<< "$((i1 & m1)).$((i2 & m2)).$((i3 & m3)).$((i4 & m4))"
124 printf "%d.%d.%d.%d\n" "$((255 - $m1 + $s1))" "$((255 - $m2 + $s2))" "$((255 - $m3 + $s3))" "$((255 - $m4 + $s4 - 1))"
127 ##increments subnet by a value
130 function increment_subnet {
131 IFS=. read -r i1 i2 i3 i4 <<< "$1"
132 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 | $2))"
136 ##finds netmask of interface
138 ##returns long format 255.255.x.x
139 function find_netmask {
140 ifconfig $1 | grep -Eo 'netmask\s+[\.0-9]+' | awk '{print $2}'
143 ##finds short netmask of interface
145 ##returns short format, ex: /21
146 function find_short_netmask {
147 echo "/$(ip addr show $1 | grep -Eo '^\s+inet\s+[\/\.0-9]+' | awk '{print $2}' | cut -d / -f2)"
152 ##assumes a /24 subnet
154 baseaddr="$(echo $1 | cut -d. -f1-3)"
155 lsv="$(echo $1 | cut -d. -f4)"
156 if [ "$lsv" -ge 254 ]; then
163 ##subtracts a value from an IP address
164 ##params: last ip, ip_count
165 ##assumes ip_count is less than the last octect of the address
167 IFS=. read -r i1 i2 i3 i4 <<< "$1"
169 if [ $i4 -lt $ip_count ]; then
170 echo -e "\n\n${red}ERROR: Can't subtract $ip_count from IP address $1 Exiting${reset}\n\n"
173 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 - $ip_count ))"
176 ##removes the network interface config from Vagrantfile
178 ##assumes you are in the directory of Vagrantfile
179 function remove_vagrant_network {
180 sed -i 's/^.*'"$1"'.*$//' Vagrantfile
183 ##check if IP is in use
185 ##ping ip to get arp entry, then check arp
186 function is_ip_used {
187 ping -c 5 $1 > /dev/null 2>&1
188 arp -n | grep "$1 " | grep -iv incomplete > /dev/null 2>&1
191 ##find next usable IP
193 function next_usable_ip {
195 while [ "$new_ip" ]; do
196 if ! is_ip_used $new_ip; then
200 new_ip=$(next_ip $new_ip)
205 ##increment ip by value
206 ##params: ip, amount to increment by
207 ##increment_ip $next_private_ip 10
208 function increment_ip {
209 baseaddr="$(echo $1 | cut -d. -f1-3)"
210 lsv="$(echo $1 | cut -d. -f4)"
213 if [ "$lsv" -ge 254 ]; then
219 ##translates yaml into variables
220 ##params: filename, prefix (ex. "config_")
221 ##usage: parse_yaml opnfv_ksgen_settings.yml "config_"
224 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
225 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
226 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
228 indent = length($1)/2;
230 for (i in vname) {if (i > indent) {delete vname[i]}}
231 if (length($3) > 0) {
232 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
233 printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
238 ##translates the command line paramaters into variables
239 ##params: $@ the entire command line is passed
240 ##usage: parse_cmd_line() "$@"
242 if [[ ( $1 == "--help") || $1 == "-h" ]]; then
247 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
248 echo "Use -h to display help"
251 while [ "`echo $1 | cut -c1`" = "-" ]
267 -enable_virtual_dhcp)
268 enable_virtual_dhcp="TRUE"
310 if [ ! -z "$enable_virtual_dhcp" ] && [ ! -z "$static_ip_range" ]; then
311 echo -e "\n\n${red}ERROR: Incorrect Usage. Static IP range cannot be set when using DHCP!. Exiting${reset}\n\n"
315 if [ -z "$virtual" ]; then
316 if [ ! -z "$enable_virtual_dhcp" ]; then
317 echo -e "\n\n${red}ERROR: Incorrect Usage. enable_virtual_dhcp can only be set when using -virtual!. Exiting${reset}\n\n"
319 elif [ ! -z "$static_ip_range" ]; then
320 echo -e "\n\n${red}ERROR: Incorrect Usage. static_ip_range can only be set when using -virtual!. Exiting${reset}\n\n"
325 if [ -z "$floating_ip_count" ]; then
330 if [[ $nic_arg_flag -eq 1 ]]; then
331 if [ -z "$virtual" ]; then
332 for nic_type in admin_nic private_nic public_nic; do
333 eval "nic_value=\$$nic_type"
334 if [ -z "$nic_value" ]; then
335 echo "${red}$nic_type is empty or not defined. Required when other nic args are given!${reset}"
338 interface_ip=$(find_ip $nic_value)
339 if [ ! "$interface_ip" ]; then
340 echo "${red}$nic_value does not have an IP address! Exiting... ${reset}"
345 ##if virtual only public_nic should be specified
346 for nic_type in admin_nic private_nic storage_nic; do
347 eval "nic_value=\$$nic_type"
348 if [ ! -z "$nic_value" ]; then
349 echo "${red}$nic_type is not a valid argument using -virtual. Please only specify public_nic!${reset}"
354 interface_ip=$(find_ip $public_nic)
355 if [ ! "$interface_ip" ]; then
356 echo "${red}Public NIC: $public_nic does not have an IP address! Exiting... ${reset}"
365 ##usage: disable_selinux()
370 ##Install the EPEL repository and additional packages
372 ##usage: install_EPEL()
374 # Install EPEL repo for access to many other yum repos
375 # Major version is pinned to force some consistency for Arno
376 yum install -y epel-release-7*
378 # Install other required packages
379 # Major versions are pinned to force some consistency for Arno
380 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
381 printf '%s\n' 'deploy.sh: Unable to install depdency packages' >&2
386 ##Download and install virtual box
388 ##usage: install_vbox()
390 ##install VirtualBox repo
391 if cat /etc/*release | grep -i "Fedora release"; then
392 vboxurl=http://download.virtualbox.org/virtualbox/rpm/fedora/\$releasever/\$basearch
394 vboxurl=http://download.virtualbox.org/virtualbox/rpm/el/\$releasever/\$basearch
397 cat > /etc/yum.repos.d/virtualbox.repo << EOM
399 name=Oracle Linux / RHEL / CentOS-\$releasever / \$basearch - VirtualBox
403 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
404 skip_if_unavailable = 1
409 if ! yum list installed | grep -i virtualbox; then
410 if ! yum -y install VirtualBox-4.3; then
411 printf '%s\n' 'deploy.sh: Unable to install virtualbox package' >&2
416 ##install kmod-VirtualBox
417 if ! lsmod | grep vboxdrv; then
418 sudo /etc/init.d/vboxdrv setup
419 if ! lsmod | grep vboxdrv; then
420 printf '%s\n' 'deploy.sh: Unable to install kernel module for virtualbox' >&2
424 printf '%s\n' 'deploy.sh: Skipping kernel module for virtualbox. Already Installed'
428 ##install Ansible using yum
430 ##usage: install_ansible()
432 if ! yum list installed | grep -i ansible; then
433 if ! yum -y install ansible-1*; then
434 printf '%s\n' 'deploy.sh: Unable to install Ansible package' >&2
440 ##install Vagrant RPM directly with the bintray.com site
442 ##usage: install_vagrant()
444 if ! rpm -qa | grep vagrant; then
445 if ! rpm -Uvh https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm; then
446 printf '%s\n' 'deploy.sh: Unable to install vagrant package' >&2
450 printf '%s\n' 'deploy.sh: Skipping Vagrant install as it is already installed.'
453 ##add centos 7 box to vagrant
454 if ! vagrant box list | grep opnfv/centos-7.0; then
455 if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
456 printf '%s\n' 'deploy.sh: Unable to download centos7 box for Vagrant' >&2
460 printf '%s\n' 'deploy.sh: Skipping Vagrant box add as centos-7.0 is already installed.'
463 ##install workaround for centos7
464 if ! vagrant plugin list | grep vagrant-centos7_fix; then
465 if ! vagrant plugin install vagrant-centos7_fix; then
466 printf '%s\n' 'deploy.sh: Warning: unable to install vagrant centos7 workaround' >&2
469 printf '%s\n' 'deploy.sh: Skipping Vagrant plugin as centos7 workaround is already installed.'
474 ##remove bgs vagrant incase it wasn't cleaned up
478 rm -rf $vm_dir/foreman_vm
481 ##clone genesis and move to node vm dir
482 ##params: destination directory
483 ##usage: clone_bgs /tmp/myvm/
485 script_dir="`dirname "$script"`"
486 cp -fr $script_dir/ $1
487 cp -fr $script_dir/../../common/puppet-opnfv $1
490 ##validates the network settings and update VagrantFile with network settings
492 ##usage: configure_network()
493 configure_network() {
494 cd $vm_dir/foreman_vm
496 ##if nic_arg_flag is set, then we don't figure out
498 if [[ $nic_arg_flag -eq 1 ]]; then
499 echo "${blue}Static Network Interfaces Defined. Updating Vagrantfile...${reset}"
500 if [ $virtual ]; then
501 nic_list="$public_nic"
502 elif [ -z "$storage_nic" ]; then
503 echo "${blue}storage_nic not defined, will combine storage into private VLAN ${reset}"
504 nic_list="$admin_nic $private_nic $public_nic"
506 nic_list="$admin_nic $private_nic $public_nic $storage_nic"
508 nic_array=( $nic_list )
511 echo "${blue}Detecting network configuration...${reset}"
512 ##detect host 1 or 3 interface configuration
513 #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
514 output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | cut -d " " -f10`
517 if [ ! "$output" ]; then
518 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
522 ##virtual we only find 1 interface
523 if [ $virtual ]; then
524 if [ ! -z "${nic_array[0]}" ]; then
525 echo "${blue}Public Interface specified: ${nic_array[0]}${reset}"
526 this_default_gw_interface=${nic_array[0]}
528 ##find interface with default gateway
529 this_default_gw=$(ip route | grep default | awk '{print $3}')
530 echo "${blue}Default Gateway: $this_default_gw ${reset}"
531 this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
534 ##find interface IP, make sure its valid
535 interface_ip=$(find_ip $this_default_gw_interface)
536 if [ ! "$interface_ip" ]; then
537 echo "${red}Interface ${this_default_gw_interface} does not have an IP: $interface_ip ! Exiting ${reset}"
542 if [ ! -z "$static_ip_range" ]; then
543 new_ip=$(echo $static_ip_range | cut -d , -f1)
544 subnet_mask=$(find_netmask $this_default_gw_interface)
545 host_subnet=$(find_subnet $interface_ip $subnet_mask)
546 ip_range_subnet=$(find_subnet $new_ip $subnet_mask)
547 if [ "$ip_range_subnet" != "$host_subnet" ]; then
548 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}"
552 new_ip=$(next_usable_ip $interface_ip)
553 if [ ! "$new_ip" ]; then
554 echo "${red} Cannot find next IP on interface ${this_default_gw_interface} new_ip: $new_ip ! Exiting ${reset}"
558 interface=$this_default_gw_interface
559 public_interface=$interface
560 interface_arr[$interface]=2
561 interface_ip_arr[2]=$new_ip
562 subnet_mask=$(find_netmask $interface)
563 public_subnet_mask=$subnet_mask
564 public_short_subnet_mask=$(find_short_netmask $interface)
566 if ! verify_subnet_size $public_subnet_mask 25; then
567 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}"
571 ##set that interface to be public
572 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
575 ##find number of interfaces with ip and substitute in VagrantFile
577 for interface in ${output}; do
579 if [ "$if_counter" -ge 4 ]; then
582 interface_ip=$(find_ip $interface)
583 if [ ! "$interface_ip" ]; then
586 new_ip=$(next_usable_ip $interface_ip)
587 if [ ! "$new_ip" ]; then
590 interface_arr[$interface]=$if_counter
591 interface_ip_arr[$if_counter]=$new_ip
592 subnet_mask=$(find_netmask $interface)
593 if [ "$if_counter" -eq 0 ]; then
594 admin_subnet_mask=$subnet_mask
595 if ! verify_subnet_size $admin_subnet_mask 5; then
596 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}"
600 elif [ "$if_counter" -eq 1 ]; then
601 private_subnet_mask=$subnet_mask
602 private_short_subnet_mask=$(find_short_netmask $interface)
604 if ! verify_subnet_size $private_subnet_mask 15; then
605 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}"
608 elif [ "$if_counter" -eq 2 ]; then
609 public_subnet_mask=$subnet_mask
610 public_short_subnet_mask=$(find_short_netmask $interface)
612 if ! verify_subnet_size $public_subnet_mask 25; then
613 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}"
616 elif [ "$if_counter" -eq 3 ]; then
617 storage_subnet_mask=$subnet_mask
619 if ! verify_subnet_size $storage_subnet_mask 10; then
620 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}"
624 echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
627 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
631 ##now remove interface config in Vagrantfile for 1 node
632 ##if 1, 3, or 4 interfaces set deployment type
633 ##if 2 interfaces remove 2nd interface and set deployment type
634 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
635 if [ $virtual ]; then
636 deployment_type="single_network"
637 echo "${blue}Single network detected for Virtual deployment...converting to three_network with internal networks! ${reset}"
638 private_internal_ip=155.1.2.2
639 admin_internal_ip=156.1.2.2
640 private_subnet_mask=255.255.255.0
641 private_short_subnet_mask=/24
642 interface_ip_arr[1]=$private_internal_ip
643 interface_ip_arr[0]=$admin_internal_ip
644 admin_subnet_mask=255.255.255.0
645 admin_short_subnet_mask=/24
646 sed -i 's/^.*eth_replace1.*$/ config.vm.network "private_network", virtualbox__intnet: "my_private_network", ip: '\""$private_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
647 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$admin_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
648 remove_vagrant_network eth_replace3
649 deployment_type=three_network
651 echo "${blue}Single network or 2 network detected for baremetal deployment. This is unsupported! Exiting. ${reset}"
654 elif [ "$if_counter" == 3 ]; then
655 deployment_type="three_network"
656 remove_vagrant_network eth_replace3
658 deployment_type="multi_network"
661 echo "${blue}Network detected: ${deployment_type}! ${reset}"
663 if [ $virtual ]; then
664 if [ -z "$enable_virtual_dhcp" ]; then
665 sed -i 's/^.*disable_dhcp_flag =.*$/ disable_dhcp_flag = true/' Vagrantfile
666 if [ $static_ip_range ]; then
667 ##verify static range is at least 20 IPs
668 static_ip_range_begin=$(echo $static_ip_range | cut -d , -f1)
669 static_ip_range_end=$(echo $static_ip_range | cut -d , -f2)
670 ##verify range is at least 20 ips
671 ##assumes less than 255 range pool
672 begin_octet=$(echo $static_ip_range_begin | cut -d . -f4)
673 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
674 ip_count=$((end_octet-begin_octet+1))
675 if [ "$ip_count" -lt 20 ]; then
676 echo "${red}Static range is less than 20 ips: ${ip_count}, exiting ${reset}"
679 echo "${blue}Static IP range is size $ip_count ${reset}"
685 if route | grep default; then
686 echo "${blue}Default Gateway Detected ${reset}"
687 host_default_gw=$(ip route | grep default | awk '{print $3}')
688 echo "${blue}Default Gateway: $host_default_gw ${reset}"
689 default_gw_interface=$(ip route get $host_default_gw | awk '{print $3}')
690 case "${interface_arr[$default_gw_interface]}" in
692 echo "${blue}Default Gateway Detected on Admin Interface!${reset}"
693 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
694 node_default_gw=$host_default_gw
697 echo "${red}Default Gateway Detected on Private Interface!${reset}"
698 echo "${red}Private subnet should be private and not have Internet access!${reset}"
702 echo "${blue}Default Gateway Detected on Public Interface!${reset}"
703 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
704 echo "${blue}Will setup NAT from Admin -> Public Network on VM!${reset}"
705 sed -i 's/^.*nat_flag =.*$/ nat_flag = true/' Vagrantfile
706 echo "${blue}Setting node gateway to be VM Admin IP${reset}"
707 node_default_gw=${interface_ip_arr[0]}
708 public_gateway=$default_gw
711 echo "${red}Default Gateway Detected on Storage Interface!${reset}"
712 echo "${red}Storage subnet should be private and not have Internet access!${reset}"
716 echo "${red}Unable to determine which interface default gateway is on..Exiting!${reset}"
722 defaultgw=`echo ${interface_ip_arr[0]} | cut -d. -f1-3`
724 defaultgw=$defaultgw$firstip
725 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
726 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
727 node_default_gw=$defaultgw
730 if [ $base_config ]; then
731 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
732 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
737 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'`
738 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
739 echo "${blue}Controller nodes found in settings: ${controller_nodes}${reset}"
740 my_controller_array=( $controller_nodes )
741 num_control_nodes=${#my_controller_array[@]}
742 if [ "$num_control_nodes" -ne 3 ]; then
743 if cat opnfv_ksgen_settings.yml | grep ha_flag | grep true; then
744 echo "${red}Error: You must define exactly 3 control nodes when HA flag is true!${reset}"
748 echo "${blue}Number of Controller nodes detected: ${num_control_nodes}${reset}"
751 if [ $no_parse ]; then
752 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
756 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
757 ##Edit the ksgen settings appropriately
758 ##ksgen settings will be stored in /vagrant on the vagrant machine
759 ##if single node deployment all the variables will have the same ip
760 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
762 sed -i 's/^.*default_gw:.*$/default_gw:'" $node_default_gw"'/' opnfv_ksgen_settings.yml
764 ##replace private interface parameter
765 ##private interface will be of hosts, so we need to know the provisioned host interface name
766 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
767 ##replace IP for parameters with next IP that will be given to controller
768 if [ "$deployment_type" == "single_network" ]; then
769 ##we also need to assign IP addresses to nodes
770 ##for single node, foreman is managing the single network, so we can't reserve them
771 ##not supporting single network anymore for now
772 echo "{blue}Single Network type is unsupported right now. Please check your interface configuration. Exiting. ${reset}"
775 elif [[ "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
777 if [ "$deployment_type" == "three_network" ]; then
778 sed -i 's/^.*network_type:.*$/network_type: three_network/' opnfv_ksgen_settings.yml
781 sed -i 's/^.*deployment_type:.*$/ deployment_type: '"$deployment_type"'/' opnfv_ksgen_settings.yml
783 ##get ip addresses for private network on controllers to make dhcp entries
784 ##required for controllers_ip_array global param
785 next_private_ip=${interface_ip_arr[1]}
788 for node in controller1 controller2 controller3; do
789 next_private_ip=$(next_usable_ip $next_private_ip)
790 if [ ! "$next_private_ip" ]; then
791 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
794 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
795 controller_ip_array=$controller_ip_array$next_private_ip,
796 controllers_ip_arr[$control_count]=$next_private_ip
800 next_public_ip=${interface_ip_arr[2]}
801 foreman_ip=$next_public_ip
803 ##if no dhcp, find all the Admin IPs for nodes in advance
804 if [ $virtual ]; then
805 if [ -z "$enable_virtual_dhcp" ]; then
806 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
807 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'`
808 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
809 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
810 nodes=${controller_nodes}${compute_nodes}
811 next_admin_ip=${interface_ip_arr[0]}
813 for node in ${nodes}; do
814 next_admin_ip=$(next_ip $next_admin_ip)
815 if [ ! "$next_admin_ip" ]; then
816 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
819 admin_ip_arr[$node]=$next_admin_ip
820 sed -i 's/'"$node$type"'/'"$next_admin_ip"'/g' opnfv_ksgen_settings.yml
824 ##allocate node public IPs
825 for node in ${nodes}; do
826 next_public_ip=$(next_usable_ip $next_public_ip)
827 if [ ! "$next_public_ip" ]; then
828 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
831 public_ip_arr[$node]=$next_public_ip
836 ##replace global param for controllers_ip_array
837 controller_ip_array=${controller_ip_array%?}
838 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
840 ##now replace all the VIP variables. admin//private can be the same IP
841 ##we have to use IP's here that won't be allocated to hosts at provisioning time
842 ##therefore we increment the ip by 10 to make sure we have a safe buffer
843 next_private_ip=$(increment_ip $next_private_ip 10)
845 private_output=$(grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml)
846 if [ ! -z "$private_output" ]; then
847 while read -r line; do
848 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
849 next_private_ip=$(next_usable_ip $next_private_ip)
850 if [ ! "$next_private_ip" ]; then
851 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
854 done <<< "$private_output"
857 ##replace odl_control_ip (non-HA only)
858 odl_control_ip=${controllers_ip_arr[0]}
859 sed -i 's/^.*odl_control_ip:.*$/ odl_control_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
861 ##replace controller_ip (non-HA only)
862 sed -i 's/^.*controller_ip:.*$/ controller_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
864 ##replace foreman site
865 sed -i 's/^.*foreman_url:.*$/ foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
866 ##replace public vips
867 ##no need to do this if no dhcp
868 if [[ -z "$enable_virtual_dhcp" && ! -z "$virtual" ]]; then
869 next_public_ip=$(next_usable_ip $next_public_ip)
871 next_public_ip=$(increment_ip $next_public_ip 10)
874 public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
875 if [ ! -z "$public_output" ]; then
876 while read -r line; do
877 if echo $line | grep horizon_public_vip; then
878 horizon_public_vip=$next_public_ip
880 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
881 next_public_ip=$(next_usable_ip $next_public_ip)
882 if [ ! "$next_public_ip" ]; then
883 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
886 done <<< "$public_output"
889 ##replace public_network param
890 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
891 sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
892 ##replace private_network param
893 private_subnet=$(find_subnet $next_private_ip $private_subnet_mask)
894 sed -i 's/^.*private_network:.*$/ private_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
895 ##replace storage_network
896 if [ "$deployment_type" == "three_network" ]; then
897 sed -i 's/^.*storage_network:.*$/ storage_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
899 next_storage_ip=${interface_ip_arr[3]}
900 storage_subnet=$(find_subnet $next_storage_ip $storage_subnet_mask)
901 sed -i 's/^.*storage_network:.*$/ storage_network:'" $storage_subnet"'/' opnfv_ksgen_settings.yml
904 ##replace public_subnet param
905 public_subnet=$public_subnet'\'$public_short_subnet_mask
906 sed -i 's/^.*public_subnet:.*$/ public_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
907 ##replace private_subnet param
908 private_subnet=$private_subnet'\'$private_short_subnet_mask
909 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"'/' opnfv_ksgen_settings.yml
911 ##replace public_dns param to be foreman server
912 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[2]}'/' opnfv_ksgen_settings.yml
914 ##replace public_gateway
915 if [ -z "$public_gateway" ]; then
916 ##if unset then we assume its the first IP in the public subnet
917 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
918 public_gateway=$(increment_subnet $public_subnet 1)
920 sed -i 's/^.*public_gateway:.*$/ public_gateway:'" $public_gateway"'/' opnfv_ksgen_settings.yml
922 ##we have to define an allocation range of the public subnet to give
923 ##to neutron to use as floating IPs
924 ##if static ip range, then we take the difference of the end range and current ip
925 ## to be the allocation pool
926 ##if not static ip, we will use the last 20 IP from the subnet
927 ## note that this is not a really good idea because the subnet must be at least a /27 for this to work...
928 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
929 if [ ! -z "$static_ip_range" ]; then
930 begin_octet=$(echo $next_public_ip | cut -d . -f4)
931 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
932 ip_diff=$((end_octet-begin_octet))
933 if [ $ip_diff -le 0 ]; then
934 echo "${red}ip range left for floating range is less than or equal to 0! $ipdiff ${reset}"
937 public_allocation_start=$(next_ip $next_public_ip)
938 public_allocation_end=$static_ip_range_end
941 last_ip_subnet=$(find_last_ip_subnet $next_public_ip $public_subnet_mask)
942 public_allocation_start=$(subtract_ip $last_ip_subnet $floating_ip_count )
943 public_allocation_end=${last_ip_subnet}
945 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
947 sed -i 's/^.*public_allocation_start:.*$/ public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
948 sed -i 's/^.*public_allocation_end:.*$/ public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
951 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
955 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
960 ##Configure bootstrap.sh to use the virtual Khaleesi playbook
962 ##usage: configure_virtual()
963 configure_virtual() {
964 if [ $virtual ]; then
965 echo "${blue} Virtual flag detected, setting Khaleesi playbook to be opnfv-vm.yml ${reset}"
966 sed -i 's/opnfv.yml/opnfv-vm.yml/' bootstrap.sh
970 ##Starts Foreman VM with Vagrant
972 ##usage: start_vagrant()
974 echo "${blue}Starting Vagrant! ${reset}"
977 if ! vagrant up; then
978 printf '%s\n' 'deploy.sh: Unable to complete Foreman VM install' >&2
981 echo "${blue}Foreman VM is up! ${reset}"
985 ##start the VM if this is a virtual installation
986 ##this function does nothing if baremetal servers are being used
988 ##usage: start_virtual_nodes()
989 start_virtual_nodes() {
990 if [ $virtual ]; then
993 echo "${blue}Setting VMs up... ${reset}"
994 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'`
995 ##due to ODL Helium bug of OVS connecting to ODL too early, we need controllers to install first
996 ##this is fix kind of assumes more than I would like to, but for now it should be OK as we always have
997 ##3 static controllers
998 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
999 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
1000 nodes=${controller_nodes}${compute_nodes}
1002 compute_wait_completed=false
1004 for node in ${nodes}; do
1006 ##remove VM nodes incase it wasn't cleaned up
1007 rm -rf $vm_dir/$node
1008 rm -rf /tmp/genesis/
1010 ##clone genesis and move into node folder
1011 clone_bgs $vm_dir/$node
1015 if [ $base_config ]; then
1016 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
1017 echo "${red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
1022 ##parse yaml into variables
1023 eval $(parse_yaml opnfv_ksgen_settings.yml "config_")
1025 node_type=config_nodes_${node}_type
1026 node_type=$(eval echo \$$node_type)
1028 ##modify memory and cpu
1029 node_memory=$(eval echo \${config_nodes_${node}_memory})
1030 node_vcpus=$(eval echo \${config_nodes_${node}_cpus})
1031 node_storage=$(eval echo \${config_nodes_${node}_disk})
1033 sed -i 's/^.*vb.memory =.*$/ vb.memory = '"$node_memory"'/' Vagrantfile
1034 sed -i 's/^.*vb.cpus =.*$/ vb.cpus = '"$node_vcpus"'/' Vagrantfile
1036 if ! resize_vagrant_disk $node_storage; then
1037 echo "${red}Error while resizing vagrant box to size $node_storage for $node! ${reset}"
1041 ##trozet test make compute nodes wait 20 minutes
1042 if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
1043 echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
1044 compute_wait_completed=true
1048 ## Add Admin interface
1049 mac_string=config_nodes_${node}_mac_address
1050 mac_addr=$(eval echo \$$mac_string)
1051 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1052 if [ $mac_addr == "" ]; then
1053 echo "${red} Unable to find mac_address for $node! ${reset}"
1056 this_admin_ip=${admin_ip_arr[$node]}
1057 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
1059 ## Add private interface
1060 if [ "$node_type" == "controller" ]; then
1061 mac_string=config_nodes_${node}_private_mac
1062 mac_addr=$(eval echo \$$mac_string)
1063 if [ $mac_addr == "" ]; then
1064 echo "${red} Unable to find private_mac for $node! ${reset}"
1068 ##generate random mac
1069 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1071 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1072 if [ "$node_type" == "controller" ]; then
1073 new_node_ip=${controllers_ip_arr[$controller_count]}
1074 if [ ! "$new_node_ip" ]; then
1075 echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
1078 ((controller_count++))
1080 next_private_ip=$(next_ip $next_private_ip)
1081 if [ ! "$next_private_ip" ]; then
1082 echo "{red}ERROR: Could not find private ip for $node ${reset}"
1085 new_node_ip=$next_private_ip
1087 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
1088 ##replace host_ip in vm_nodes_provision with private ip
1089 sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
1091 if [ ! -z "$ping_site" ]; then
1092 sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
1095 ##find public ip info and add public interface
1096 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
1097 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
1098 this_public_ip=${public_ip_arr[$node]}
1100 if [ -z "$enable_virtual_dhcp" ]; then
1101 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
1103 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
1105 remove_vagrant_network eth_replace3
1107 ##modify provisioning to do puppet install, config, and foreman check-in
1108 ##substitute host_name and dns_server in the provisioning script
1109 host_string=config_nodes_${node}_hostname
1110 host_name=$(eval echo \$$host_string)
1111 sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
1112 ##dns server should be the foreman server
1113 sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
1114 ## remove bootstrap and NAT provisioning
1115 sed -i '/nat_setup.sh/d' Vagrantfile
1116 sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
1117 ## modify default_gw to be node_default_gw
1118 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
1119 echo "${blue}Starting Vagrant Node $node! ${reset}"
1121 if ! vagrant up; then
1122 echo "${red} Unable to start $node ${reset}"
1125 echo "${blue} $node VM is up! ${reset}"
1128 echo "${blue} All VMs are UP! ${reset}"
1129 echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
1130 ##check puppet is complete
1131 ##ssh into foreman server, run check to verify puppet is complete
1132 pushd $vm_dir/foreman_vm
1133 if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
1134 echo "${red} Failed to validate puppet completion on nodes ${reset}"
1137 echo "{$blue} Puppet complete on all nodes! ${reset}"
1140 ##add routes back to nodes
1141 for node in ${nodes}; do
1143 if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
1144 echo "${blue} Adding public route back to $node! ${reset}"
1145 vagrant ssh -c "route add default gw $this_default_gw"
1146 vagrant ssh -c "route delete default gw 10.0.2.2"
1150 if [ ! -z "$horizon_public_vip" ]; then
1151 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
1153 ##Find public IP of controller
1154 for node in ${nodes}; do
1155 node_type=config_nodes_${node}_type
1156 node_type=$(eval echo \$$node_type)
1157 if [ "$node_type" == "controller" ]; then
1159 horizon_ip=`vagrant ssh -c "ifconfig enp0s10" | grep -Eo "inet [0-9\.]+" | awk {'print $2'}`
1164 if [ -z "$horizon_ip" ]; then
1165 echo "${red}Warn: Unable to determine horizon IP, please login to your controller node to find it${reset}"
1167 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_ip} ${reset}"
1172 ##check to make sure nodes are powered off
1173 ##this function does nothing if virtual
1175 ##usage: check_baremetal_nodes()
1176 check_baremetal_nodes() {
1177 if [ $virtual ]; then
1178 echo "${blue}Skipping Baremetal node power status check as deployment is virtual ${reset}"
1180 echo "${blue}Checking Baremetal nodes power state... ${reset}"
1181 if [ ! -z "$base_config" ]; then
1183 # Major version is pinned to force some consistency for Arno
1184 if ! yum list installed | grep -i ipmitool; then
1185 echo "${blue}Installing ipmitool...${reset}"
1186 if ! yum -y install ipmitool-1*; then
1187 echo "${red}Failed to install ipmitool!${reset}"
1192 ###find all the bmc IPs and number of nodes
1194 output=`grep bmc_ip $base_config | grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+'`
1195 for line in ${output} ; do
1196 bmc_ip[$node_counter]=$line
1200 max_nodes=$((node_counter-1))
1202 ###find bmc_users per node
1204 output=`grep bmc_user $base_config | sed 's/\s*bmc_user:\s*//'`
1205 for line in ${output} ; do
1206 bmc_user[$node_counter]=$line
1210 ###find bmc_pass per node
1212 output=`grep bmc_pass $base_config | sed 's/\s*bmc_pass:\s*//'`
1213 for line in ${output} ; do
1214 bmc_pass[$node_counter]=$line
1218 for mynode in `seq 0 $max_nodes`; do
1219 echo "${blue}Node: ${bmc_ip[$mynode]} ${bmc_user[$mynode]} ${bmc_pass[$mynode]} ${reset}"
1220 ipmi_output=`ipmitool -I lanplus -P ${bmc_pass[$mynode]} -U ${bmc_user[$mynode]} -H ${bmc_ip[$mynode]} chassis status \
1221 | grep "System Power" | cut -d ':' -f2 | tr -d [:blank:]`
1222 if [ "$ipmi_output" == "on" ]; then
1223 echo "${red}Error: Node is powered on: ${bmc_ip[$mynode]} ${reset}"
1224 echo "${red}Please run clean.sh before running deploy! ${reset}"
1226 elif [ "$ipmi_output" == "off" ]; then
1227 echo "${blue}Node: ${bmc_ip[$mynode]} is powered off${reset}"
1229 echo "${red}Warning: Unable to detect node power state: ${bmc_ip[$mynode]} ${reset}"
1233 echo "${red}base_config was not provided for a baremetal install! Exiting${reset}"
1239 ##resizes vagrant disk (cannot shrink)
1240 ##params: size in GB
1241 ##usage: resize_vagrant_disk 100
1242 resize_vagrant_disk() {
1243 if [[ "$1" < 40 ]]; then
1244 echo "${blue}Warn: Requested disk size cannot be less than 40, using 40 as new size${reset}"
1250 if ! vagrant box list | grep opnfv; then
1251 vagrant box remove -f opnfv/centos-7.0
1252 if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
1253 echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
1258 pushd $vagrant_box_dir
1260 # Close medium to make sure we can modify it
1261 vboxmanage closemedium disk $vagrant_box_vmdk
1263 cur_size=$(vboxmanage showhdinfo $vagrant_box_vmdk | grep -i capacity | grep -Eo [0-9]+)
1264 cur_size_gb=$((cur_size / 1024))
1266 if [ "$cur_size_gb" -eq "$new_size_gb" ]; then
1267 echo "${blue}Info: Disk size already ${cur_size_gb} ${reset}"
1270 elif [[ "$new_size_gb" < "$cur_size_gb" ]] ; then
1271 echo "${blue}Info: Requested disk is less than ${cur_size_gb} ${reset}"
1272 echo "${blue}Re-adding vagrant box${reset}"
1273 if vagrant box list | grep opnfv; then
1275 vagrant box remove -f opnfv/centos-7.0
1276 if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
1277 echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
1280 pushd $vagrant_box_dir
1284 new_size=$((new_size_gb * 1024))
1285 if ! vboxmanage clonehd $vagrant_box_vmdk tmp-disk.vdi --format vdi; then
1286 echo "${red}Error: Unable to clone ${vagrant_box_vmdk}${reset}"
1291 if ! vboxmanage modifyhd tmp-disk.vdi --resize $new_size; then
1292 echo "${red}Error: Unable modify tmp-disk.vdi to ${new_size}${reset}"
1297 if ! vboxmanage clonehd tmp-disk.vdi resized-disk.vmdk --format vmdk; then
1298 echo "${red}Error: Unable clone tmp-disk.vdi to vmdk${reset}"
1303 vboxmanage closemedium disk tmp-disk.vdi --delete
1304 rm -f tmp-disk.vdi $vagrant_box_vmdk
1305 cp -f resized-disk.vmdk $vagrant_box_vmdk
1306 vboxmanage closemedium disk resized-disk.vmdk --delete
1315 check_baremetal_nodes
1322 clone_bgs $vm_dir/foreman_vm