d996b92ad09d478dea1d0e5a4ba5dd2179b1f539
[apex.git] / ci / deploy.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Tim Rozet (Red Hat), Dan Radez (Red Hat) and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # Deploy script to install provisioning server for OPNFV Apex
12 # author: Dan Radez (dradez@redhat.com)
13 # author: Tim Rozet (trozet@redhat.com)
14 #
15 # Based on RDO Manager http://www.rdoproject.org
16
17 set -e
18
19 ##VARIABLES
20 reset=$(tput sgr0 || echo "")
21 blue=$(tput setaf 4 || echo "")
22 red=$(tput setaf 1 || echo "")
23 green=$(tput setaf 2 || echo "")
24
25 interactive="FALSE"
26 ping_site="8.8.8.8"
27 ntp_server="pool.ntp.org"
28 net_isolation_enabled="TRUE"
29 post_config="TRUE"
30 debug="FALSE"
31
32 declare -i CNT
33 declare UNDERCLOUD
34 declare -A deploy_options_array
35 declare -a performance_options
36 declare -A NET_MAP
37
38 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
39 DEPLOY_OPTIONS=""
40 CONFIG=${CONFIG:-'/var/opt/opnfv'}
41 RESOURCES=${RESOURCES:-"$CONFIG/images"}
42 LIB=${LIB:-"$CONFIG/lib"}
43 OPNFV_NETWORK_TYPES="admin_network private_network public_network storage_network api_network"
44
45 VM_CPUS=4
46 VM_RAM=8
47 VM_COMPUTES=2
48
49 # Netmap used to map networks to OVS bridge names
50 NET_MAP['admin_network']="br-admin"
51 NET_MAP['private_network']="br-private"
52 NET_MAP['public_network']="br-public"
53 NET_MAP['storage_network']="br-storage"
54 NET_MAP['api_network']="br-api"
55 ext_net_type="interface"
56 ip_address_family=4
57
58 # Libraries
59 lib_files=(
60 $LIB/common-functions.sh
61 $LIB/configure-deps-functions.sh
62 $LIB/parse-functions.sh
63 $LIB/utility-functions.sh
64 $LIB/installer/onos/onos_gw_mac_update.sh
65 )
66 for lib_file in ${lib_files[@]}; do
67   if ! source $lib_file; then
68     echo -e "${red}ERROR: Failed to source $lib_file${reset}"
69     exit 1
70   fi
71 done
72
73 ##FUNCTIONS
74 ##checks if prefix exists in string
75 ##params: string, prefix
76 ##usage: contains_prefix "deploy_setting_launcher=1" "deploy_setting"
77 contains_prefix() {
78   local mystr=$1
79   local prefix=$2
80   if echo $mystr | grep -E "^$prefix.*$" > /dev/null; then
81     return 0
82   else
83     return 1
84   fi
85 }
86
87 ##verify internet connectivity
88 #params: none
89 function verify_internet {
90   if ping -c 2 $ping_site > /dev/null; then
91     if ping -c 2 www.google.com > /dev/null; then
92       echo "${blue}Internet connectivity detected${reset}"
93       return 0
94     else
95       echo "${red}Internet connectivity detected, but DNS lookup failed${reset}"
96       return 1
97     fi
98   else
99     echo "${red}No internet connectivity detected${reset}"
100     return 1
101   fi
102 }
103
104 ##verify vm exists, an has a dhcp lease assigned to it
105 ##params: none
106 function setup_undercloud_vm {
107   if ! virsh list --all | grep undercloud > /dev/null; then
108       undercloud_nets="default admin_network"
109       if [[ $enabled_network_list =~ "public_network" ]]; then
110         undercloud_nets+=" public_network"
111       fi
112       define_vm undercloud hd 30 "$undercloud_nets" 4 12288
113
114       ### this doesn't work for some reason I was getting hangup events so using cp instead
115       #virsh vol-upload --pool default --vol undercloud.qcow2 --file $CONFIG/stack/undercloud.qcow2
116       #2015-12-05 12:57:20.569+0000: 8755: info : libvirt version: 1.2.8, package: 16.el7_1.5 (CentOS BuildSystem <http://bugs.centos.org>, 2015-11-03-13:56:46, worker1.bsys.centos.org)
117       #2015-12-05 12:57:20.569+0000: 8755: warning : virKeepAliveTimerInternal:143 : No response from client 0x7ff1e231e630 after 6 keepalive messages in 35 seconds
118       #2015-12-05 12:57:20.569+0000: 8756: warning : virKeepAliveTimerInternal:143 : No response from client 0x7ff1e231e630 after 6 keepalive messages in 35 seconds
119       #error: cannot close volume undercloud.qcow2
120       #error: internal error: received hangup / error event on socket
121       #error: Reconnected to the hypervisor
122
123       local undercloud_dst=/var/lib/libvirt/images/undercloud.qcow2
124       cp -f $RESOURCES/undercloud.qcow2 $undercloud_dst
125
126       # resize Undercloud machine
127       echo "Checking if Undercloud needs to be resized..."
128       undercloud_size=$(LIBGUESTFS_BACKEND=direct virt-filesystems --long -h --all -a $undercloud_dst |grep device | grep -Eo "[0-9\.]+G" | sed -n 's/\([0-9][0-9]*\).*/\1/p')
129       if [ "$undercloud_size" -lt 30 ]; then
130         qemu-img resize /var/lib/libvirt/images/undercloud.qcow2 +25G
131         LIBGUESTFS_BACKEND=direct virt-resize --expand /dev/sda1 $RESOURCES/undercloud.qcow2 $undercloud_dst
132         LIBGUESTFS_BACKEND=direct virt-customize -a $undercloud_dst --run-command 'xfs_growfs -d /dev/sda1 || true'
133         new_size=$(LIBGUESTFS_BACKEND=direct virt-filesystems --long -h --all -a $undercloud_dst |grep filesystem | grep -Eo "[0-9\.]+G" | sed -n 's/\([0-9][0-9]*\).*/\1/p')
134         if [ "$new_size" -lt 30 ]; then
135           echo "Error resizing Undercloud machine, disk size is ${new_size}"
136           exit 1
137         else
138           echo "Undercloud successfully resized"
139         fi
140       else
141         echo "Skipped Undercloud resize, upstream is large enough"
142       fi
143
144   else
145       echo "Found Undercloud VM, using existing VM"
146   fi
147
148   # if the VM is not running update the authkeys and start it
149   if ! virsh list | grep undercloud > /dev/null; then
150     echo "Injecting ssh key to Undercloud VM"
151     LIBGUESTFS_BACKEND=direct virt-customize -a $undercloud_dst --run-command "mkdir -p /root/.ssh/" \
152         --upload ~/.ssh/id_rsa.pub:/root/.ssh/authorized_keys \
153         --run-command "chmod 600 /root/.ssh/authorized_keys && restorecon /root/.ssh/authorized_keys" \
154         --run-command "cp /root/.ssh/authorized_keys /home/stack/.ssh/" \
155         --run-command "chown stack:stack /home/stack/.ssh/authorized_keys && chmod 600 /home/stack/.ssh/authorized_keys"
156     virsh start undercloud
157   fi
158
159   sleep 10 # let undercloud get started up
160
161   # get the undercloud VM IP
162   CNT=10
163   echo -n "${blue}Waiting for Undercloud's dhcp address${reset}"
164   undercloud_mac=$(virsh domiflist undercloud | grep default | awk '{ print $5 }')
165   while ! $(arp -e | grep ${undercloud_mac} > /dev/null) && [ $CNT -gt 0 ]; do
166       echo -n "."
167       sleep 10
168       CNT=$((CNT-1))
169   done
170   UNDERCLOUD=$(arp -e | grep ${undercloud_mac} | awk {'print $1'})
171
172   if [ -z "$UNDERCLOUD" ]; then
173     echo "\n\nCan't get IP for Undercloud. Can Not Continue."
174     exit 1
175   else
176      echo -e "${blue}\rUndercloud VM has IP $UNDERCLOUD${reset}"
177   fi
178
179   CNT=10
180   echo -en "${blue}\rValidating Undercloud VM connectivity${reset}"
181   while ! ping -c 1 $UNDERCLOUD > /dev/null && [ $CNT -gt 0 ]; do
182       echo -n "."
183       sleep 3
184       CNT=$((CNT-1))
185   done
186   if [ "$CNT" -eq 0 ]; then
187       echo "Failed to contact Undercloud. Can Not Continue"
188       exit 1
189   fi
190   CNT=10
191   while ! ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "echo ''" 2>&1> /dev/null && [ $CNT -gt 0 ]; do
192       echo -n "."
193       sleep 3
194       CNT=$((CNT-1))
195   done
196   if [ "$CNT" -eq 0 ]; then
197       echo "Failed to connect to Undercloud. Can Not Continue"
198       exit 1
199   fi
200
201   # extra space to overwrite the previous connectivity output
202   echo -e "${blue}\r                                                                 ${reset}"
203   sleep 1
204
205   # ssh key fix for stack user
206   ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "restorecon -r /home/stack"
207 }
208
209 ##Create virtual nodes in virsh
210 ##params: vcpus, ramsize
211 function setup_virtual_baremetal {
212   local vcpus ramsize
213   if [ -z "$1" ]; then
214     vcpus=4
215     ramsize=8192
216   elif [ -z "$2" ]; then
217     vcpus=$1
218     ramsize=8192
219   else
220     vcpus=$1
221     ramsize=$(($2*1024))
222   fi
223   #start by generating the opening json for instackenv.json
224   cat > $CONFIG/instackenv-virt.json << EOF
225 {
226   "nodes": [
227 EOF
228
229   # next create the virtual machines and add their definitions to the file
230   if [ "$ha_enabled" == "False" ]; then
231       # 1 controller + computes
232       # zero based so just pass compute count
233       vm_index=$VM_COMPUTES
234   else
235       # 3 controller + computes
236       # zero based so add 2 to compute count
237       vm_index=$((2+$VM_COMPUTES))
238   fi
239
240   for i in $(seq 0 $vm_index); do
241     if ! virsh list --all | grep baremetal${i} > /dev/null; then
242       define_vm baremetal${i} network 41 'admin_network' $vcpus $ramsize
243       for n in private_network public_network storage_network api_network; do
244         if [[ $enabled_network_list =~ $n ]]; then
245           echo -n "$n "
246           virsh attach-interface --domain baremetal${i} --type network --source $n --model virtio --config
247         fi
248       done
249     else
250       echo "Found Baremetal ${i} VM, using existing VM"
251     fi
252     #virsh vol-list default | grep baremetal${i} 2>&1> /dev/null || virsh vol-create-as default baremetal${i}.qcow2 41G --format qcow2
253     mac=$(virsh domiflist baremetal${i} | grep admin_network | awk '{ print $5 }')
254
255     if [ "$VM_COMPUTES" -gt 0 ]; then
256       capability="profile:compute"
257       VM_COMPUTES=$((VM_COMPUTES - 1))
258     else
259       capability="profile:control"
260     fi
261
262     cat >> $CONFIG/instackenv-virt.json << EOF
263     {
264       "pm_addr": "192.168.122.1",
265       "pm_user": "root",
266       "pm_password": "INSERT_STACK_USER_PRIV_KEY",
267       "pm_type": "pxe_ssh",
268       "mac": [
269         "$mac"
270       ],
271       "cpu": "$vcpus",
272       "memory": "$ramsize",
273       "disk": "41",
274       "arch": "x86_64",
275       "capabilities": "$capability"
276     },
277 EOF
278   done
279
280   #truncate the last line to remove the comma behind the bracket
281   tail -n 1 $CONFIG/instackenv-virt.json | wc -c | xargs -I {} truncate $CONFIG/instackenv-virt.json -s -{}
282
283   #finally reclose the bracket and close the instackenv.json file
284   cat >> $CONFIG/instackenv-virt.json << EOF
285     }
286   ],
287   "arch": "x86_64",
288   "host-ip": "192.168.122.1",
289   "power_manager": "nova.virt.baremetal.virtual_power_driver.VirtualPowerManager",
290   "seed-ip": "",
291   "ssh-key": "INSERT_STACK_USER_PRIV_KEY",
292   "ssh-user": "root"
293 }
294 EOF
295   #Overwrite the tripleo-inclubator domain.xml with our own, keeping a backup.
296   if [ ! -f /usr/share/tripleo/templates/domain.xml.bak ]; then
297     /usr/bin/mv -f /usr/share/tripleo/templates/domain.xml /usr/share/tripleo/templates/domain.xml.bak
298   fi
299
300   /usr/bin/cp -f $LIB/installer/domain.xml /usr/share/tripleo/templates/domain.xml
301 }
302
303 ##Create virtual nodes in virsh
304 ##params: name - String: libvirt name for VM
305 ##        bootdev - String: boot device for the VM
306 ##        disksize - Number: size of the disk in GB
307 ##        ovs_bridges: - List: list of ovs bridges
308 ##        vcpus - Number of VCPUs to use (defaults to 4)
309 ##        ramsize - Size of RAM for VM in MB (defaults to 8192)
310 function define_vm () {
311   local vcpus ramsize
312
313   if [ -z "$5" ]; then
314     vcpus=4
315     ramsize=8388608
316   elif [ -z "$6" ]; then
317     vcpus=$5
318     ramsize=8388608
319   else
320     vcpus=$5
321     ramsize=$(($6*1024))
322   fi
323
324   # Create the libvirt storage volume
325   if virsh vol-list default | grep ${1}.qcow2 2>&1> /dev/null; then
326     volume_path=$(virsh vol-path --pool default ${1}.qcow2 || echo "/var/lib/libvirt/images/${1}.qcow2")
327     echo "Volume ${1} exists. Deleting Existing Volume $volume_path"
328     virsh vol-dumpxml ${1}.qcow2 --pool default > /dev/null || echo '' #ok for this to fail
329     touch $volume_path
330     virsh vol-delete ${1}.qcow2 --pool default
331   fi
332   virsh vol-create-as default ${1}.qcow2 ${3}G --format qcow2
333   volume_path=$(virsh vol-path --pool default ${1}.qcow2)
334   if [ ! -f $volume_path ]; then
335       echo "$volume_path Not created successfully... Aborting"
336       exit 1
337   fi
338
339   # create the VM
340   /usr/libexec/openstack-tripleo/configure-vm --name $1 \
341                                               --bootdev $2 \
342                                               --image "$volume_path" \
343                                               --diskbus sata \
344                                               --arch x86_64 \
345                                               --cpus $vcpus \
346                                               --memory $ramsize \
347                                               --libvirt-nic-driver virtio \
348                                               --baremetal-interface $4
349 }
350
351 ##Copy over the glance images and instackenv json file
352 ##params: none
353 function configure_undercloud {
354   local controller_nic_template compute_nic_template
355   echo
356   echo "Copying configuration files to Undercloud"
357   if [[ "$net_isolation_enabled" == "TRUE" ]]; then
358     echo -e "${blue}Network Environment set for Deployment: ${reset}"
359     cat /tmp/network-environment.yaml
360     scp ${SSH_OPTIONS[@]} /tmp/network-environment.yaml "stack@$UNDERCLOUD":
361
362     # check for ODL L3/ONOS
363     if [ "${deploy_options_array['sdn_l3']}" == 'True' ]; then
364       ext_net_type=br-ex
365     fi
366
367     if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
368       ovs_dpdk_bridge='br-phy'
369     else
370       ovs_dpdk_bridge=''
371     fi
372
373     if ! controller_nic_template=$(python3.4 -B $LIB/python/apex_python_utils.py nic-template -r controller -s $NETSETS -i $net_isolation_enabled -t $CONFIG/nics-template.yaml.jinja2 -n "$enabled_network_list" -e "br-ex" -af $ip_addr_family); then
374       echo -e "${red}ERROR: Failed to generate controller NIC heat template ${reset}"
375       exit 1
376     fi
377
378     if ! compute_nic_template=$(python3.4 -B $LIB/python/apex_python_utils.py nic-template -r compute -s $NETSETS -i $net_isolation_enabled -t $CONFIG/nics-template.yaml.jinja2 -n "$enabled_network_list" -e $ext_net_type -af $ip_addr_family -d "$ovs_dpdk_bridge"); then
379       echo -e "${red}ERROR: Failed to generate compute NIC heat template ${reset}"
380       exit 1
381     fi
382     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" << EOI
383 mkdir nics/
384 cat > nics/controller.yaml << EOF
385 $controller_nic_template
386 EOF
387 cat > nics/compute.yaml << EOF
388 $compute_nic_template
389 EOF
390 EOI
391   fi
392
393   # ensure stack user on Undercloud machine has an ssh key
394   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "if [ ! -e ~/.ssh/id_rsa.pub ]; then ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa; fi"
395
396   if [ "$virtual" == "TRUE" ]; then
397
398       # copy the Undercloud VM's stack user's pub key to
399       # root's auth keys so that Undercloud can control
400       # vm power on the hypervisor
401       ssh ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "cat /home/stack/.ssh/id_rsa.pub" >> /root/.ssh/authorized_keys
402
403       DEPLOY_OPTIONS+=" --libvirt-type qemu"
404       INSTACKENV=$CONFIG/instackenv-virt.json
405
406       # upload instackenv file to Undercloud for virtual deployment
407       scp ${SSH_OPTIONS[@]} $INSTACKENV "stack@$UNDERCLOUD":instackenv.json
408   fi
409
410   # allow stack to control power management on the hypervisor via sshkey
411   # only if this is a virtual deployment
412   if [ "$virtual" == "TRUE" ]; then
413       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
414 while read -r line; do
415   stack_key=\${stack_key}\\\\\\\\n\${line}
416 done < <(cat ~/.ssh/id_rsa)
417 stack_key=\$(echo \$stack_key | sed 's/\\\\\\\\n//')
418 sed -i 's~INSERT_STACK_USER_PRIV_KEY~'"\$stack_key"'~' instackenv.json
419 EOI
420   fi
421
422   # copy stack's ssh key to this users authorized keys
423   ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "cat /home/stack/.ssh/id_rsa.pub" >> ~/.ssh/authorized_keys
424
425   # disable requiretty for sudo
426   ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "sed -i 's/Defaults\s*requiretty//'" /etc/sudoers
427
428   # configure undercloud on Undercloud VM
429   echo "Running undercloud configuration."
430   echo "Logging undercloud configuration to undercloud:/home/stack/apex-undercloud-install.log"
431   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" << EOI
432 if [[ "$net_isolation_enabled" == "TRUE" ]]; then
433   sed -i 's/#local_ip/local_ip/' undercloud.conf
434   sed -i 's/#network_gateway/network_gateway/' undercloud.conf
435   sed -i 's/#network_cidr/network_cidr/' undercloud.conf
436   sed -i 's/#dhcp_start/dhcp_start/' undercloud.conf
437   sed -i 's/#dhcp_end/dhcp_end/' undercloud.conf
438   sed -i 's/#inspection_iprange/inspection_iprange/' undercloud.conf
439   sed -i 's/#undercloud_debug/undercloud_debug/' undercloud.conf
440
441   openstack-config --set undercloud.conf DEFAULT local_ip ${admin_network_provisioner_ip}/${admin_network_cidr##*/}
442   openstack-config --set undercloud.conf DEFAULT network_gateway ${admin_network_provisioner_ip}
443   openstack-config --set undercloud.conf DEFAULT network_cidr ${admin_network_cidr}
444   openstack-config --set undercloud.conf DEFAULT dhcp_start ${admin_network_dhcp_range%%,*}
445   openstack-config --set undercloud.conf DEFAULT dhcp_end ${admin_network_dhcp_range##*,}
446   openstack-config --set undercloud.conf DEFAULT inspection_iprange ${admin_network_introspection_range}
447   openstack-config --set undercloud.conf DEFAULT undercloud_debug false
448
449 fi
450
451 sudo sed -i '/CephClusterFSID:/c\\  CephClusterFSID: \\x27$(cat /proc/sys/kernel/random/uuid)\\x27' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml
452 sudo sed -i '/CephMonKey:/c\\  CephMonKey: \\x27'"\$(ceph-authtool --gen-print-key)"'\\x27' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml
453 sudo sed -i '/CephAdminKey:/c\\  CephAdminKey: \\x27'"\$(ceph-authtool --gen-print-key)"'\\x27' /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml
454
455 # we assume that packages will not need to be updated with undercloud install
456 # and that it will be used only to configure the undercloud
457 # packages updates would need to be handled manually with yum update
458 sudo cp -f /usr/share/diskimage-builder/elements/yum/bin/install-packages /usr/share/diskimage-builder/elements/yum/bin/install-packages.bak
459 cat << 'EOF' | sudo tee /usr/share/diskimage-builder/elements/yum/bin/install-packages > /dev/null
460 #!/bin/sh
461 exit 0
462 EOF
463
464 openstack undercloud install &> apex-undercloud-install.log || {
465     # cat the undercloud install log incase it fails
466     echo "ERROR: openstack undercloud install has failed. Dumping Log:"
467     cat apex-undercloud-install.log
468     exit 1
469 }
470
471 sleep 30
472 sudo systemctl restart openstack-glance-api
473 sudo systemctl restart openstack-nova-conductor
474 sudo systemctl restart openstack-nova-compute
475
476 sudo sed -i '/num_engine_workers/c\num_engine_workers = 2' /etc/heat/heat.conf
477 sudo sed -i '/#workers\s=/c\workers = 2' /etc/heat/heat.conf
478 sudo systemctl restart openstack-heat-engine
479 sudo systemctl restart openstack-heat-api
480 EOI
481
482 # configure external network
483   ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" << EOI
484 if [[ "$public_network_vlan" != "native" ]]; then
485   cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-vlan${public_network_vlan}
486 DEVICE=vlan${public_network_vlan}
487 ONBOOT=yes
488 DEVICETYPE=ovs
489 TYPE=OVSIntPort
490 BOOTPROTO=static
491 IPADDR=${public_network_provisioner_ip}
492 PREFIX=${public_network_cidr##*/}
493 OVS_BRIDGE=br-ctlplane
494 OVS_OPTIONS="tag=${public_network_vlan}"
495 EOF
496   ifup vlan${public_network_vlan}
497 else
498   if ! ip a s eth2 | grep ${public_network_provisioner_ip} > /dev/null; then
499       ip a a ${public_network_provisioner_ip}/${public_network_cidr##*/} dev eth2
500       ip link set up dev eth2
501   fi
502 fi
503 EOI
504
505 # WORKAROUND: must restart the above services to fix sync problem with nova compute manager
506 # TODO: revisit and file a bug if necessary. This should eventually be removed
507 # as well as glance api problem
508 echo -e "${blue}INFO: Sleeping 15 seconds while services come back from restart${reset}"
509 sleep 15
510
511 }
512
513 ##preping it for deployment and launch the deploy
514 ##params: none
515 function undercloud_prep_overcloud_deploy {
516   if [[ "${#deploy_options_array[@]}" -eq 0 || "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
517     if [ "${deploy_options_array['sdn_l3']}" == 'True' ]; then
518       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_l3.yaml"
519     elif [ "${deploy_options_array['sfc']}" == 'True' ]; then
520       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sfc.yaml"
521     elif [ "${deploy_options_array['vpn']}" == 'True' ]; then
522       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sdnvpn.yaml"
523     elif [ "${deploy_options_array['vpp']}" == 'True' ]; then
524       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_fdio.yaml"
525     else
526       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight.yaml"
527     fi
528     SDN_IMAGE=opendaylight
529     if [ "${deploy_options_array['sfc']}" == 'True' ]; then
530       SDN_IMAGE+=-sfc
531       if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
532           echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute an SFC deployment."
533           echo "Please install the opnfv-apex-opendaylight-sfc package to provide this overcloud image for deployment.${reset}"
534           exit 1
535       fi
536     fi
537   elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
538     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
539     SDN_IMAGE=opendaylight
540   elif [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
541     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
542     SDN_IMAGE=onos
543   elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
544     echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
545     exit 1
546   elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
547     echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
548     SDN_IMAGE=opendaylight
549   else
550     echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
551     echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, False, or null${reset}"
552     exit 1
553   fi
554
555
556
557   # Make sure the correct overcloud image is available
558   if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
559       echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
560       echo "Both ONOS and OpenDaylight are currently deployed from this image."
561       echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
562       exit 1
563   fi
564
565   echo "Copying overcloud image to Undercloud"
566   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f overcloud-full.qcow2"
567   scp ${SSH_OPTIONS[@]} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
568
569   # Install ovs-dpdk inside the overcloud image if it is enabled.
570   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
571     # install dpdk packages before ovs
572     echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
573
574     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
575       cat << EOF > vfio_pci.modules
576 #!/bin/bash
577 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
578 EOF
579
580       cat << EOF > uio_pci_generic.modules
581 #!/bin/bash
582 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
583 EOF
584
585       LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
586                                                --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
587                                                --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
588                                                --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
589                                                --run-command "yum install -y /root/dpdk_rpms/*" \
590                                                -a overcloud-full.qcow2
591 EOI
592   elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
593     echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
594     exit 1
595   fi
596
597   # Set ODL version accordingly
598   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['odl_version']}" == 'boron' ]]; then
599     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
600       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
601                                                --run-command "yum -y install /root/boron/*" \
602                                                -a overcloud-full.qcow2
603 EOI
604   fi
605
606   # Add performance deploy options if they have been set
607   if [ ! -z "${deploy_options_array['performance']}" ]; then
608
609     # Remove previous kernel args files per role
610     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Compute-kernel_params.txt"
611     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Controller-kernel_params.txt"
612
613     # Push performance options to subscript to modify per-role images as needed
614     for option in "${performance_options[@]}" ; do
615       echo -e "${blue}Setting performance option $option${reset}"
616       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "bash build_perf_image.sh $option"
617     done
618
619     # Build IPA kernel option ramdisks
620     ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
621 /bin/cp -f /home/stack/ironic-python-agent.initramfs /root/
622 mkdir -p ipa/
623 pushd ipa
624 gunzip -c ../ironic-python-agent.initramfs | cpio -i
625 if [ ! -f /home/stack/Compute-kernel_params.txt ]; then
626   touch /home/stack/Compute-kernel_params.txt
627   chown stack /home/stack/Compute-kernel_params.txt
628 fi
629 /bin/cp -f /home/stack/Compute-kernel_params.txt tmp/kernel_params.txt
630 echo "Compute params set: "
631 cat tmp/kernel_params.txt
632 /bin/cp -f /root/image.py usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.py
633 /bin/cp -f /root/image.pyc usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.pyc
634 find . | cpio -o -H newc | gzip > /home/stack/Compute-ironic-python-agent.initramfs
635 chown stack /home/stack/Compute-ironic-python-agent.initramfs
636 if [ ! -f /home/stack/Controller-kernel_params.txt ]; then
637   touch /home/stack/Controller-kernel_params.txt
638   chown stack /home/stack/Controller-kernel_params.txt
639 fi
640 /bin/cp -f /home/stack/Controller-kernel_params.txt tmp/kernel_params.txt
641 echo "Controller params set: "
642 cat tmp/kernel_params.txt
643 find . | cpio -o -H newc | gzip > /home/stack/Controller-ironic-python-agent.initramfs
644 chown stack /home/stack/Controller-ironic-python-agent.initramfs
645 popd
646 /bin/rm -rf ipa/
647 EOI
648
649     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml"
650   fi
651
652   # make sure ceph is installed
653   DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
654
655   # scale compute nodes according to inventory
656   total_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "cat /home/stack/instackenv.json | grep -c memory")
657
658   # check if HA is enabled
659   if [[ "$ha_enabled" == "True" ]]; then
660      DEPLOY_OPTIONS+=" --control-scale 3"
661      compute_nodes=$((total_nodes - 3))
662      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
663   else
664      compute_nodes=$((total_nodes - 1))
665   fi
666
667   if [ "$compute_nodes" -le 0 ]; then
668     echo -e "${red}ERROR: Invalid number of compute nodes: ${compute_nodes}. Check your inventory file.${reset}"
669     exit 1
670   else
671     echo -e "${blue}INFO: Number of compute nodes set for deployment: ${compute_nodes}${reset}"
672     DEPLOY_OPTIONS+=" --compute-scale ${compute_nodes}"
673   fi
674
675   if [[ "$net_isolation_enabled" == "TRUE" ]]; then
676      #DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml"
677      DEPLOY_OPTIONS+=" -e network-environment.yaml"
678   fi
679
680   if [[ "$ha_enabled" == "True" ]] || [[ "$net_isolation_enabled" == "TRUE" ]]; then
681      DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
682   fi
683
684   if [[ ! "$virtual" == "TRUE" ]]; then
685      DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
686   else
687      DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
688   fi
689
690   DEPLOY_OPTIONS+=" -e opnfv-environment.yaml"
691
692   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
693
694   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
695 if [ "$debug" == 'TRUE' ]; then
696     LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex
697 fi
698
699 source stackrc
700 set -o errexit
701 echo "Uploading overcloud glance images"
702 openstack overcloud image upload
703
704 echo "Configuring undercloud and discovering nodes"
705 openstack baremetal import --json instackenv.json
706 openstack baremetal configure boot
707 bash -x set_perf_images.sh ${performance_roles[@]}
708 #if [[ -z "$virtual" ]]; then
709 #  openstack baremetal introspection bulk start
710 #fi
711 echo "Configuring flavors"
712 for flavor in baremetal control compute; do
713   echo -e "${blue}INFO: Updating flavor: \${flavor}${reset}"
714   if openstack flavor list | grep \${flavor}; then
715     openstack flavor delete \${flavor}
716   fi
717   openstack flavor create --id auto --ram 4096 --disk 39 --vcpus 1 \${flavor}
718   if ! openstack flavor list | grep \${flavor}; then
719     echo -e "${red}ERROR: Unable to create flavor \${flavor}${reset}"
720   fi
721 done
722 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
723 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="control" control
724 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="compute" compute
725 echo "Configuring nameserver on ctlplane network"
726 dns_server_ext=''
727 for dns_server in ${dns_servers}; do
728   dns_server_ext="\${dns_server_ext} --dns-nameserver \${dns_server}"
729 done
730 neutron subnet-update \$(neutron subnet-list | grep -Ev "id|tenant|external|storage" | grep -v \\\\-\\\\- | awk {'print \$2'}) \${dns_server_ext}
731 echo "Executing overcloud deployment, this should run for an extended period without output."
732 sleep 60 #wait for Hypervisor stats to check-in to nova
733 # save deploy command so it can be used for debugging
734 cat > deploy_command << EOF
735 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
736 EOF
737 EOI
738
739   if [ "$interactive" == "TRUE" ]; then
740     if ! prompt_user "Overcloud Deployment"; then
741       echo -e "${blue}INFO: User requests exit${reset}"
742       exit 0
743     fi
744   fi
745
746   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
747 source stackrc
748 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
749 if ! heat stack-list | grep CREATE_COMPLETE 1>/dev/null; then
750   $(typeset -f debug_stack)
751   debug_stack
752   exit 1
753 fi
754 EOI
755
756   # Configure DPDK
757   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
758     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI || (echo "DPDK config failed, exiting..."; exit 1)
759 source stackrc
760 set -o errexit
761 for node in \$(nova list | grep novacompute | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
762 echo "Running DPDK test app on \$node"
763 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
764 set -o errexit
765 sudo dpdk_helloworld --no-pci
766 sudo dpdk_nic_bind -s
767 EOF
768 done
769 EOI
770   fi
771
772   if [ "$debug" == 'TRUE' ]; then
773       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
774 source overcloudrc
775 echo "Keystone Endpoint List:"
776 openstack endpoint list
777 echo "Keystone Service List"
778 openstack service list
779 cinder quota-show \$(openstack project list | grep admin | awk {'print \$2'})
780 EOI
781   fi
782 }
783
784 ##Post configuration after install
785 ##params: none
786 function configure_post_install {
787   local opnfv_attach_networks ovs_ip ip_range net_cidr tmp_ip
788   opnfv_attach_networks="admin_network public_network"
789
790   echo -e "${blue}INFO: Post Install Configuration Running...${reset}"
791
792   echo -e "${blue}INFO: Configuring ssh for root to overcloud nodes...${reset}"
793   # copy host key to instack
794   scp ${SSH_OPTIONS[@]} /root/.ssh/id_rsa.pub "stack@$UNDERCLOUD":jumphost_id_rsa.pub
795
796   # add host key to overcloud nodes authorized keys
797   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" << EOI
798 source stackrc
799 nodes=\$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
800 for node in \$nodes; do
801 cat ~/jumphost_id_rsa.pub | ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" 'cat >> ~/.ssh/authorized_keys'
802 done
803 EOI
804
805   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
806     echo -e "${blue}INFO: Bringing up br-phy and ovs-agent for dpdk compute nodes...${reset}"
807     compute_nodes=$(undercloud_connect stack "source stackrc; nova list | grep compute | wc -l")
808     i=0
809     while [ "$i" -lt "$compute_nodes" ]; do
810       overcloud_connect compute${i} "sudo ifup br-phy; sudo systemctl restart neutron-openvswitch-agent"
811       i=$((i + 1))
812     done
813   fi
814
815   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
816 source overcloudrc
817 set -o errexit
818 echo "Configuring Neutron external network"
819 neutron net-create external --router:external=True --tenant-id \$(openstack project show service | grep id | awk '{ print \$4 }')
820 neutron subnet-create --name external-net --tenant-id \$(openstack project show service | grep id | awk '{ print \$4 }') --disable-dhcp external --gateway ${public_network_gateway} --allocation-pool start=${public_network_floating_ip_range%%,*},end=${public_network_floating_ip_range##*,} ${public_network_cidr}
821
822 echo "Removing sahara endpoint and service"
823 sahara_service_id=\$(openstack service list | grep sahara | cut -d ' ' -f 2)
824 sahara_endpoint_id=\$(openstack endpoint list | grep sahara | cut -d ' ' -f 2)
825 openstack endpoint delete \$sahara_endpoint_id
826 openstack service delete \$sahara_service_id
827
828 echo "Removing swift endpoint and service"
829 swift_service_id=\$(openstack service list | grep swift | cut -d ' ' -f 2)
830 swift_endpoint_id=\$(openstack endpoint list | grep swift | cut -d ' ' -f 2)
831 openstack endpoint delete \$swift_endpoint_id
832 openstack service delete \$swift_service_id
833
834 if [ "${deploy_options_array['congress']}" == 'True' ]; then
835     for s in nova neutronv2 ceilometer cinder glancev2 keystone; do
836         openstack congress datasource create \$s "\$s" \\
837             --config username=\$OS_USERNAME \\
838             --config tenant_name=\$OS_TENANT_NAME \\
839             --config password=\$OS_PASSWORD \\
840             --config auth_url=\$OS_AUTH_URL
841     done
842 fi
843 EOI
844
845   echo -e "${blue}INFO: Checking if OVS bridges have IP addresses...${reset}"
846   for network in ${opnfv_attach_networks}; do
847     ovs_ip=$(find_ip ${NET_MAP[$network]})
848     tmp_ip=''
849     if [ -n "$ovs_ip" ]; then
850       echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} has IP address ${ovs_ip}${reset}"
851     else
852       echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} missing IP, will configure${reset}"
853       # use last IP of allocation pool
854       eval "ip_range=\${${network}_usable_ip_range}"
855       ovs_ip=${ip_range##*,}
856       eval "net_cidr=\${${network}_cidr}"
857       sudo ip addr add ${ovs_ip}/${net_cidr##*/} dev ${NET_MAP[$network]}
858       sudo ip link set up ${NET_MAP[$network]}
859       tmp_ip=$(find_ip ${NET_MAP[$network]})
860       if [ -n "$tmp_ip" ]; then
861         echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} IP set: ${tmp_ip}${reset}"
862         continue
863       else
864         echo -e "${red}ERROR: Unable to set OVS Bridge ${NET_MAP[$network]} with IP: ${ovs_ip}${reset}"
865         return 1
866       fi
867     fi
868   done
869
870   # for virtual, we NAT public network through Undercloud
871   if [ "$virtual" == "TRUE" ]; then
872     if ! configure_undercloud_nat ${public_network_cidr}; then
873       echo -e "${red}ERROR: Unable to NAT undercloud with external net: ${public_network_cidr}${reset}"
874       exit 1
875     else
876       echo -e "${blue}INFO: Undercloud VM has been setup to NAT Overcloud public network${reset}"
877     fi
878   fi
879
880   # for sfc deployments we need the vxlan workaround
881   if [ "${deploy_options_array['sfc']}" == 'True' ]; then
882       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
883 source stackrc
884 set -o errexit
885 for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
886 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
887 sudo ifconfig br-int up
888 sudo ip route add 123.123.123.0/24 dev br-int
889 EOF
890 done
891 EOI
892   fi
893
894   # Collect deployment logs
895   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
896 mkdir -p ~/deploy_logs
897 rm -rf deploy_logs/*
898 source stackrc
899 set -o errexit
900 for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
901  ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
902  sudo cp /var/log/messages /home/heat-admin/messages.log
903  sudo chown heat-admin /home/heat-admin/messages.log
904 EOF
905 scp ${SSH_OPTIONS[@]} heat-admin@\$node:/home/heat-admin/messages.log ~/deploy_logs/\$node.messages.log
906 if [ "$debug" == "TRUE" ]; then
907     nova list --ip \$node
908     echo "---------------------------"
909     echo "-----/var/log/messages-----"
910     echo "---------------------------"
911     cat ~/deploy_logs/\$node.messages.log
912     echo "---------------------------"
913     echo "----------END LOG----------"
914     echo "---------------------------"
915 fi
916  ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
917  sudo rm -f /home/heat-admin/messages.log
918 EOF
919 done
920
921 # Print out the undercloud IP and dashboard URL
922 source stackrc
923 echo "Undercloud IP: $UNDERCLOUD, please connect by doing 'opnfv-util undercloud'"
924 echo "Overcloud dashboard available at http://\$(heat output-show overcloud PublicVip | sed 's/"//g')/dashboard"
925 EOI
926
927 }
928
929 display_usage() {
930   echo -e "Usage:\n$0 [arguments] \n"
931   echo -e "   -d|--deploy-settings : Full path to deploy settings yaml file. Optional.  Defaults to null"
932   echo -e "   -i|--inventory : Full path to inventory yaml file. Required only for baremetal"
933   echo -e "   -n|--net-settings : Full path to network settings file. Optional."
934   echo -e "   -p|--ping-site : site to use to verify IP connectivity. Optional. Defaults to 8.8.8.8"
935   echo -e "   -v|--virtual : Virtualize overcloud nodes instead of using baremetal."
936   echo -e "   --flat : disable Network Isolation and use a single flat network for the underlay network."
937   echo -e "   --no-post-config : disable Post Install configuration."
938   echo -e "   --debug : enable debug output."
939   echo -e "   --interactive : enable interactive deployment mode which requires user to confirm steps of deployment."
940   echo -e "   --virtual-cpus : Number of CPUs to use per Overcloud VM in a virtual deployment (defaults to 4)."
941   echo -e "   --virtual-ram : Amount of RAM to use per Overcloud VM in GB (defaults to 8)."
942 }
943
944 ##translates the command line parameters into variables
945 ##params: $@ the entire command line is passed
946 ##usage: parse_cmd_line() "$@"
947 parse_cmdline() {
948   echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
949   echo "Use -h to display help"
950   sleep 2
951
952   while [ "${1:0:1}" = "-" ]
953   do
954     case "$1" in
955         -h|--help)
956                 display_usage
957                 exit 0
958             ;;
959         -d|--deploy-settings)
960                 DEPLOY_SETTINGS_FILE=$2
961                 echo "Deployment Configuration file: $2"
962                 shift 2
963             ;;
964         -i|--inventory)
965                 INVENTORY_FILE=$2
966                 shift 2
967             ;;
968         -n|--net-settings)
969                 NETSETS=$2
970                 echo "Network Settings Configuration file: $2"
971                 shift 2
972             ;;
973         -p|--ping-site)
974                 ping_site=$2
975                 echo "Using $2 as the ping site"
976                 shift 2
977             ;;
978         -v|--virtual)
979                 virtual="TRUE"
980                 echo "Executing a Virtual Deployment"
981                 shift 1
982             ;;
983         --flat )
984                 net_isolation_enabled="FALSE"
985                 echo "Underlay Network Isolation Disabled: using flat configuration"
986                 shift 1
987             ;;
988         --no-post-config )
989                 post_config="FALSE"
990                 echo "Post install configuration disabled"
991                 shift 1
992             ;;
993         --debug )
994                 debug="TRUE"
995                 echo "Enable debug output"
996                 shift 1
997             ;;
998         --interactive )
999                 interactive="TRUE"
1000                 echo "Interactive mode enabled"
1001                 shift 1
1002             ;;
1003         --virtual-cpus )
1004                 VM_CPUS=$2
1005                 echo "Number of CPUs per VM set to $VM_CPUS"
1006                 shift 2
1007             ;;
1008         --virtual-ram )
1009                 VM_RAM=$2
1010                 echo "Amount of RAM per VM set to $VM_RAM"
1011                 shift 2
1012             ;;
1013         --virtual-computes )
1014                 VM_COMPUTES=$2
1015                 echo "Virtual Compute nodes set to $VM_COMPUTES"
1016                 shift 2
1017             ;;
1018         *)
1019                 display_usage
1020                 exit 1
1021             ;;
1022     esac
1023   done
1024
1025   if [[ ! -z "$NETSETS" && "$net_isolation_enabled" == "FALSE" ]]; then
1026     echo -e "${red}INFO: Single flat network requested. Only admin_network settings will be used!${reset}"
1027   elif [[ -z "$NETSETS" ]]; then
1028     echo -e "${red}ERROR: You must provide a network_settings file with -n.${reset}"
1029     exit 1
1030   fi
1031
1032   if [[ -n "$virtual" && -n "$INVENTORY_FILE" ]]; then
1033     echo -e "${red}ERROR: You should not specify an inventory with virtual deployments${reset}"
1034     exit 1
1035   fi
1036
1037   if [[ -z "$DEPLOY_SETTINGS_FILE" || ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
1038     echo -e "${red}ERROR: Deploy Settings: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
1039     exit 1
1040   fi
1041
1042   if [[ ! -z "$NETSETS" && ! -f "$NETSETS" ]]; then
1043     echo -e "${red}ERROR: Network Settings: ${NETSETS} does not exist! Exiting...${reset}"
1044     exit 1
1045   fi
1046
1047   if [[ ! -z "$INVENTORY_FILE" && ! -f "$INVENTORY_FILE" ]]; then
1048     echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
1049     exit 1
1050   fi
1051
1052   if [[ -z "$virtual" && -z "$INVENTORY_FILE" ]]; then
1053     echo -e "${red}ERROR: You must specify an inventory file for baremetal deployments! Exiting...${reset}"
1054     exit 1
1055   fi
1056
1057   if [[ "$net_isolation_enabled" == "FALSE" && "$post_config" == "TRUE" ]]; then
1058     echo -e "${blue}INFO: Post Install Configuration will be skipped.  It is not supported with --flat${reset}"
1059     post_config="FALSE"
1060   fi
1061
1062 }
1063
1064 ##END FUNCTIONS
1065
1066 main() {
1067   parse_cmdline "$@"
1068   echo -e "${blue}INFO: Parsing network settings file...${reset}"
1069   parse_network_settings
1070   if ! configure_deps; then
1071     echo -e "${red}Dependency Validation Failed, Exiting.${reset}"
1072     exit 1
1073   fi
1074   if [ -n "$DEPLOY_SETTINGS_FILE" ]; then
1075     echo -e "${blue}INFO: Parsing deploy settings file...${reset}"
1076     parse_deploy_settings
1077   fi
1078   setup_undercloud_vm
1079   if [ "$virtual" == "TRUE" ]; then
1080     setup_virtual_baremetal $VM_CPUS $VM_RAM
1081   elif [ -n "$INVENTORY_FILE" ]; then
1082     parse_inventory_file
1083   fi
1084   configure_undercloud
1085   undercloud_prep_overcloud_deploy
1086   if [ "$post_config" == "TRUE" ]; then
1087     if ! configure_post_install; then
1088       echo -e "${red}ERROR:Post Install Configuration Failed, Exiting.${reset}"
1089       exit 1
1090     else
1091       echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
1092     fi
1093   fi
1094   if [[ "${deploy_options_array['sdn_controller']}" == 'onos' ]]; then
1095     if ! onos_update_gw_mac ${public_network_cidr} ${public_network_gateway}; then
1096       echo -e "${red}ERROR:ONOS Post Install Configuration Failed, Exiting.${reset}"
1097       exit 1
1098     else
1099       echo -e "${blue}INFO: ONOS Post Install Configuration Complete${reset}"
1100     fi
1101   fi
1102 }
1103
1104 main "$@"