Splitting out deploy.sh undercloud to functions file
[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/virtual-setup-functions.sh
64 $LIB/undercloud-functions.sh
65 $LIB/utility-functions.sh
66 $LIB/installer/onos/onos_gw_mac_update.sh
67 )
68 for lib_file in ${lib_files[@]}; do
69   if ! source $lib_file; then
70     echo -e "${red}ERROR: Failed to source $lib_file${reset}"
71     exit 1
72   fi
73 done
74
75 ##FUNCTIONS
76 ##checks if prefix exists in string
77 ##params: string, prefix
78 ##usage: contains_prefix "deploy_setting_launcher=1" "deploy_setting"
79 contains_prefix() {
80   local mystr=$1
81   local prefix=$2
82   if echo $mystr | grep -E "^$prefix.*$" > /dev/null; then
83     return 0
84   else
85     return 1
86   fi
87 }
88
89 ##verify internet connectivity
90 #params: none
91 function verify_internet {
92   if ping -c 2 $ping_site > /dev/null; then
93     if ping -c 2 www.google.com > /dev/null; then
94       echo "${blue}Internet connectivity detected${reset}"
95       return 0
96     else
97       echo "${red}Internet connectivity detected, but DNS lookup failed${reset}"
98       return 1
99     fi
100   else
101     echo "${red}No internet connectivity detected${reset}"
102     return 1
103   fi
104 }
105
106 ##preping it for deployment and launch the deploy
107 ##params: none
108 function undercloud_prep_overcloud_deploy {
109   if [[ "${#deploy_options_array[@]}" -eq 0 || "${deploy_options_array['sdn_controller']}" == 'opendaylight' ]]; then
110     if [ "${deploy_options_array['sdn_l3']}" == 'True' ]; then
111       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_l3.yaml"
112     elif [ "${deploy_options_array['sfc']}" == 'True' ]; then
113       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sfc.yaml"
114     elif [ "${deploy_options_array['vpn']}" == 'True' ]; then
115       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_sdnvpn.yaml"
116     elif [ "${deploy_options_array['vpp']}" == 'True' ]; then
117       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight_fdio.yaml"
118     else
119       DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight.yaml"
120     fi
121     SDN_IMAGE=opendaylight
122     if [ "${deploy_options_array['sfc']}" == 'True' ]; then
123       SDN_IMAGE+=-sfc
124       if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
125           echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute an SFC deployment."
126           echo "Please install the opnfv-apex-opendaylight-sfc package to provide this overcloud image for deployment.${reset}"
127           exit 1
128       fi
129     fi
130   elif [ "${deploy_options_array['sdn_controller']}" == 'opendaylight-external' ]; then
131     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/opendaylight-external.yaml"
132     SDN_IMAGE=opendaylight
133   elif [ "${deploy_options_array['sdn_controller']}" == 'onos' ]; then
134     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/onos.yaml"
135     SDN_IMAGE=onos
136   elif [ "${deploy_options_array['sdn_controller']}" == 'opencontrail' ]; then
137     echo -e "${red}ERROR: OpenContrail is currently unsupported...exiting${reset}"
138     exit 1
139   elif [[ -z "${deploy_options_array['sdn_controller']}" || "${deploy_options_array['sdn_controller']}" == 'False' ]]; then
140     echo -e "${blue}INFO: SDN Controller disabled...will deploy nosdn scenario${reset}"
141     SDN_IMAGE=opendaylight
142   else
143     echo "${red}Invalid sdn_controller: ${deploy_options_array['sdn_controller']}${reset}"
144     echo "${red}Valid choices are opendaylight, opendaylight-external, onos, opencontrail, False, or null${reset}"
145     exit 1
146   fi
147
148
149
150   # Make sure the correct overcloud image is available
151   if [ ! -f $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 ]; then
152       echo "${red} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 is required to execute your deployment."
153       echo "Both ONOS and OpenDaylight are currently deployed from this image."
154       echo "Please install the opnfv-apex package to provide this overcloud image for deployment.${reset}"
155       exit 1
156   fi
157
158   echo "Copying overcloud image to Undercloud"
159   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f overcloud-full.qcow2"
160   scp ${SSH_OPTIONS[@]} $RESOURCES/overcloud-full-${SDN_IMAGE}.qcow2 "stack@$UNDERCLOUD":overcloud-full.qcow2
161
162   # Install ovs-dpdk inside the overcloud image if it is enabled.
163   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
164     # install dpdk packages before ovs
165     echo -e "${blue}INFO: Enabling kernel modules for dpdk inside overcloud image${reset}"
166
167     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
168       cat << EOF > vfio_pci.modules
169 #!/bin/bash
170 exec /sbin/modprobe vfio_pci >/dev/null 2>&1
171 EOF
172
173       cat << EOF > uio_pci_generic.modules
174 #!/bin/bash
175 exec /sbin/modprobe uio_pci_generic >/dev/null 2>&1
176 EOF
177
178       LIBGUESTFS_BACKEND=direct virt-customize --upload vfio_pci.modules:/etc/sysconfig/modules/ \
179                                                --upload uio_pci_generic.modules:/etc/sysconfig/modules/ \
180                                                --run-command "chmod 0755 /etc/sysconfig/modules/vfio_pci.modules" \
181                                                --run-command "chmod 0755 /etc/sysconfig/modules/uio_pci_generic.modules" \
182                                                --run-command "yum install -y /root/dpdk_rpms/*" \
183                                                -a overcloud-full.qcow2
184 EOI
185   elif [ "${deploy_options_array['dataplane']}" != 'ovs' ]; then
186     echo "${red}${deploy_options_array['dataplane']} not supported${reset}"
187     exit 1
188   fi
189
190   # Set ODL version accordingly
191   if [[ "${deploy_options_array['sdn_controller']}" == 'opendaylight' && "${deploy_options_array['odl_version']}" == 'boron' ]]; then
192     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
193       LIBGUESTFS_BACKEND=direct virt-customize --run-command "yum -y remove opendaylight" \
194                                                --run-command "yum -y install /root/boron/*" \
195                                                -a overcloud-full.qcow2
196 EOI
197   fi
198
199   # Add performance deploy options if they have been set
200   if [ ! -z "${deploy_options_array['performance']}" ]; then
201
202     # Remove previous kernel args files per role
203     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Compute-kernel_params.txt"
204     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "rm -f Controller-kernel_params.txt"
205
206     # Push performance options to subscript to modify per-role images as needed
207     for option in "${performance_options[@]}" ; do
208       echo -e "${blue}Setting performance option $option${reset}"
209       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" "bash build_perf_image.sh $option"
210     done
211
212     # Build IPA kernel option ramdisks
213     ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" <<EOI
214 /bin/cp -f /home/stack/ironic-python-agent.initramfs /root/
215 mkdir -p ipa/
216 pushd ipa
217 gunzip -c ../ironic-python-agent.initramfs | cpio -i
218 if [ ! -f /home/stack/Compute-kernel_params.txt ]; then
219   touch /home/stack/Compute-kernel_params.txt
220   chown stack /home/stack/Compute-kernel_params.txt
221 fi
222 /bin/cp -f /home/stack/Compute-kernel_params.txt tmp/kernel_params.txt
223 echo "Compute params set: "
224 cat tmp/kernel_params.txt
225 /bin/cp -f /root/image.py usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.py
226 /bin/cp -f /root/image.pyc usr/lib/python2.7/site-packages/ironic_python_agent/extensions/image.pyc
227 find . | cpio -o -H newc | gzip > /home/stack/Compute-ironic-python-agent.initramfs
228 chown stack /home/stack/Compute-ironic-python-agent.initramfs
229 if [ ! -f /home/stack/Controller-kernel_params.txt ]; then
230   touch /home/stack/Controller-kernel_params.txt
231   chown stack /home/stack/Controller-kernel_params.txt
232 fi
233 /bin/cp -f /home/stack/Controller-kernel_params.txt tmp/kernel_params.txt
234 echo "Controller params set: "
235 cat tmp/kernel_params.txt
236 find . | cpio -o -H newc | gzip > /home/stack/Controller-ironic-python-agent.initramfs
237 chown stack /home/stack/Controller-ironic-python-agent.initramfs
238 popd
239 /bin/rm -rf ipa/
240 EOI
241
242     DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/numa.yaml"
243   fi
244
245   # make sure ceph is installed
246   DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/storage-environment.yaml"
247
248   # scale compute nodes according to inventory
249   total_nodes=$(ssh -T ${SSH_OPTIONS[@]} "root@$UNDERCLOUD" "cat /home/stack/instackenv.json | grep -c memory")
250
251   # check if HA is enabled
252   if [[ "$ha_enabled" == "True" ]]; then
253      DEPLOY_OPTIONS+=" --control-scale 3"
254      compute_nodes=$((total_nodes - 3))
255      DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/puppet-pacemaker.yaml"
256   else
257      compute_nodes=$((total_nodes - 1))
258   fi
259
260   if [ "$compute_nodes" -le 0 ]; then
261     echo -e "${red}ERROR: Invalid number of compute nodes: ${compute_nodes}. Check your inventory file.${reset}"
262     exit 1
263   else
264     echo -e "${blue}INFO: Number of compute nodes set for deployment: ${compute_nodes}${reset}"
265     DEPLOY_OPTIONS+=" --compute-scale ${compute_nodes}"
266   fi
267
268   if [[ "$net_isolation_enabled" == "TRUE" ]]; then
269      #DEPLOY_OPTIONS+=" -e /usr/share/openstack-tripleo-heat-templates/environments/network-isolation.yaml"
270      DEPLOY_OPTIONS+=" -e network-environment.yaml"
271   fi
272
273   if [[ "$ha_enabled" == "True" ]] || [[ "$net_isolation_enabled" == "TRUE" ]]; then
274      DEPLOY_OPTIONS+=" --ntp-server $ntp_server"
275   fi
276
277   if [[ ! "$virtual" == "TRUE" ]]; then
278      DEPLOY_OPTIONS+=" --control-flavor control --compute-flavor compute"
279   else
280      DEPLOY_OPTIONS+=" -e virtual-environment.yaml"
281   fi
282
283   DEPLOY_OPTIONS+=" -e opnfv-environment.yaml"
284
285   echo -e "${blue}INFO: Deploy options set:\n${DEPLOY_OPTIONS}${reset}"
286
287   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
288 if [ "$debug" == 'TRUE' ]; then
289     LIBGUESTFS_BACKEND=direct virt-customize -a overcloud-full.qcow2 --root-password password:opnfvapex
290 fi
291
292 source stackrc
293 set -o errexit
294 echo "Uploading overcloud glance images"
295 openstack overcloud image upload
296
297 echo "Configuring undercloud and discovering nodes"
298 openstack baremetal import --json instackenv.json
299 openstack baremetal configure boot
300 bash -x set_perf_images.sh ${performance_roles[@]}
301 #if [[ -z "$virtual" ]]; then
302 #  openstack baremetal introspection bulk start
303 #fi
304 echo "Configuring flavors"
305 for flavor in baremetal control compute; do
306   echo -e "${blue}INFO: Updating flavor: \${flavor}${reset}"
307   if openstack flavor list | grep \${flavor}; then
308     openstack flavor delete \${flavor}
309   fi
310   openstack flavor create --id auto --ram 4096 --disk 39 --vcpus 1 \${flavor}
311   if ! openstack flavor list | grep \${flavor}; then
312     echo -e "${red}ERROR: Unable to create flavor \${flavor}${reset}"
313   fi
314 done
315 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
316 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="control" control
317 openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" --property "capabilities:profile"="compute" compute
318 echo "Configuring nameserver on ctlplane network"
319 dns_server_ext=''
320 for dns_server in ${dns_servers}; do
321   dns_server_ext="\${dns_server_ext} --dns-nameserver \${dns_server}"
322 done
323 neutron subnet-update \$(neutron subnet-list | grep -Ev "id|tenant|external|storage" | grep -v \\\\-\\\\- | awk {'print \$2'}) \${dns_server_ext}
324 echo "Executing overcloud deployment, this should run for an extended period without output."
325 sleep 60 #wait for Hypervisor stats to check-in to nova
326 # save deploy command so it can be used for debugging
327 cat > deploy_command << EOF
328 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
329 EOF
330 EOI
331
332   if [ "$interactive" == "TRUE" ]; then
333     if ! prompt_user "Overcloud Deployment"; then
334       echo -e "${blue}INFO: User requests exit${reset}"
335       exit 0
336     fi
337   fi
338
339   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
340 source stackrc
341 openstack overcloud deploy --templates $DEPLOY_OPTIONS --timeout 90
342 if ! heat stack-list | grep CREATE_COMPLETE 1>/dev/null; then
343   $(typeset -f debug_stack)
344   debug_stack
345   exit 1
346 fi
347 EOI
348
349   # Configure DPDK
350   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
351     ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI || (echo "DPDK config failed, exiting..."; exit 1)
352 source stackrc
353 set -o errexit
354 for node in \$(nova list | grep novacompute | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
355 echo "Running DPDK test app on \$node"
356 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
357 set -o errexit
358 sudo dpdk_helloworld --no-pci
359 sudo dpdk_nic_bind -s
360 EOF
361 done
362 EOI
363   fi
364
365   if [ "$debug" == 'TRUE' ]; then
366       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
367 source overcloudrc
368 echo "Keystone Endpoint List:"
369 openstack endpoint list
370 echo "Keystone Service List"
371 openstack service list
372 cinder quota-show \$(openstack project list | grep admin | awk {'print \$2'})
373 EOI
374   fi
375 }
376
377 ##Post configuration after install
378 ##params: none
379 function configure_post_install {
380   local opnfv_attach_networks ovs_ip ip_range net_cidr tmp_ip
381   opnfv_attach_networks="admin_network public_network"
382
383   echo -e "${blue}INFO: Post Install Configuration Running...${reset}"
384
385   echo -e "${blue}INFO: Configuring ssh for root to overcloud nodes...${reset}"
386   # copy host key to instack
387   scp ${SSH_OPTIONS[@]} /root/.ssh/id_rsa.pub "stack@$UNDERCLOUD":jumphost_id_rsa.pub
388
389   # add host key to overcloud nodes authorized keys
390   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" << EOI
391 source stackrc
392 nodes=\$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
393 for node in \$nodes; do
394 cat ~/jumphost_id_rsa.pub | ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" 'cat >> ~/.ssh/authorized_keys'
395 done
396 EOI
397
398   if [ "${deploy_options_array['dataplane']}" == 'ovs_dpdk' ]; then
399     echo -e "${blue}INFO: Bringing up br-phy and ovs-agent for dpdk compute nodes...${reset}"
400     compute_nodes=$(undercloud_connect stack "source stackrc; nova list | grep compute | wc -l")
401     i=0
402     while [ "$i" -lt "$compute_nodes" ]; do
403       overcloud_connect compute${i} "sudo ifup br-phy; sudo systemctl restart neutron-openvswitch-agent"
404       i=$((i + 1))
405     done
406   fi
407
408   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
409 source overcloudrc
410 set -o errexit
411 echo "Configuring Neutron external network"
412 neutron net-create external --router:external=True --tenant-id \$(openstack project show service | grep id | awk '{ print \$4 }')
413 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}
414
415 echo "Removing sahara endpoint and service"
416 sahara_service_id=\$(openstack service list | grep sahara | cut -d ' ' -f 2)
417 sahara_endpoint_id=\$(openstack endpoint list | grep sahara | cut -d ' ' -f 2)
418 openstack endpoint delete \$sahara_endpoint_id
419 openstack service delete \$sahara_service_id
420
421 echo "Removing swift endpoint and service"
422 swift_service_id=\$(openstack service list | grep swift | cut -d ' ' -f 2)
423 swift_endpoint_id=\$(openstack endpoint list | grep swift | cut -d ' ' -f 2)
424 openstack endpoint delete \$swift_endpoint_id
425 openstack service delete \$swift_service_id
426
427 if [ "${deploy_options_array['congress']}" == 'True' ]; then
428     for s in nova neutronv2 ceilometer cinder glancev2 keystone; do
429         openstack congress datasource create \$s "\$s" \\
430             --config username=\$OS_USERNAME \\
431             --config tenant_name=\$OS_TENANT_NAME \\
432             --config password=\$OS_PASSWORD \\
433             --config auth_url=\$OS_AUTH_URL
434     done
435 fi
436 EOI
437
438   echo -e "${blue}INFO: Checking if OVS bridges have IP addresses...${reset}"
439   for network in ${opnfv_attach_networks}; do
440     ovs_ip=$(find_ip ${NET_MAP[$network]})
441     tmp_ip=''
442     if [ -n "$ovs_ip" ]; then
443       echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} has IP address ${ovs_ip}${reset}"
444     else
445       echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} missing IP, will configure${reset}"
446       # use last IP of allocation pool
447       eval "ip_range=\${${network}_usable_ip_range}"
448       ovs_ip=${ip_range##*,}
449       eval "net_cidr=\${${network}_cidr}"
450       sudo ip addr add ${ovs_ip}/${net_cidr##*/} dev ${NET_MAP[$network]}
451       sudo ip link set up ${NET_MAP[$network]}
452       tmp_ip=$(find_ip ${NET_MAP[$network]})
453       if [ -n "$tmp_ip" ]; then
454         echo -e "${blue}INFO: OVS Bridge ${NET_MAP[$network]} IP set: ${tmp_ip}${reset}"
455         continue
456       else
457         echo -e "${red}ERROR: Unable to set OVS Bridge ${NET_MAP[$network]} with IP: ${ovs_ip}${reset}"
458         return 1
459       fi
460     fi
461   done
462
463   # for virtual, we NAT public network through Undercloud
464   if [ "$virtual" == "TRUE" ]; then
465     if ! configure_undercloud_nat ${public_network_cidr}; then
466       echo -e "${red}ERROR: Unable to NAT undercloud with external net: ${public_network_cidr}${reset}"
467       exit 1
468     else
469       echo -e "${blue}INFO: Undercloud VM has been setup to NAT Overcloud public network${reset}"
470     fi
471   fi
472
473   # for sfc deployments we need the vxlan workaround
474   if [ "${deploy_options_array['sfc']}" == 'True' ]; then
475       ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
476 source stackrc
477 set -o errexit
478 for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
479 ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
480 sudo ifconfig br-int up
481 sudo ip route add 123.123.123.0/24 dev br-int
482 EOF
483 done
484 EOI
485   fi
486
487   # Collect deployment logs
488   ssh -T ${SSH_OPTIONS[@]} "stack@$UNDERCLOUD" <<EOI
489 mkdir -p ~/deploy_logs
490 rm -rf deploy_logs/*
491 source stackrc
492 set -o errexit
493 for node in \$(nova list | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"); do
494  ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
495  sudo cp /var/log/messages /home/heat-admin/messages.log
496  sudo chown heat-admin /home/heat-admin/messages.log
497 EOF
498 scp ${SSH_OPTIONS[@]} heat-admin@\$node:/home/heat-admin/messages.log ~/deploy_logs/\$node.messages.log
499 if [ "$debug" == "TRUE" ]; then
500     nova list --ip \$node
501     echo "---------------------------"
502     echo "-----/var/log/messages-----"
503     echo "---------------------------"
504     cat ~/deploy_logs/\$node.messages.log
505     echo "---------------------------"
506     echo "----------END LOG----------"
507     echo "---------------------------"
508 fi
509  ssh -T ${SSH_OPTIONS[@]} "heat-admin@\$node" <<EOF
510  sudo rm -f /home/heat-admin/messages.log
511 EOF
512 done
513
514 # Print out the undercloud IP and dashboard URL
515 source stackrc
516 echo "Undercloud IP: $UNDERCLOUD, please connect by doing 'opnfv-util undercloud'"
517 echo "Overcloud dashboard available at http://\$(heat output-show overcloud PublicVip | sed 's/"//g')/dashboard"
518 EOI
519
520 }
521
522 display_usage() {
523   echo -e "Usage:\n$0 [arguments] \n"
524   echo -e "   -d|--deploy-settings : Full path to deploy settings yaml file. Optional.  Defaults to null"
525   echo -e "   -i|--inventory : Full path to inventory yaml file. Required only for baremetal"
526   echo -e "   -n|--net-settings : Full path to network settings file. Optional."
527   echo -e "   -p|--ping-site : site to use to verify IP connectivity. Optional. Defaults to 8.8.8.8"
528   echo -e "   -v|--virtual : Virtualize overcloud nodes instead of using baremetal."
529   echo -e "   --flat : disable Network Isolation and use a single flat network for the underlay network."
530   echo -e "   --no-post-config : disable Post Install configuration."
531   echo -e "   --debug : enable debug output."
532   echo -e "   --interactive : enable interactive deployment mode which requires user to confirm steps of deployment."
533   echo -e "   --virtual-cpus : Number of CPUs to use per Overcloud VM in a virtual deployment (defaults to 4)."
534   echo -e "   --virtual-ram : Amount of RAM to use per Overcloud VM in GB (defaults to 8)."
535 }
536
537 ##translates the command line parameters into variables
538 ##params: $@ the entire command line is passed
539 ##usage: parse_cmd_line() "$@"
540 parse_cmdline() {
541   echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
542   echo "Use -h to display help"
543   sleep 2
544
545   while [ "${1:0:1}" = "-" ]
546   do
547     case "$1" in
548         -h|--help)
549                 display_usage
550                 exit 0
551             ;;
552         -d|--deploy-settings)
553                 DEPLOY_SETTINGS_FILE=$2
554                 echo "Deployment Configuration file: $2"
555                 shift 2
556             ;;
557         -i|--inventory)
558                 INVENTORY_FILE=$2
559                 shift 2
560             ;;
561         -n|--net-settings)
562                 NETSETS=$2
563                 echo "Network Settings Configuration file: $2"
564                 shift 2
565             ;;
566         -p|--ping-site)
567                 ping_site=$2
568                 echo "Using $2 as the ping site"
569                 shift 2
570             ;;
571         -v|--virtual)
572                 virtual="TRUE"
573                 echo "Executing a Virtual Deployment"
574                 shift 1
575             ;;
576         --flat )
577                 net_isolation_enabled="FALSE"
578                 echo "Underlay Network Isolation Disabled: using flat configuration"
579                 shift 1
580             ;;
581         --no-post-config )
582                 post_config="FALSE"
583                 echo "Post install configuration disabled"
584                 shift 1
585             ;;
586         --debug )
587                 debug="TRUE"
588                 echo "Enable debug output"
589                 shift 1
590             ;;
591         --interactive )
592                 interactive="TRUE"
593                 echo "Interactive mode enabled"
594                 shift 1
595             ;;
596         --virtual-cpus )
597                 VM_CPUS=$2
598                 echo "Number of CPUs per VM set to $VM_CPUS"
599                 shift 2
600             ;;
601         --virtual-ram )
602                 VM_RAM=$2
603                 echo "Amount of RAM per VM set to $VM_RAM"
604                 shift 2
605             ;;
606         --virtual-computes )
607                 VM_COMPUTES=$2
608                 echo "Virtual Compute nodes set to $VM_COMPUTES"
609                 shift 2
610             ;;
611         *)
612                 display_usage
613                 exit 1
614             ;;
615     esac
616   done
617
618   if [[ ! -z "$NETSETS" && "$net_isolation_enabled" == "FALSE" ]]; then
619     echo -e "${red}INFO: Single flat network requested. Only admin_network settings will be used!${reset}"
620   elif [[ -z "$NETSETS" ]]; then
621     echo -e "${red}ERROR: You must provide a network_settings file with -n.${reset}"
622     exit 1
623   fi
624
625   if [[ -n "$virtual" && -n "$INVENTORY_FILE" ]]; then
626     echo -e "${red}ERROR: You should not specify an inventory with virtual deployments${reset}"
627     exit 1
628   fi
629
630   if [[ -z "$DEPLOY_SETTINGS_FILE" || ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
631     echo -e "${red}ERROR: Deploy Settings: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
632     exit 1
633   fi
634
635   if [[ ! -z "$NETSETS" && ! -f "$NETSETS" ]]; then
636     echo -e "${red}ERROR: Network Settings: ${NETSETS} does not exist! Exiting...${reset}"
637     exit 1
638   fi
639
640   if [[ ! -z "$INVENTORY_FILE" && ! -f "$INVENTORY_FILE" ]]; then
641     echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
642     exit 1
643   fi
644
645   if [[ -z "$virtual" && -z "$INVENTORY_FILE" ]]; then
646     echo -e "${red}ERROR: You must specify an inventory file for baremetal deployments! Exiting...${reset}"
647     exit 1
648   fi
649
650   if [[ "$net_isolation_enabled" == "FALSE" && "$post_config" == "TRUE" ]]; then
651     echo -e "${blue}INFO: Post Install Configuration will be skipped.  It is not supported with --flat${reset}"
652     post_config="FALSE"
653   fi
654
655 }
656
657 ##END FUNCTIONS
658
659 main() {
660   parse_cmdline "$@"
661   echo -e "${blue}INFO: Parsing network settings file...${reset}"
662   parse_network_settings
663   if ! configure_deps; then
664     echo -e "${red}Dependency Validation Failed, Exiting.${reset}"
665     exit 1
666   fi
667   if [ -n "$DEPLOY_SETTINGS_FILE" ]; then
668     echo -e "${blue}INFO: Parsing deploy settings file...${reset}"
669     parse_deploy_settings
670   fi
671   setup_undercloud_vm
672   if [ "$virtual" == "TRUE" ]; then
673     setup_virtual_baremetal $VM_CPUS $VM_RAM
674   elif [ -n "$INVENTORY_FILE" ]; then
675     parse_inventory_file
676   fi
677   configure_undercloud
678   undercloud_prep_overcloud_deploy
679   if [ "$post_config" == "TRUE" ]; then
680     if ! configure_post_install; then
681       echo -e "${red}ERROR:Post Install Configuration Failed, Exiting.${reset}"
682       exit 1
683     else
684       echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
685     fi
686   fi
687   if [[ "${deploy_options_array['sdn_controller']}" == 'onos' ]]; then
688     if ! onos_update_gw_mac ${public_network_cidr} ${public_network_gateway}; then
689       echo -e "${red}ERROR:ONOS Post Install Configuration Failed, Exiting.${reset}"
690       exit 1
691     else
692       echo -e "${blue}INFO: ONOS Post Install Configuration Complete${reset}"
693     fi
694   fi
695 }
696
697 main "$@"