9affa80aeabbbcbffc40691df169ffe06b6d3e3b
[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 post_config="TRUE"
29 debug="FALSE"
30
31 ovs_rpm_name=openvswitch-2.5.90-1.el7.centos.x86_64.rpm
32 ovs_kmod_rpm_name=openvswitch-kmod-2.5.90-1.el7.centos.x86_64.rpm
33
34 declare -i CNT
35 declare UNDERCLOUD
36 declare -A deploy_options_array
37 declare -a performance_options
38 declare -A NET_MAP
39
40 APEX_TMP_DIR=$(python3 -c "import tempfile; print(tempfile.mkdtemp())")
41 SSH_OPTIONS=(-o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null -o LogLevel=error)
42 DEPLOY_OPTIONS=""
43 CONFIG=${CONFIG:-'/var/opt/opnfv'}
44 RESOURCES=${RESOURCES:-"$CONFIG/images"}
45 LIB=${LIB:-"$CONFIG/lib"}
46 OPNFV_NETWORK_TYPES="admin tenant external storage api"
47
48 VM_CPUS=4
49 VM_RAM=8
50 VM_COMPUTES=1
51
52 # Netmap used to map networks to OVS bridge names
53 NET_MAP['admin']="br-admin"
54 NET_MAP['tenant']="br-tenant"
55 NET_MAP['external']="br-external"
56 NET_MAP['storage']="br-storage"
57 NET_MAP['api']="br-api"
58 ext_net_type="interface"
59 ip_address_family=4
60
61 # Libraries
62 lib_files=(
63 $LIB/common-functions.sh
64 $LIB/configure-deps-functions.sh
65 $LIB/parse-functions.sh
66 $LIB/virtual-setup-functions.sh
67 $LIB/undercloud-functions.sh
68 $LIB/overcloud-deploy-functions.sh
69 $LIB/post-install-functions.sh
70 $LIB/utility-functions.sh
71 $LIB/installer/onos/onos_gw_mac_update.sh
72 )
73 for lib_file in ${lib_files[@]}; do
74   if ! source $lib_file; then
75     echo -e "${red}ERROR: Failed to source $lib_file${reset}"
76     exit 1
77   fi
78 done
79
80 display_usage() {
81   echo -e "Usage:\n$0 [arguments] \n"
82   echo -e "   --deploy-settings | -d : Full path to deploy settings yaml file. Optional.  Defaults to null"
83   echo -e "   --inventory | -i : Full path to inventory yaml file. Required only for baremetal"
84   echo -e "   --net-settings | -n : Full path to network settings file. Optional."
85   echo -e "   --ping-site | -p : site to use to verify IP connectivity. Optional. Defaults to 8.8.8.8"
86   echo -e "   --virtual | -v : Virtualize overcloud nodes instead of using baremetal."
87   echo -e "   --flat : disable Network Isolation and use a single flat network for the underlay network."
88   echo -e "   --no-post-config : disable Post Install configuration."
89   echo -e "   --debug : enable debug output."
90   echo -e "   --interactive : enable interactive deployment mode which requires user to confirm steps of deployment."
91   echo -e "   --virtual-cpus : Number of CPUs to use per Overcloud VM in a virtual deployment (defaults to 4)."
92   echo -e "   --virtual-ram : Amount of RAM to use per Overcloud VM in GB (defaults to 8)."
93 }
94
95 ##translates the command line parameters into variables
96 ##params: $@ the entire command line is passed
97 ##usage: parse_cmd_line() "$@"
98 parse_cmdline() {
99   echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
100   echo "Use -h to display help"
101
102   while [ "${1:0:1}" = "-" ]
103   do
104     case "$1" in
105         -h|--help)
106                 display_usage
107                 exit 0
108             ;;
109         -d|--deploy-settings)
110                 DEPLOY_SETTINGS_FILE=$2
111                 echo "Deployment Configuration file: $2"
112                 shift 2
113             ;;
114         -i|--inventory)
115                 INVENTORY_FILE=$2
116                 shift 2
117             ;;
118         -n|--net-settings)
119                 NETSETS=$2
120                 echo "Network Settings Configuration file: $2"
121                 shift 2
122             ;;
123         -p|--ping-site)
124                 ping_site=$2
125                 echo "Using $2 as the ping site"
126                 shift 2
127             ;;
128         -v|--virtual)
129                 virtual="TRUE"
130                 echo "Executing a Virtual Deployment"
131                 shift 1
132             ;;
133         --no-post-config )
134                 post_config="FALSE"
135                 echo "Post install configuration disabled"
136                 shift 1
137             ;;
138         --debug )
139                 debug="TRUE"
140                 echo "Enable debug output"
141                 shift 1
142             ;;
143         --interactive )
144                 interactive="TRUE"
145                 echo "Interactive mode enabled"
146                 shift 1
147             ;;
148         --virtual-cpus )
149                 VM_CPUS=$2
150                 echo "Number of CPUs per VM set to $VM_CPUS"
151                 shift 2
152             ;;
153         --virtual-ram )
154                 VM_RAM=$2
155                 echo "Amount of RAM per VM set to $VM_RAM"
156                 shift 2
157             ;;
158         --virtual-computes )
159                 VM_COMPUTES=$2
160                 echo "Virtual Compute nodes set to $VM_COMPUTES"
161                 shift 2
162             ;;
163         *)
164                 display_usage
165                 exit 1
166             ;;
167     esac
168   done
169   sleep 2
170
171   if [[ -z "$NETSETS" ]]; then
172     echo -e "${red}ERROR: You must provide a network_settings file with -n.${reset}"
173     exit 1
174   fi
175
176   # inventory file usage validation
177   if [[ -n "$virtual" ]]; then
178       if [[ -n "$INVENTORY_FILE" ]]; then
179           echo -e "${red}ERROR: You should not specify an inventory file with virtual deployments${reset}"
180           exit 1
181       else
182           INVENTORY_FILE="$APEX_TMP_DIR/inventory-virt.yaml"
183       fi
184   elif [[ -z "$INVENTORY_FILE" ]]; then
185     echo -e "${red}ERROR: You must specify an inventory file for baremetal deployments! Exiting...${reset}"
186     exit 1
187   elif [[ ! -f "$INVENTORY_FILE" ]]; then
188     echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
189     exit 1
190   fi
191
192   if [[ -z "$DEPLOY_SETTINGS_FILE" || ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
193     echo -e "${red}ERROR: Deploy Settings: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
194     exit 1
195   fi
196
197   if [[ ! -z "$NETSETS" && ! -f "$NETSETS" ]]; then
198     echo -e "${red}ERROR: Network Settings: ${NETSETS} does not exist! Exiting...${reset}"
199     exit 1
200   fi
201
202 }
203
204 main() {
205   parse_cmdline "$@"
206   if [ -n "$DEPLOY_SETTINGS_FILE" ]; then
207     echo -e "${blue}INFO: Parsing deploy settings file...${reset}"
208     parse_deploy_settings
209   fi
210   echo -e "${blue}INFO: Parsing network settings file...${reset}"
211   parse_network_settings
212   if ! configure_deps; then
213     echo -e "${red}Dependency Validation Failed, Exiting.${reset}"
214     exit 1
215   fi
216   #Correct the time on the server prior to launching any VMs
217   if ntpdate $ntp_server; then
218     hwclock --systohc
219   else
220     echo "${blue}WARNING: ntpdate failed to update the time on the server. ${reset}"
221   fi
222   setup_undercloud_vm
223   if [ "$virtual" == "TRUE" ]; then
224     setup_virtual_baremetal $VM_CPUS $VM_RAM
225   fi
226   parse_inventory_file
227   configure_undercloud
228   overcloud_deploy
229   if [ "$post_config" == "TRUE" ]; then
230     if ! configure_post_install; then
231       echo -e "${red}ERROR:Post Install Configuration Failed, Exiting.${reset}"
232       exit 1
233     else
234       echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
235     fi
236   fi
237   if [[ "${deploy_options_array['sdn_controller']}" == 'onos' ]]; then
238     if ! onos_update_gw_mac ${external_cidr} ${external_gateway}; then
239       echo -e "${red}ERROR:ONOS Post Install Configuration Failed, Exiting.${reset}"
240       exit 1
241     else
242       echo -e "${blue}INFO: ONOS Post Install Configuration Complete${reset}"
243     fi
244   fi
245 }
246
247 main "$@"