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