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