Splitting post-install into 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/overcloud-deploy-functions.sh
66 $LIB/post-install-functions.sh
67 $LIB/utility-functions.sh
68 $LIB/installer/onos/onos_gw_mac_update.sh
69 )
70 for lib_file in ${lib_files[@]}; do
71   if ! source $lib_file; then
72     echo -e "${red}ERROR: Failed to source $lib_file${reset}"
73     exit 1
74   fi
75 done
76
77 ##FUNCTIONS
78 ##checks if prefix exists in string
79 ##params: string, prefix
80 ##usage: contains_prefix "deploy_setting_launcher=1" "deploy_setting"
81 contains_prefix() {
82   local mystr=$1
83   local prefix=$2
84   if echo $mystr | grep -E "^$prefix.*$" > /dev/null; then
85     return 0
86   else
87     return 1
88   fi
89 }
90
91 ##verify internet connectivity
92 #params: none
93 function verify_internet {
94   if ping -c 2 $ping_site > /dev/null; then
95     if ping -c 2 www.google.com > /dev/null; then
96       echo "${blue}Internet connectivity detected${reset}"
97       return 0
98     else
99       echo "${red}Internet connectivity detected, but DNS lookup failed${reset}"
100       return 1
101     fi
102   else
103     echo "${red}No internet connectivity detected${reset}"
104     return 1
105   fi
106 }
107
108 display_usage() {
109   echo -e "Usage:\n$0 [arguments] \n"
110   echo -e "   -d|--deploy-settings : Full path to deploy settings yaml file. Optional.  Defaults to null"
111   echo -e "   -i|--inventory : Full path to inventory yaml file. Required only for baremetal"
112   echo -e "   -n|--net-settings : Full path to network settings file. Optional."
113   echo -e "   -p|--ping-site : site to use to verify IP connectivity. Optional. Defaults to 8.8.8.8"
114   echo -e "   -v|--virtual : Virtualize overcloud nodes instead of using baremetal."
115   echo -e "   --flat : disable Network Isolation and use a single flat network for the underlay network."
116   echo -e "   --no-post-config : disable Post Install configuration."
117   echo -e "   --debug : enable debug output."
118   echo -e "   --interactive : enable interactive deployment mode which requires user to confirm steps of deployment."
119   echo -e "   --virtual-cpus : Number of CPUs to use per Overcloud VM in a virtual deployment (defaults to 4)."
120   echo -e "   --virtual-ram : Amount of RAM to use per Overcloud VM in GB (defaults to 8)."
121 }
122
123 ##translates the command line parameters into variables
124 ##params: $@ the entire command line is passed
125 ##usage: parse_cmd_line() "$@"
126 parse_cmdline() {
127   echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
128   echo "Use -h to display help"
129   sleep 2
130
131   while [ "${1:0:1}" = "-" ]
132   do
133     case "$1" in
134         -h|--help)
135                 display_usage
136                 exit 0
137             ;;
138         -d|--deploy-settings)
139                 DEPLOY_SETTINGS_FILE=$2
140                 echo "Deployment Configuration file: $2"
141                 shift 2
142             ;;
143         -i|--inventory)
144                 INVENTORY_FILE=$2
145                 shift 2
146             ;;
147         -n|--net-settings)
148                 NETSETS=$2
149                 echo "Network Settings Configuration file: $2"
150                 shift 2
151             ;;
152         -p|--ping-site)
153                 ping_site=$2
154                 echo "Using $2 as the ping site"
155                 shift 2
156             ;;
157         -v|--virtual)
158                 virtual="TRUE"
159                 echo "Executing a Virtual Deployment"
160                 shift 1
161             ;;
162         --flat )
163                 net_isolation_enabled="FALSE"
164                 echo "Underlay Network Isolation Disabled: using flat configuration"
165                 shift 1
166             ;;
167         --no-post-config )
168                 post_config="FALSE"
169                 echo "Post install configuration disabled"
170                 shift 1
171             ;;
172         --debug )
173                 debug="TRUE"
174                 echo "Enable debug output"
175                 shift 1
176             ;;
177         --interactive )
178                 interactive="TRUE"
179                 echo "Interactive mode enabled"
180                 shift 1
181             ;;
182         --virtual-cpus )
183                 VM_CPUS=$2
184                 echo "Number of CPUs per VM set to $VM_CPUS"
185                 shift 2
186             ;;
187         --virtual-ram )
188                 VM_RAM=$2
189                 echo "Amount of RAM per VM set to $VM_RAM"
190                 shift 2
191             ;;
192         --virtual-computes )
193                 VM_COMPUTES=$2
194                 echo "Virtual Compute nodes set to $VM_COMPUTES"
195                 shift 2
196             ;;
197         *)
198                 display_usage
199                 exit 1
200             ;;
201     esac
202   done
203
204   if [[ ! -z "$NETSETS" && "$net_isolation_enabled" == "FALSE" ]]; then
205     echo -e "${red}INFO: Single flat network requested. Only admin_network settings will be used!${reset}"
206   elif [[ -z "$NETSETS" ]]; then
207     echo -e "${red}ERROR: You must provide a network_settings file with -n.${reset}"
208     exit 1
209   fi
210
211   if [[ -n "$virtual" && -n "$INVENTORY_FILE" ]]; then
212     echo -e "${red}ERROR: You should not specify an inventory with virtual deployments${reset}"
213     exit 1
214   fi
215
216   if [[ -z "$DEPLOY_SETTINGS_FILE" || ! -f "$DEPLOY_SETTINGS_FILE" ]]; then
217     echo -e "${red}ERROR: Deploy Settings: ${DEPLOY_SETTINGS_FILE} does not exist! Exiting...${reset}"
218     exit 1
219   fi
220
221   if [[ ! -z "$NETSETS" && ! -f "$NETSETS" ]]; then
222     echo -e "${red}ERROR: Network Settings: ${NETSETS} does not exist! Exiting...${reset}"
223     exit 1
224   fi
225
226   if [[ ! -z "$INVENTORY_FILE" && ! -f "$INVENTORY_FILE" ]]; then
227     echo -e "{$red}ERROR: Inventory File: ${INVENTORY_FILE} does not exist! Exiting...${reset}"
228     exit 1
229   fi
230
231   if [[ -z "$virtual" && -z "$INVENTORY_FILE" ]]; then
232     echo -e "${red}ERROR: You must specify an inventory file for baremetal deployments! Exiting...${reset}"
233     exit 1
234   fi
235
236   if [[ "$net_isolation_enabled" == "FALSE" && "$post_config" == "TRUE" ]]; then
237     echo -e "${blue}INFO: Post Install Configuration will be skipped.  It is not supported with --flat${reset}"
238     post_config="FALSE"
239   fi
240
241 }
242
243 ##END FUNCTIONS
244
245 main() {
246   parse_cmdline "$@"
247   echo -e "${blue}INFO: Parsing network settings file...${reset}"
248   parse_network_settings
249   if ! configure_deps; then
250     echo -e "${red}Dependency Validation Failed, Exiting.${reset}"
251     exit 1
252   fi
253   if [ -n "$DEPLOY_SETTINGS_FILE" ]; then
254     echo -e "${blue}INFO: Parsing deploy settings file...${reset}"
255     parse_deploy_settings
256   fi
257   setup_undercloud_vm
258   if [ "$virtual" == "TRUE" ]; then
259     setup_virtual_baremetal $VM_CPUS $VM_RAM
260   elif [ -n "$INVENTORY_FILE" ]; then
261     parse_inventory_file
262   fi
263   configure_undercloud
264   overcloud_deploy
265   if [ "$post_config" == "TRUE" ]; then
266     if ! configure_post_install; then
267       echo -e "${red}ERROR:Post Install Configuration Failed, Exiting.${reset}"
268       exit 1
269     else
270       echo -e "${blue}INFO: Post Install Configuration Complete${reset}"
271     fi
272   fi
273   if [[ "${deploy_options_array['sdn_controller']}" == 'onos' ]]; then
274     if ! onos_update_gw_mac ${public_network_cidr} ${public_network_gateway}; then
275       echo -e "${red}ERROR:ONOS Post Install Configuration Failed, Exiting.${reset}"
276       exit 1
277     else
278       echo -e "${blue}INFO: ONOS Post Install Configuration Complete${reset}"
279     fi
280   fi
281 }
282
283 main "$@"