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