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
35 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
36 echo -e "\n${green}Make sure you have the latest kernel installed before running this script! (yum update kernel +reboot)${reset}\n"
37 echo -e "\nUsage:\n$0 [arguments] \n"
38 echo -e "\n -no_parse : No variable parsing into config. Flag. \n"
39 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"
40 echo -e "\n -virtual : Node virtualization instead of baremetal. Flag. \n"
41 echo -e "\n -enable_virtual_dhcp : Run dhcp server instead of using static IPs. Use this with -virtual only. \n"
42 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"
43 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"
44 echo -e "\n -floating_ip_count : number of IP address from the public range to be used for floating IP. Default is 20.\n"
47 ##find ip of interface
48 ##params: interface name
50 ip addr show $1 | grep -Eo '^\s+inet\s+[\.0-9]+' | awk '{print $2}'
53 ##finds subnet of ip and netmask
55 function find_subnet {
56 IFS=. read -r i1 i2 i3 i4 <<< "$1"
57 IFS=. read -r m1 m2 m3 m4 <<< "$2"
58 printf "%d.%d.%d.%d\n" "$((i1 & m1))" "$((i2 & m2))" "$((i3 & m3))" "$((i4 & m4))"
61 ##finds last usable ip (broadcast minus 1) of a subnet from an IP and netmask
62 ## Warning: This function only works for IPv4 at the moment.
64 function find_last_ip_subnet {
65 IFS=. read -r i1 i2 i3 i4 <<< "$1"
66 IFS=. read -r m1 m2 m3 m4 <<< "$2"
67 IFS=. read -r s1 s2 s3 s4 <<< "$((i1 & m1)).$((i2 & m2)).$((i3 & m3)).$((i4 & m4))"
68 printf "%d.%d.%d.%d\n" "$((255 - $m1 + $s1))" "$((255 - $m2 + $s2))" "$((255 - $m3 + $s3))" "$((255 - $m4 + $s4 - 1))"
71 ##increments subnet by a value
74 function increment_subnet {
75 IFS=. read -r i1 i2 i3 i4 <<< "$1"
76 printf "%d.%d.%d.%d\n" "$i1" "$i2" "$i3" "$((i4 | $2))"
80 ##finds netmask of interface
82 ##returns long format 255.255.x.x
83 function find_netmask {
84 ifconfig $1 | grep -Eo 'netmask\s+[\.0-9]+' | awk '{print $2}'
87 ##finds short netmask of interface
89 ##returns short format, ex: /21
90 function find_short_netmask {
91 echo "/$(ip addr show $1 | grep -Eo '^\s+inet\s+[\/\.0-9]+' | awk '{print $2}' | cut -d / -f2)"
96 ##assumes a /24 subnet
98 baseaddr="$(echo $1 | cut -d. -f1-3)"
99 lsv="$(echo $1 | cut -d. -f4)"
100 if [ "$lsv" -ge 254 ]; then
107 ##removes the network interface config from Vagrantfile
109 ##assumes you are in the directory of Vagrantfile
110 function remove_vagrant_network {
111 sed -i 's/^.*'"$1"'.*$//' Vagrantfile
114 ##check if IP is in use
116 ##ping ip to get arp entry, then check arp
117 function is_ip_used {
118 ping -c 5 $1 > /dev/null 2>&1
119 arp -n | grep "$1 " | grep -iv incomplete > /dev/null 2>&1
122 ##find next usable IP
124 function next_usable_ip {
126 while [ "$new_ip" ]; do
127 if ! is_ip_used $new_ip; then
131 new_ip=$(next_ip $new_ip)
136 ##increment ip by value
137 ##params: ip, amount to increment by
138 ##increment_ip $next_private_ip 10
139 function increment_ip {
140 baseaddr="$(echo $1 | cut -d. -f1-3)"
141 lsv="$(echo $1 | cut -d. -f4)"
144 if [ "$lsv" -ge 254 ]; then
150 ##translates yaml into variables
151 ##params: filename, prefix (ex. "config_")
152 ##usage: parse_yaml opnfv_ksgen_settings.yml "config_"
155 local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
156 sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
157 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
159 indent = length($1)/2;
161 for (i in vname) {if (i > indent) {delete vname[i]}}
162 if (length($3) > 0) {
163 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
164 printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
169 ##translates the command line paramaters into variables
170 ##params: $@ the entire command line is passed
171 ##usage: parse_cmd_line() "$@"
173 if [[ ( $1 == "--help") || $1 == "-h" ]]; then
178 echo -e "\n\n${blue}This script is used to deploy Foreman/QuickStack Installer and Provision OPNFV Target System${reset}\n\n"
179 echo "Use -h to display help"
182 while [ "`echo $1 | cut -c1`" = "-" ]
198 -enable_virtual_dhcp)
199 enable_virtual_dhcp="TRUE"
221 if [ ! -z "$enable_virtual_dhcp" ] && [ ! -z "$static_ip_range" ]; then
222 echo -e "\n\n${red}ERROR: Incorrect Usage. Static IP range cannot be set when using DHCP!. Exiting${reset}\n\n"
226 if [ -z "$virtual" ]; then
227 if [ ! -z "$enable_virtual_dhcp" ]; then
228 echo -e "\n\n${red}ERROR: Incorrect Usage. enable_virtual_dhcp can only be set when using -virtual!. Exiting${reset}\n\n"
230 elif [ ! -z "$static_ip_range" ]; then
231 echo -e "\n\n${red}ERROR: Incorrect Usage. static_ip_range can only be set when using -virtual!. Exiting${reset}\n\n"
236 if [ -z "$floating_ip_count" ]; then
243 ##usage: disable_selinux()
248 ##Install the EPEL repository and additional packages
250 ##usage: install_EPEL()
252 # Install EPEL repo for access to many other yum repos
253 # Major version is pinned to force some consistency for Arno
254 yum install -y epel-release-7*
256 # Install other required packages
257 # Major versions are pinned to force some consistency for Arno
258 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
259 printf '%s\n' 'deploy.sh: Unable to install depdency packages' >&2
264 ##Download and install virtual box
266 ##usage: install_vbox()
268 ##install VirtualBox repo
269 if cat /etc/*release | grep -i "Fedora release"; then
270 vboxurl=http://download.virtualbox.org/virtualbox/rpm/fedora/\$releasever/\$basearch
272 vboxurl=http://download.virtualbox.org/virtualbox/rpm/el/\$releasever/\$basearch
275 cat > /etc/yum.repos.d/virtualbox.repo << EOM
277 name=Oracle Linux / RHEL / CentOS-\$releasever / \$basearch - VirtualBox
281 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
282 skip_if_unavailable = 1
287 if ! yum list installed | grep -i virtualbox; then
288 if ! yum -y install VirtualBox-4.3; then
289 printf '%s\n' 'deploy.sh: Unable to install virtualbox package' >&2
294 ##install kmod-VirtualBox
295 if ! lsmod | grep vboxdrv; then
296 sudo /etc/init.d/vboxdrv setup
297 if ! lsmod | grep vboxdrv; then
298 printf '%s\n' 'deploy.sh: Unable to install kernel module for virtualbox' >&2
302 printf '%s\n' 'deploy.sh: Skipping kernel module for virtualbox. Already Installed'
306 ##install Ansible using yum
308 ##usage: install_ansible()
310 if ! yum list installed | grep -i ansible; then
311 if ! yum -y install ansible-1*; then
312 printf '%s\n' 'deploy.sh: Unable to install Ansible package' >&2
318 ##install Vagrant RPM directly with the bintray.com site
320 ##usage: install_vagrant()
322 if ! rpm -qa | grep vagrant; then
323 if ! rpm -Uvh https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm; then
324 printf '%s\n' 'deploy.sh: Unable to install vagrant package' >&2
328 printf '%s\n' 'deploy.sh: Skipping Vagrant install as it is already installed.'
331 ##add centos 7 box to vagrant
332 if ! vagrant box list | grep chef/centos-7.0; then
333 if ! vagrant box add chef/centos-7.0 --provider virtualbox; then
334 printf '%s\n' 'deploy.sh: Unable to download centos7 box for Vagrant' >&2
338 printf '%s\n' 'deploy.sh: Skipping Vagrant box add as centos-7.0 is already installed.'
341 ##install workaround for centos7
342 if ! vagrant plugin list | grep vagrant-centos7_fix; then
343 if ! vagrant plugin install vagrant-centos7_fix; then
344 printf '%s\n' 'deploy.sh: Warning: unable to install vagrant centos7 workaround' >&2
347 printf '%s\n' 'deploy.sh: Skipping Vagrant plugin as centos7 workaround is already installed.'
352 ##remove bgs vagrant incase it wasn't cleaned up
356 rm -rf /tmp/bgs_vagrant
359 ##clone bgs vagrant version 1.0 using git
365 ##will change this to be opnfv repo when commit is done
366 if ! git clone -b v1.0 https://github.com/trozet/bgs_vagrant.git; then
367 printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
372 ##validates the network settings and update VagrantFile with network settings
374 ##usage: configure_network()
375 configure_network() {
378 echo "${blue}Detecting network configuration...${reset}"
379 ##detect host 1 or 3 interface configuration
380 #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
381 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
383 if [ ! "$output" ]; then
384 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
388 ##virtual we only find 1 interface
389 if [ $virtual ]; then
390 ##find interface with default gateway
391 this_default_gw=$(ip route | grep default | awk '{print $3}')
392 echo "${blue}Default Gateway: $this_default_gw ${reset}"
393 this_default_gw_interface=$(ip route get $this_default_gw | awk '{print $3}')
395 ##find interface IP, make sure its valid
396 interface_ip=$(find_ip $this_default_gw_interface)
397 if [ ! "$interface_ip" ]; then
398 echo "${red}Interface ${this_default_gw_interface} does not have an IP: $interface_ip ! Exiting ${reset}"
403 if [ ! -z "$static_ip_range" ]; then
404 new_ip=$(echo $static_ip_range | cut -d , -f1)
406 new_ip=$(next_usable_ip $interface_ip)
407 if [ ! "$new_ip" ]; then
408 echo "${red} Cannot find next IP on interface ${this_default_gw_interface} new_ip: $new_ip ! Exiting ${reset}"
412 interface=$this_default_gw_interface
413 public_interface=$interface
414 interface_arr[$interface]=2
415 interface_ip_arr[2]=$new_ip
416 subnet_mask=$(find_netmask $interface)
417 public_subnet_mask=$subnet_mask
418 public_short_subnet_mask=$(find_short_netmask $interface)
420 ##set that interface to be public
421 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
424 ##find number of interfaces with ip and substitute in VagrantFile
426 for interface in ${output}; do
428 if [ "$if_counter" -ge 4 ]; then
431 interface_ip=$(find_ip $interface)
432 if [ ! "$interface_ip" ]; then
435 new_ip=$(next_usable_ip $interface_ip)
436 if [ ! "$new_ip" ]; then
439 interface_arr[$interface]=$if_counter
440 interface_ip_arr[$if_counter]=$new_ip
441 subnet_mask=$(find_netmask $interface)
442 if [ "$if_counter" -eq 0 ]; then
443 admin_subnet_mask=$subnet_mask
444 elif [ "$if_counter" -eq 1 ]; then
445 private_subnet_mask=$subnet_mask
446 private_short_subnet_mask=$(find_short_netmask $interface)
447 elif [ "$if_counter" -eq 2 ]; then
448 public_subnet_mask=$subnet_mask
449 public_short_subnet_mask=$(find_short_netmask $interface)
450 elif [ "$if_counter" -eq 3 ]; then
451 storage_subnet_mask=$subnet_mask
453 echo "${red}ERROR: interface counter outside valid range of 0 to 3: $if_counter ! ${reset}"
456 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "public_network", ip: '\""$new_ip"\"', bridge: '\'"$interface"\'', netmask: '\""$subnet_mask"\"'/' Vagrantfile
460 ##now remove interface config in Vagrantfile for 1 node
461 ##if 1, 3, or 4 interfaces set deployment type
462 ##if 2 interfaces remove 2nd interface and set deployment type
463 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
464 if [ $virtual ]; then
465 deployment_type="single_network"
466 echo "${blue}Single network detected for Virtual deployment...converting to three_network with internal networks! ${reset}"
467 private_internal_ip=155.1.2.2
468 admin_internal_ip=156.1.2.2
469 private_subnet_mask=255.255.255.0
470 private_short_subnet_mask=/24
471 interface_ip_arr[1]=$private_internal_ip
472 interface_ip_arr[0]=$admin_internal_ip
473 admin_subnet_mask=255.255.255.0
474 admin_short_subnet_mask=/24
475 sed -i 's/^.*eth_replace1.*$/ config.vm.network "private_network", virtualbox__intnet: "my_private_network", ip: '\""$private_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
476 sed -i 's/^.*eth_replace0.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$admin_internal_ip"\"', netmask: '\""$private_subnet_mask"\"'/' Vagrantfile
477 remove_vagrant_network eth_replace3
478 deployment_type=three_network
480 echo "${blue}Single network or 2 network detected for baremetal deployment. This is unsupported! Exiting. ${reset}"
483 elif [ "$if_counter" == 3 ]; then
484 deployment_type="three_network"
485 remove_vagrant_network eth_replace3
487 deployment_type="multi_network"
490 echo "${blue}Network detected: ${deployment_type}! ${reset}"
492 if [ $virtual ]; then
493 if [ -z "$enable_virtual_dhcp" ]; then
494 sed -i 's/^.*disable_dhcp_flag =.*$/ disable_dhcp_flag = true/' Vagrantfile
495 if [ $static_ip_range ]; then
496 ##verify static range is at least 20 IPs
497 static_ip_range_begin=$(echo $static_ip_range | cut -d , -f1)
498 static_ip_range_end=$(echo $static_ip_range | cut -d , -f2)
499 ##verify range is at least 20 ips
500 ##assumes less than 255 range pool
501 begin_octet=$(echo $static_ip_range_begin | cut -d . -f4)
502 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
503 ip_count=$((end_octet-begin_octet+1))
504 if [ "$ip_count" -lt 20 ]; then
505 echo "${red}Static range is less than 20 ips: ${ip_count}, exiting ${reset}"
508 echo "${blue}Static IP range is size $ip_count ${reset}"
514 if route | grep default; then
515 echo "${blue}Default Gateway Detected ${reset}"
516 host_default_gw=$(ip route | grep default | awk '{print $3}')
517 echo "${blue}Default Gateway: $host_default_gw ${reset}"
518 default_gw_interface=$(ip route get $host_default_gw | awk '{print $3}')
519 case "${interface_arr[$default_gw_interface]}" in
521 echo "${blue}Default Gateway Detected on Admin Interface!${reset}"
522 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
523 node_default_gw=$host_default_gw
526 echo "${red}Default Gateway Detected on Private Interface!${reset}"
527 echo "${red}Private subnet should be private and not have Internet access!${reset}"
531 echo "${blue}Default Gateway Detected on Public Interface!${reset}"
532 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$host_default_gw"\"'/' Vagrantfile
533 echo "${blue}Will setup NAT from Admin -> Public Network on VM!${reset}"
534 sed -i 's/^.*nat_flag =.*$/ nat_flag = true/' Vagrantfile
535 echo "${blue}Setting node gateway to be VM Admin IP${reset}"
536 node_default_gw=${interface_ip_arr[0]}
537 public_gateway=$default_gw
540 echo "${red}Default Gateway Detected on Storage Interface!${reset}"
541 echo "${red}Storage subnet should be private and not have Internet access!${reset}"
545 echo "${red}Unable to determine which interface default gateway is on..Exiting!${reset}"
551 defaultgw=`echo ${interface_ip_arr[0]} | cut -d. -f1-3`
553 defaultgw=$defaultgw$firstip
554 echo "${blue}Unable to find default gateway. Assuming it is $defaultgw ${reset}"
555 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$defaultgw"\"'/' Vagrantfile
556 node_default_gw=$defaultgw
559 if [ $base_config ]; then
560 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
561 echo "{red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
566 if [ $no_parse ]; then
567 echo "${blue}Skipping parsing variables into settings file as no_parse flag is set${reset}"
571 echo "${blue}Gathering network parameters for Target System...this may take a few minutes${reset}"
572 ##Edit the ksgen settings appropriately
573 ##ksgen settings will be stored in /vagrant on the vagrant machine
574 ##if single node deployment all the variables will have the same ip
575 ##interface names will be enp0s3, enp0s8, enp0s9 in chef/centos7
577 sed -i 's/^.*default_gw:.*$/default_gw:'" $node_default_gw"'/' opnfv_ksgen_settings.yml
579 ##replace private interface parameter
580 ##private interface will be of hosts, so we need to know the provisioned host interface name
581 ##we add biosdevname=0, net.ifnames=0 to the kickstart to use regular interface naming convention on hosts
582 ##replace IP for parameters with next IP that will be given to controller
583 if [ "$deployment_type" == "single_network" ]; then
584 ##we also need to assign IP addresses to nodes
585 ##for single node, foreman is managing the single network, so we can't reserve them
586 ##not supporting single network anymore for now
587 echo "{blue}Single Network type is unsupported right now. Please check your interface configuration. Exiting. ${reset}"
590 elif [[ "$deployment_type" == "multi_network" || "$deployment_type" == "three_network" ]]; then
592 if [ "$deployment_type" == "three_network" ]; then
593 sed -i 's/^.*network_type:.*$/network_type: three_network/' opnfv_ksgen_settings.yml
596 sed -i 's/^.*deployment_type:.*$/ deployment_type: '"$deployment_type"'/' opnfv_ksgen_settings.yml
598 ##get ip addresses for private network on controllers to make dhcp entries
599 ##required for controllers_ip_array global param
600 next_private_ip=${interface_ip_arr[1]}
603 for node in controller1 controller2 controller3; do
604 next_private_ip=$(next_usable_ip $next_private_ip)
605 if [ ! "$next_private_ip" ]; then
606 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for control nodes' >&2
609 sed -i 's/'"$node$type"'/'"$next_private_ip"'/g' opnfv_ksgen_settings.yml
610 controller_ip_array=$controller_ip_array$next_private_ip,
611 controllers_ip_arr[$control_count]=$next_private_ip
615 next_public_ip=${interface_ip_arr[2]}
616 foreman_ip=$next_public_ip
618 ##if no dhcp, find all the Admin IPs for nodes in advance
619 if [ $virtual ]; then
620 if [ -z "$enable_virtual_dhcp" ]; then
621 sed -i 's/^.*no_dhcp:.*$/no_dhcp: true/' opnfv_ksgen_settings.yml
622 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'`
623 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
624 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
625 nodes=${controller_nodes}${compute_nodes}
626 next_admin_ip=${interface_ip_arr[0]}
628 for node in ${nodes}; do
629 next_admin_ip=$(next_ip $next_admin_ip)
630 if [ ! "$next_admin_ip" ]; then
631 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
634 admin_ip_arr[$node]=$next_admin_ip
635 sed -i 's/'"$node$type"'/'"$next_admin_ip"'/g' opnfv_ksgen_settings.yml
639 ##allocate node public IPs
640 for node in ${nodes}; do
641 next_public_ip=$(next_usable_ip $next_public_ip)
642 if [ ! "$next_public_ip" ]; then
643 echo "${red} Unable to find an unused IP in admin_network for $node ! ${reset}"
646 public_ip_arr[$node]=$next_public_ip
651 ##replace global param for controllers_ip_array
652 controller_ip_array=${controller_ip_array%?}
653 sed -i 's/^.*controllers_ip_array:.*$/ controllers_ip_array: '"$controller_ip_array"'/' opnfv_ksgen_settings.yml
655 ##now replace all the VIP variables. admin//private can be the same IP
656 ##we have to use IP's here that won't be allocated to hosts at provisioning time
657 ##therefore we increment the ip by 10 to make sure we have a safe buffer
658 next_private_ip=$(increment_ip $next_private_ip 10)
660 private_output=$(grep -E '*private_vip|loadbalancer_vip|db_vip|amqp_vip|*admin_vip' opnfv_ksgen_settings.yml)
661 if [ ! -z "$private_output" ]; then
662 while read -r line; do
663 sed -i 's/^.*'"$line"'.*$/ '"$line $next_private_ip"'/' opnfv_ksgen_settings.yml
664 next_private_ip=$(next_usable_ip $next_private_ip)
665 if [ ! "$next_private_ip" ]; then
666 printf '%s\n' 'deploy.sh: Unable to find next ip for private network for vip replacement' >&2
669 done <<< "$private_output"
672 ##replace odl_control_ip (non-HA only)
673 odl_control_ip=${controllers_ip_arr[0]}
674 sed -i 's/^.*odl_control_ip:.*$/ odl_control_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
676 ##replace controller_ip (non-HA only)
677 sed -i 's/^.*controller_ip:.*$/ controller_ip: '"$odl_control_ip"'/' opnfv_ksgen_settings.yml
679 ##replace foreman site
680 sed -i 's/^.*foreman_url:.*$/ foreman_url:'" https:\/\/$foreman_ip"'\/api\/v2\//' opnfv_ksgen_settings.yml
681 ##replace public vips
682 ##no need to do this if virtual and no dhcp
683 if [ ! -z "$enable_virtual_dhcp" ]; then
684 next_public_ip=$(increment_ip $next_public_ip 10)
686 next_public_ip=$(next_usable_ip $next_public_ip)
689 public_output=$(grep -E '*public_vip' opnfv_ksgen_settings.yml)
690 if [ ! -z "$public_output" ]; then
691 while read -r line; do
692 if echo $line | grep horizon_public_vip; then
693 horizon_public_vip=$next_public_ip
695 sed -i 's/^.*'"$line"'.*$/ '"$line $next_public_ip"'/' opnfv_ksgen_settings.yml
696 next_public_ip=$(next_usable_ip $next_public_ip)
697 if [ ! "$next_public_ip" ]; then
698 printf '%s\n' 'deploy.sh: Unable to find next ip for public network for vip replcement' >&2
701 done <<< "$public_output"
704 ##replace public_network param
705 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
706 sed -i 's/^.*public_network:.*$/ public_network:'" $public_subnet"'/' opnfv_ksgen_settings.yml
707 ##replace private_network param
708 private_subnet=$(find_subnet $next_private_ip $private_subnet_mask)
709 sed -i 's/^.*private_network:.*$/ private_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
710 ##replace storage_network
711 if [ "$deployment_type" == "three_network" ]; then
712 sed -i 's/^.*storage_network:.*$/ storage_network:'" $private_subnet"'/' opnfv_ksgen_settings.yml
714 next_storage_ip=${interface_ip_arr[3]}
715 storage_subnet=$(find_subnet $next_storage_ip $storage_subnet_mask)
716 sed -i 's/^.*storage_network:.*$/ storage_network:'" $storage_subnet"'/' opnfv_ksgen_settings.yml
719 ##replace public_subnet param
720 public_subnet=$public_subnet'\'$public_short_subnet_mask
721 sed -i 's/^.*public_subnet:.*$/ public_subnet:'" $public_subnet"'/' opnfv_ksgen_settings.yml
722 ##replace private_subnet param
723 private_subnet=$private_subnet'\'$private_short_subnet_mask
724 sed -i 's/^.*private_subnet:.*$/ private_subnet:'" $private_subnet"'/' opnfv_ksgen_settings.yml
726 ##replace public_dns param to be foreman server
727 sed -i 's/^.*public_dns:.*$/ public_dns: '${interface_ip_arr[2]}'/' opnfv_ksgen_settings.yml
729 ##replace public_gateway
730 if [ -z "$public_gateway" ]; then
731 ##if unset then we assume its the first IP in the public subnet
732 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
733 public_gateway=$(increment_subnet $public_subnet 1)
735 sed -i 's/^.*public_gateway:.*$/ public_gateway:'" $public_gateway"'/' opnfv_ksgen_settings.yml
737 ##we have to define an allocation range of the public subnet to give
738 ##to neutron to use as floating IPs
739 ##if static ip range, then we take the difference of the end range and current ip
740 ## to be the allocation pool
741 ##if not static ip, we will use the last 20 IP from the subnet
742 ## note that this is not a really good idea because the subnet must be at least a /27 for this to work...
743 public_subnet=$(find_subnet $next_public_ip $public_subnet_mask)
744 if [ ! -z "$static_ip_range" ]; then
745 begin_octet=$(echo $next_public_ip | cut -d . -f4)
746 end_octet=$(echo $static_ip_range_end | cut -d . -f4)
747 ip_diff=$((end_octet-begin_octet))
748 if [ $ip_diff -le 0 ]; then
749 echo "${red}ip range left for floating range is less than or equal to 0! $ipdiff ${reset}"
752 public_allocation_start=$(next_ip $next_public_ip)
753 public_allocation_end=$static_ip_range_end
754 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
757 last_ip_subnet=$(find_last_ip_subnet $next_public_ip $public_subnet_mask)
758 public_allocation_start=$(increment_subnet $public_subnet $(( $last_ip_subnet - $floating_ip_count )) )
759 public_allocation_end=$(increment_subnet $public_subnet $(( $last_ip_subnet )) )
760 echo "${blue}Neutron Floating IP range: $public_allocation_start to $public_allocation_end ${reset}"
761 echo "${blue}Foreman VM is up! ${reset}"
764 sed -i 's/^.*public_allocation_start:.*$/ public_allocation_start:'" $public_allocation_start"'/' opnfv_ksgen_settings.yml
765 sed -i 's/^.*public_allocation_end:.*$/ public_allocation_end:'" $public_allocation_end"'/' opnfv_ksgen_settings.yml
768 printf '%s\n' 'deploy.sh: Unknown network type: $deployment_type' >&2
772 echo "${blue}Parameters Complete. Settings have been set for Foreman. ${reset}"
777 ##Configure bootstrap.sh to use the virtual Khaleesi playbook
779 ##usage: configure_virtual()
780 configure_virtual() {
781 if [ $virtual ]; then
782 echo "${blue} Virtual flag detected, setting Khaleesi playbook to be opnfv-vm.yml ${reset}"
783 sed -i 's/opnfv.yml/opnfv-vm.yml/' bootstrap.sh
787 ##Starts Foreman VM with Vagrant
789 ##usage: start_vagrant()
791 echo "${blue}Starting Vagrant! ${reset}"
794 if ! vagrant up; then
795 printf '%s\n' 'deploy.sh: Unable to start vagrant' >&2
798 echo "${blue}Foreman VM is up! ${reset}"
802 ##start the VM if this is a virtual installation
803 ##this function does nothing if baremetal servers are being used
805 ##usage: start_virtual_nodes()
806 start_virtual_nodes() {
807 if [ $virtual ]; then
810 echo "${blue}Setting VMs up... ${reset}"
811 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'`
812 ##due to ODL Helium bug of OVS connecting to ODL too early, we need controllers to install first
813 ##this is fix kind of assumes more than I would like to, but for now it should be OK as we always have
814 ##3 static controllers
815 compute_nodes=`echo $nodes | tr " " "\n" | grep -v controller | tr "\n" " "`
816 controller_nodes=`echo $nodes | tr " " "\n" | grep controller | tr "\n" " "`
817 nodes=${controller_nodes}${compute_nodes}
819 compute_wait_completed=false
821 for node in ${nodes}; do
824 ##remove VM nodes incase it wasn't cleaned up
828 ##will change this to be opnfv repo when commit is done
829 if ! git clone https://github.com/trozet/bgs_vagrant.git $node; then
830 printf '%s\n' 'deploy.sh: Unable to clone vagrant repo' >&2
836 if [ $base_config ]; then
837 if ! cp -f $base_config opnfv_ksgen_settings.yml; then
838 echo "${red}ERROR: Unable to copy $base_config to opnfv_ksgen_settings.yml${reset}"
843 ##parse yaml into variables
844 eval $(parse_yaml opnfv_ksgen_settings.yml "config_")
846 node_type=config_nodes_${node}_type
847 node_type=$(eval echo \$$node_type)
849 ##trozet test make compute nodes wait 20 minutes
850 if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
851 echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
852 compute_wait_completed=true
856 ##find number of interfaces with ip and substitute in VagrantFile
857 output=`ifconfig | grep -E "^[a-zA-Z0-9]+:"| grep -Ev "lo|tun|virbr|vboxnet" | awk '{print $1}' | sed 's/://'`
859 if [ ! "$output" ]; then
860 printf '%s\n' 'deploy.sh: Unable to detect interfaces to bridge to' >&2
865 for interface in ${output}; do
867 if [ -z "$enable_virtual_dhcp" ]; then
868 if [ "$if_counter" -ge 1 ]; then
871 elif [ "$if_counter" -ge 4 ]; then
874 interface_ip=$(find_ip $interface)
875 if [ ! "$interface_ip" ]; then
878 case "${if_counter}" in
880 mac_string=config_nodes_${node}_mac_address
881 mac_addr=$(eval echo \$$mac_string)
882 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
883 if [ $mac_addr == "" ]; then
884 echo "${red} Unable to find mac_address for $node! ${reset}"
889 if [ "$node_type" == "controller" ]; then
890 mac_string=config_nodes_${node}_private_mac
891 mac_addr=$(eval echo \$$mac_string)
892 if [ $mac_addr == "" ]; then
893 echo "${red} Unable to find private_mac for $node! ${reset}"
897 ##generate random mac
898 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
900 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
903 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
904 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
907 this_admin_ip=${admin_ip_arr[$node]}
908 sed -i 's/^.*eth_replace'"$if_counter"'.*$/ config.vm.network "private_network", virtualbox__intnet: "my_admin_network", ip: '\""$this_admin_ip"\"', netmask: '\""$admin_subnet_mask"\"', :mac => '\""$mac_addr"\"'/' Vagrantfile
911 ##now remove interface config in Vagrantfile for 1 node
912 ##if 1, 3, or 4 interfaces set deployment type
913 ##if 2 interfaces remove 2nd interface and set deployment type
914 if [[ "$if_counter" == 1 || "$if_counter" == 2 ]]; then
915 deployment_type="single_network"
916 if [ "$node_type" == "controller" ]; then
917 mac_string=config_nodes_${node}_private_mac
918 mac_addr=$(eval echo \$$mac_string)
919 if [ $mac_addr == "" ]; then
920 echo "${red} Unable to find private_mac for $node! ${reset}"
924 ##generate random mac
925 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
927 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
928 if [ "$node_type" == "controller" ]; then
929 new_node_ip=${controllers_ip_arr[$controller_count]}
930 if [ ! "$new_node_ip" ]; then
931 echo "{red}ERROR: Empty node ip for controller $controller_count ${reset}"
934 ((controller_count++))
936 next_private_ip=$(next_ip $next_private_ip)
937 if [ ! "$next_private_ip" ]; then
938 echo "{red}ERROR: Could not find private ip for $node ${reset}"
941 new_node_ip=$next_private_ip
943 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
944 ##replace host_ip in vm_nodes_provision with private ip
945 sed -i 's/^host_ip=REPLACE/host_ip='$new_node_ip'/' vm_nodes_provision.sh
947 if [ ! -z "$ping_site" ]; then
948 sed -i 's/www.google.com/'$ping_site'/' vm_nodes_provision.sh
950 ##find public ip info
951 mac_addr=$(echo -n 00-60-2F; dd bs=1 count=3 if=/dev/random 2>/dev/null |hexdump -v -e '/1 "-%02X"')
952 mac_addr=$(echo $mac_addr | sed 's/:\|-//g')
953 this_public_ip=${public_ip_arr[$node]}
955 if [ -z "$enable_virtual_dhcp" ]; then
956 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
958 sed -i 's/^.*eth_replace2.*$/ config.vm.network "public_network", bridge: '\'"$public_interface"\'', :mac => '\""$mac_addr"\"'/' Vagrantfile
960 remove_vagrant_network eth_replace3
961 elif [ "$if_counter" == 3 ]; then
962 deployment_type="three_network"
963 remove_vagrant_network eth_replace3
965 deployment_type="multi_network"
967 ##modify provisioning to do puppet install, config, and foreman check-in
968 ##substitute host_name and dns_server in the provisioning script
969 host_string=config_nodes_${node}_hostname
970 host_name=$(eval echo \$$host_string)
971 sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
972 ##dns server should be the foreman server
973 sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
974 ## remove bootstrap and NAT provisioning
975 sed -i '/nat_setup.sh/d' Vagrantfile
976 sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
977 ## modify default_gw to be node_default_gw
978 sed -i 's/^.*default_gw =.*$/ default_gw = '\""$node_default_gw"\"'/' Vagrantfile
979 ## modify VM memory to be 4gig
980 ##if node type is controller
981 if [ "$node_type" == "controller" ]; then
982 sed -i 's/^.*vb.memory =.*$/ vb.memory = 4096/' Vagrantfile
984 echo "${blue}Starting Vagrant Node $node! ${reset}"
986 if ! vagrant up; then
987 echo "${red} Unable to start $node ${reset}"
990 echo "${blue} $node VM is up! ${reset}"
993 echo "${blue} All VMs are UP! ${reset}"
994 echo "${blue} Waiting for puppet to complete on the nodes... ${reset}"
995 ##check puppet is complete
996 ##ssh into foreman server, run check to verify puppet is complete
997 pushd /tmp/bgs_vagrant
998 if ! vagrant ssh -c "/opt/khaleesi/run.sh --no-logs --use /vagrant/opnfv_ksgen_settings.yml /opt/khaleesi/playbooks/validate_opnfv-vm.yml"; then
999 echo "${red} Failed to validate puppet completion on nodes ${reset}"
1002 echo "{$blue} Puppet complete on all nodes! ${reset}"
1005 ##add routes back to nodes
1006 for node in ${nodes}; do
1008 if ! vagrant ssh -c "route | grep default | grep $this_default_gw"; then
1009 echo "${blue} Adding public route back to $node! ${reset}"
1010 vagrant ssh -c "route add default gw $this_default_gw"
1014 if [ ! -z "$horizon_public_vip" ]; then
1015 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${horizon_public_vip} ${reset}"
1017 echo "${blue} Virtual deployment SUCCESS!! Foreman URL: http://${foreman_ip}, Horizon URL: http://${odl_control_ip} ${reset}"