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