blob: b998651452b7c019638376b7e3373ea4a9fdd8e5 [file] [log] [blame]
stark, steven6754bc12019-09-19 15:43:00 -07001#!/bin/bash
2# Copyright 2019 AT&T Intellectual Property. All rights reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
17
18NO_PROMPT=0
19NO_INSTALL=0
stark, stevenf3519422019-12-05 14:14:32 -080020NO_VALIDATE=0
21POST_INSTALL=0
stark, steven6754bc12019-09-19 15:43:00 -070022OVERRIDE=0
23
24OPENSTACK_CLI_POD="os-cli-0"
25
26if [ ! -f $DIR/cloud.conf ]; then
27 echo "cloud.conf not found, exiting..."
28 exit 1
29fi
30
31. $DIR/cloud.conf
32
33while test $# -gt 0; do
34 case "$1" in
35 -h|--help)
36 echo "./cloud.sh [options]"
37 echo " "
38 echo " "
39 echo "options:"
40 echo "-f, --no-prompt executes with no prompt for confirmation"
41 echo "-n, --no-install don't install ONAP"
42 echo "-o, --override create integration override for robot configuration"
stark, stevenf3519422019-12-05 14:14:32 -080043 echo "-d, --no-validate dont validate pre-reqs before executing deployment"
44 echo "-p, --post-install execute post-install scripts"
stark, steven6754bc12019-09-19 15:43:00 -070045 echo "-h, --help provide brief overview of script"
46 echo " "
47 echo "This script deploys a cloud environment in Azure."
48 echo "It: "
49 echo "- Uses Azure Kubernetes Service (AKS) to bootstrap a kubernetes cluster."
50 echo "- Creates a VM with an external disk to be used as NFS storage."
51 echo "- Creates a VM and installs DevStack, to be used with ONAP."
52 echo "- Launches ONAP onto the AKS Cluster via OOM."
53 echo "- Configures Networking, SSH Access, and Security Group Rules"
54 echo ""
55 exit 0
56 ;;
57 -f|--no-prompt)
58 shift
59 NO_PROMPT=1
60 ;;
61 -n|--no-install)
62 shift
63 NO_INSTALL=1
64 ;;
65 -o|--override)
66 shift
67 OVERRIDE=1
68 ;;
stark, stevenf3519422019-12-05 14:14:32 -080069 -d|--no-validate)
70 shift
71 NO_VALIDATE=1
72 ;;
73 -p|--post-install)
74 shift
75 POST_INSTALL=1
76 ;;
stark, steven6754bc12019-09-19 15:43:00 -070077 *)
78 echo "Unknown Argument. Try running with --help ."
79 exit 0
80 ;;
81 esac
82done
83
stark, stevenf3519422019-12-05 14:14:32 -080084if [ $NO_VALIDATE = 0 ]; then
85 $DIR/pre_install.sh "$AKS_K8_VERSION" "$LOCATION"
86 if [ $? -ne 0 ]; then
87 exit 1
88 fi
89fi
90
stark, steven6754bc12019-09-19 15:43:00 -070091cat <<EOF
92
93Here are the parameters to be used in this build:
94
95# GLOBAL PARAMS
96LOCATION = "$LOCATION"
97USER_PUBLIC_IP_PREFIX = "$USER_PUBLIC_IP_PREFIX"
98BUILD_DIR = "$BUILD_DIR"
99
100# AKS PARAMS
101AKS_RESOURCE_GROUP_NAME = "$AKS_RESOURCE_GROUP_NAME"
102AKS_NAME = "$AKS_NAME"
103AKS_K8_VERSION = "$AKS_K8_VERSION"
104AKS_NODE_COUNT = "$AKS_NODE_COUNT"
105AKS_NODE_SIZE = "$AKS_NODE_SIZE"
106AKS_DNS_PREFIX = "$AKS_DNS_PREFIX"
107AKS_POD_CIDR = "$AKS_POD_CIDR"
108AKS_NODE_CIDR = "$AKS_NODE_CIDR"
109AKS_SERVICE_CIDR = "$AKS_SERVICE_CIDR"
110AKS_DNS_IP = "$AKS_DNS_IP"
111AKS_VNET_NAME = "$AKS_VNET_NAME"
112AKS_ADMIN_USER= = "$AKS_ADMIN_USER"
113
114# NFS PARAMS
115NFS_NAME = "$NFS_NAME"
116NFS_RG = "$NFS_RG"
117NFS_VM_SIZE = "$NFS_VM_SIZE"
118NFS_LOCATION = "$NFS_LOCATION"
119NFS_CIDR = "$NFS_CIDR"
120NFS_ADMIN_USER = "$NFS_ADMIN_USER"
121NFS_VNET_NAME = "$NFS_VNET_NAME"
122NFS_SUBNET_NAME = "$NFS_SUBNET_NAME"
123NFS_DISK_SIZE = "$NFS_DISK_SIZE"
124
125# DEVSTACK PARAMS
126DEVSTACK_NAME = "$DEVSTACK_NAME"
127DEVSTACK_RG = "$DEVSTACK_RG"
128DEVSTACK_VM_SIZE = "$DEVSTACK_VM_SIZE"
129DEVSTACK_LOCATION = "$DEVSTACK_LOCATION"
130DEVSTACK_CIDR = "$DEVSTACK_CIDR"
131DEVSTACK_PRIVATE_IP = "$DEVSTACK_PRIVATE_IP"
132DEVSTACK_ADMIN_USER = "$DEVSTACK_ADMIN_USER"
133DEVSTACK_VNET_NAME = "$DEVSTACK_VNET_NAME"
134DEVSTACK_SUBNET_NAME = "$DEVSTACK_SUBNET_NAME"
135DEVSTACK_DISK_SIZE = "$DEVSTACK_DISK_SIZE"
stark, steven0e111712020-01-29 17:01:48 -0800136DEVSTACK_BRANCH = "$DEVSTACK_BRANCH"
stark, steven6754bc12019-09-19 15:43:00 -0700137OPENSTACK_USER = "$OPENSTACK_USER"
138OPENSTACK_PASS = "$OPENSTACK_PASS"
139OPENSTACK_TENANT = "$OPENSTACK_TENANT"
140IMAGE_LIST = "$IMAGE_LIST"
141
142# ONAP PARAMS
143CLLI = "$CLLI"
144CLOUD_OWNER = "$CLOUD_OWNER"
145CLOUD_REGION = "$CLOUD_REGION"
146CUSTOMER = "$CUSTOMER"
147SUBSCRIBER = "$SUBSCRIBER"
148SERVICE_TYPE = "$SERVICE_TYPE"
149AZ = "$AZ"
150OE = "$OE"
151LOB = "$LOB"
152PLATFORM = "$PLATFORM"
153OS_ID = "$OS_ID"
154OS_TENANT_ROLE = "$OS_TENANT_ROLE"
155OS_KEYSTONE = "$OS_KEYSTONE"
156OPENSTACK_REGION = "$OPENSTACK_REGION"
157PROJECT = "$PROJECT"
158OOM_BRANCH = "$OOM_BRANCH"
159CHART_VERSION = "$CHART_VERSION"
160OOM_OVERRIDES = "$OOM_OVERRIDES"
161DOCKER_REPOSITORY = "$DOCKER_REPOSITORY"
162
163EOF
164
165if [ $NO_PROMPT = 0 ]; then
166 read -p "Would you like to proceed? [y/n]" -n 1 -r
167 echo " "
168 if [[ ! $REPLY =~ ^[Yy]$ ]]
169 then
170 exit 0
171 fi
172fi
173
174echo "Starting instantiation. This will take a little while..."
175sleep 3
176
177set -x
178set -e
179
180mkdir -p $BUILD_DIR
181
182echo "#!/bin/bash" > $BUILD_DIR/clean.sh
183echo "" >> $BUILD_DIR/clean.sh
184chmod 755 $BUILD_DIR/clean.sh
185
186ssh-keygen -t rsa -N "" -f $BUILD_DIR/id_rsa
187
188PUBLIC_KEY=$BUILD_DIR/id_rsa.pub
189PRIVATE_KEY=$BUILD_DIR/id_rsa
190
191
192echo "az group delete --resource-group $DEVSTACK_RG --yes" >> $BUILD_DIR/clean.sh
193echo "" >> $BUILD_DIR/clean.sh
194
195echo "Creating DEVSTACK Server $DEVSTACK_NAME in $LOCATION"
196$DIR/create_devstack.sh --name "$DEVSTACK_NAME" \
197 --resource-group "$DEVSTACK_RG" \
198 --size "$DEVSTACK_VM_SIZE" \
199 --location "$DEVSTACK_LOCATION" \
200 --cidr "$DEVSTACK_CIDR" \
201 --admin-user "$DEVSTACK_ADMIN_USER" \
202 --directory "$BUILD_DIR" \
203 --vnet-name "$DEVSTACK_VNET_NAME" \
204 --public-key "$PUBLIC_KEY" \
205 --user-public-ip "$USER_PUBLIC_IP_PREFIX" \
206 --devstack-private-ip "$DEVSTACK_PRIVATE_IP" \
207 --devstack-subnet-name "$DEVSTACK_SUBNET_NAME" \
208 --devstack-disk-size "$DEVSTACK_DISK_SIZE" \
209 --openstack-username "$OPENSTACK_USER" \
210 --openstack-password "$OPENSTACK_PASS" \
211 --openstack-tenant "$OPENSTACK_TENANT" \
212 --image-list "$IMAGE_LIST" \
stark, steven0e111712020-01-29 17:01:48 -0800213 --devstack-branch "$DEVSTACK_BRANCH" \
stark, steven6754bc12019-09-19 15:43:00 -0700214 --no-prompt
215
216
217echo "az group delete --resource-group $NFS_RG --yes" >> $BUILD_DIR/clean.sh
218echo "" >> $BUILD_DIR/clean.sh
219
220echo "Creating NFS Server $NFS_NAME in $LOCATION"
221$DIR/create_nfs.sh --name "$NFS_NAME" \
222 --resource-group "$NFS_RG" \
223 --size "$NFS_VM_SIZE" \
224 --location "$NFS_LOCATION" \
225 --cidr "$NFS_CIDR" \
226 --admin-user "$NFS_ADMIN_USER" \
227 --directory "$BUILD_DIR" \
228 --vnet-name "$NFS_VNET_NAME" \
229 --public-key "$PUBLIC_KEY" \
230 --user-public-ip "$USER_PUBLIC_IP_PREFIX" \
231 --nfs-subnet-name "$NFS_SUBNET_NAME" \
232 --aks-node-cidr "$AKS_NODE_CIDR" \
233 --nfs-disk-size "$NFS_DISK_SIZE" \
234 --no-prompt
235
236
237echo "az group delete --resource-group $AKS_RESOURCE_GROUP_NAME --yes" >> $BUILD_DIR/clean.sh
238echo "" >> $BUILD_DIR/clean.sh
239
240echo "Creating AKS $AKS_NAME in $LOCATION"
241$DIR/create_aks.sh --name "$AKS_NAME" \
242 --resource-group "$AKS_RESOURCE_GROUP_NAME" \
243 --kube-version "$AKS_K8_VERSION" \
244 --location "$LOCATION" \
245 --node-count "$AKS_NODE_COUNT" \
246 --size "$AKS_NODE_SIZE" \
247 --service-cidr "$AKS_SERVICE_CIDR" \
248 --pod-cidr "$AKS_POD_CIDR" \
249 --dns-ip "$AKS_DNS_IP" \
250 --node-cidr "$AKS_NODE_CIDR" \
251 --vnet-name "$AKS_VNET_NAME" \
252 --user-public-ip "$USER_PUBLIC_IP_PREFIX" \
253 --public-key "$PUBLIC_KEY" \
254 --admin-user "$AKS_ADMIN_USER" \
255 --no-prompt
256
257
258AKS_MANAGEMENT_RESOURCE_GROUP_NAME=`az group list --query "[?starts_with(name, 'MC_${AKS_RESOURCE_GROUP_NAME}')].name | [0]" --output tsv`
259AKS_VNET_ID=`az network vnet show --resource-group ${AKS_RESOURCE_GROUP_NAME} --name ${AKS_VNET_NAME} --query 'id' --output tsv`
260NFS_VNET_ID=`az network vnet show --name ${NFS_VNET_NAME} --resource-group ${NFS_RG} --query "id" --output tsv`
261DEVSTACK_VNET_ID=`az network vnet show --name ${DEVSTACK_VNET_NAME} --resource-group ${DEVSTACK_RG} --query "id" --output tsv`
262AKS_ROUTE_TABLE_NAME=`az resource list --resource-group ${AKS_MANAGEMENT_RESOURCE_GROUP_NAME} --resource-type "Microsoft.Network/routeTables" --query "[0] | name" --output tsv`
263DEVSTACK_PRIVATE_IP=`az vm show --name ${DEVSTACK_NAME} --resource-group ${DEVSTACK_RG} -d --query "privateIps" --output tsv`
264NFS_PRIVATE_IP=`az vm show --name ${NFS_NAME} --resource-group ${NFS_RG} -d --query "privateIps" --output tsv`
265NFS_PUBLIC_IP=`az vm show --name ${NFS_NAME} --resource-group ${NFS_RG} -d --query "publicIps" --output tsv`
266DEVSTACK_PUBLIC_IP=`az vm show --name ${DEVSTACK_NAME} --resource-group ${DEVSTACK_RG} -d --query "publicIps" --output tsv`
267
268# adding public ip to aks
269NIC_NAME0=`az resource list --resource-group ${AKS_MANAGEMENT_RESOURCE_GROUP_NAME} --resource-type "Microsoft.Network/networkInterfaces" --query "[0] | name" --output tsv`
270AKS_NSG_NAME=`az resource list --resource-group ${AKS_MANAGEMENT_RESOURCE_GROUP_NAME} --resource-type "Microsoft.Network/networkSecurityGroups" --query "[0] | name" --output tsv`
271$DIR/create_public_ip.sh "AKSPUBLICIP1" "$AKS_MANAGEMENT_RESOURCE_GROUP_NAME" "$NIC_NAME0"
272$DIR/create_sg_rule.sh "$AKS_MANAGEMENT_RESOURCE_GROUP_NAME" "$AKS_NSG_NAME" '*' "30000-32000" "$USER_PUBLIC_IP_PREFIX" '*' '*' "ONAP" "120"
273
274AKS_PUBLIC_IP_ADDRESS=`az network public-ip show --resource-group ${AKS_MANAGEMENT_RESOURCE_GROUP_NAME} -n AKSPUBLICIP1 --query "ipAddress" --output tsv`
275
276### Peering networks ###
277# peering requires source = VNet NAME, destination = VNet ID
278
279echo "creating peering from AKS Vnet to NFS Vnet..."
280$DIR/create_peering.sh "$AKS_VNET_NAME" \
281 "$AKS_RESOURCE_GROUP_NAME" \
282 "$NFS_VNET_ID" \
283 "kube-to-nfs"
284
285echo "creating peering from AKS Vnet to Devstack Vnet..."
286$DIR/create_peering.sh "$AKS_VNET_NAME" \
287 "$AKS_RESOURCE_GROUP_NAME" \
288 "$DEVSTACK_VNET_ID" \
289 "kube-to-devstack"
290
291echo "creating peering from NFS Vnet to AKS Vnet..."
292$DIR/create_peering.sh "$NFS_VNET_NAME" \
293 "$NFS_RG" \
294 "$AKS_VNET_ID" \
295 "nfs-to-kube"
296
297echo "creating peering from NFS Vnet to AKS Vnet..."
298$DIR/create_peering.sh "$DEVSTACK_VNET_NAME" \
299 "$DEVSTACK_RG" \
300 "$AKS_VNET_ID" \
301 "devstack-to-kube"
302
303
304### Adding next hop to kubernetes for devstack ###
305echo "creating route from AKS Vnet to Devstack Vnet..."
306$DIR/create_route.sh "$DEVSTACK_CIDR" \
307 "guestvms" \
308 "$AKS_MANAGEMENT_RESOURCE_GROUP_NAME" \
309 "$AKS_ROUTE_TABLE_NAME" \
310 "$DEVSTACK_PRIVATE_IP"
311
312
313
314# TODO
315# Lets find a better place for this
316az aks get-credentials --resource-group "$AKS_RESOURCE_GROUP_NAME" \
317 --name "$AKS_NAME" \
318 --file "$BUILD_DIR"/"kubeconfig"
319
320$DIR/configure_nfs_pod.sh "$PRIVATE_KEY" \
321 "$BUILD_DIR"/"kubeconfig" \
322 "$NFS_PRIVATE_IP" \
323 "$AKS_ADMIN_USER"
324
325# TODO
326# add this to post-install or post-configure phase
327# to support adding multiple devstacks to same ONAP
328cat > "$BUILD_DIR/openstack_rc" <<EOF
329export OS_USERNAME="$OPENSTACK_USER"
330export OS_PROJECT_NAME="$OPENSTACK_TENANT"
331export OS_AUTH_URL="http://$DEVSTACK_PRIVATE_IP/identity"
332export OS_PASSWORD="$OPENSTACK_PASS"
333export OS_USER_DOMAIN_NAME=default
334export OS_PROJECT_DOMAIN_ID=default
335EOF
336
337$DIR/util/create_openstack_cli.sh "$BUILD_DIR/kubeconfig" \
338 "$BUILD_DIR/openstack_rc" \
339 "$OPENSTACK_CLI_POD"
340
stark, stevenf3519422019-12-05 14:14:32 -0800341
stark, steven6754bc12019-09-19 15:43:00 -0700342if [ $OVERRIDE = 1 ]; then
343
344$DIR/util/create_integration_override.sh "$BUILD_DIR" \
345 "$OPENSTACK_CLI_POD" \
346 "$BUILD_DIR/openstack_rc" \
347 "$DOCKER_REPOSITORY" \
348 "$NFS_PRIVATE_IP" \
349 "$AKS_PUBLIC_IP_ADDRESS" \
350 "$BUILD_DIR/kubeconfig"
351
352fi
353
stark, stevenf3519422019-12-05 14:14:32 -0800354
stark, steven6754bc12019-09-19 15:43:00 -0700355if [ $NO_INSTALL = 0 ]; then
356
357### Starting OOM install ###
358echo "Installing ONAP..."
359$DIR/create_onap.sh "$BUILD" \
360 "$BUILD_DIR/kubeconfig" \
stark, steven6754bc12019-09-19 15:43:00 -0700361 "$OOM_BRANCH" \
362 "$BUILD_DIR" \
363 "$CHART_VERSION" \
364 "$OOM_OVERRIDES"
365
stark, steven6754bc12019-09-19 15:43:00 -0700366fi
367
stark, stevenf3519422019-12-05 14:14:32 -0800368
stark, steven6754bc12019-09-19 15:43:00 -0700369set +x
370
371cat > "$BUILD_DIR/deployment.notes" <<EOF
372==================================================================
373Phew, all done (yay!). ONAP and DevStack might still be installing
374but here are the access details...
375
376--------DEVSTACK ACCESS--------
377ssh -i ${PRIVATE_KEY} ${DEVSTACK_ADMIN_USER}@${DEVSTACK_PUBLIC_IP}
378horizon: http://${DEVSTACK_PUBLIC_IP}
379cli: kubectl exec $OPENSTACK_CLI_POD -- sh -lc "<openstack command>"
380
381--------NFS ACCESS--------
382ssh -i ${PRIVATE_KEY} ${NFS_ADMIN_USER}@${NFS_PUBLIC_IP}
383
384--------KUBERNETES ACCESS--------
385kubeconfig: export KUBECONFIG=$BUILD_DIR/kubeconfig
386dashboard: az aks browse --resource-group ${AKS_RESOURCE_GROUP_NAME} --name ${AKS_NAME}
387
388--------BUILD DETAILS--------
389Build directory: $BUILD_DIR
390Integration repo: $BUILD_DIR/integration
391OOM repo: $BUILD_DIR/oom
392
393--------ADD TO /etc/hosts--------
394$AKS_PUBLIC_IP_ADDRESS portal.api.simpledemo.onap.org
395$AKS_PUBLIC_IP_ADDRESS sdc.api.simpledemo.onap.org
396$AKS_PUBLIC_IP_ADDRESS sdc.api.fe.simpledemo.onap.org
397$AKS_PUBLIC_IP_ADDRESS sdc.api.be.simpledemo.onap.org
398$AKS_PUBLIC_IP_ADDRESS vid.api.simpledemo.onap.org
399$AKS_PUBLIC_IP_ADDRESS policy.api.simpledemo.onap.org
400$AKS_PUBLIC_IP_ADDRESS aai.api.simpledemo.onap.org
401$AKS_PUBLIC_IP_ADDRESS cli.api.simpledemo.onap.org
402$AKS_PUBLIC_IP_ADDRESS so.api.simpledemo.onap.org
403$AKS_PUBLIC_IP_ADDRESS so.monitoring.api.simpledemo.onap.org
404$AKS_PUBLIC_IP_ADDRESS so-monitoring
405$AKS_PUBLIC_IP_ADDRESS sdnc.api.simpledemo.onap.org
406$AKS_PUBLIC_IP_ADDRESS clamp.api.simpledemo.onap.org
407$AKS_PUBLIC_IP_ADDRESS dcae.api.simpledemo.onap.org
408$AKS_PUBLIC_IP_ADDRESS appc.api.simpledemo.onap.org
409$AKS_PUBLIC_IP_ADDRESS aaf.api.simpledemo.onap.org
410$AKS_PUBLIC_IP_ADDRESS portal-sdk.simpledemo.onap.org
411$AKS_PUBLIC_IP_ADDRESS robot.api.simpledemo.onap.org
412$AKS_PUBLIC_IP_ADDRESS msb.api.discovery.simpledemo.onap.org
413$AKS_PUBLIC_IP_ADDRESS msb.api.simpledemo.onap.org
414$AKS_PUBLIC_IP_ADDRESS aai.ui.simpledemo.onap.org
415$AKS_PUBLIC_IP_ADDRESS policy.api.simpledemo.onap.org
416
417EOF
418
419cat "$BUILD_DIR/deployment.notes"
stark, stevenf3519422019-12-05 14:14:32 -0800420
421
422if [ $POST_INSTALL = 1 ]; then
423
424echo "Executing post installation scripts..."
425sleep 3
426
427cat > "$BUILD_DIR/onap.conf" <<EOF
428export CLLI=$CLLI
429export CLOUD_OWNER=$CLOUD_OWNER
430export CLOUD_REGION=$CLOUD_REGION
431export OPENSTACK_IP=$DEVSTACK_PRIVATE_IP
432export OPENSTACK_USER=$OPENSTACK_USER
433export OPENSTACK_PASS=$OPENSTACK_PASS
434export OPENSTACK_TENANT=$OPENSTACK_TENANT
435export OPENSTACK_REGION=$OPENSTACK_REGION
436export CUSTOMER=$CUSTOMER
437export SUBSCRIBER=$SUBSCRIBER
438export SERVICE_TYPE=$SERVICE_TYPE
439export AZ=$AZ
440export OE=$OE
441export LOB=$LOB
442export PLATFORM=$PLATFORM
443export PROJECT=$PROJECT
444export OS_ID=$OS_ID
445export OS_TENANT_ROLE=$OS_TENANT_ROLE
446export OS_KEYSTONE=$OS_KEYSTONE
447export KUBECONFIG=$BUILD_DIR/kubeconfig
448export NFS_PRIVATE_IP=$NFS_PRIVATE_IP
449export DEVSTACK_PRIVATE_IP=$DEVSTACK_PRIVATE_IP
450export PRIVATE_KEY=$PRIVATE_KEY
451EOF
452
453$DIR/post_install.sh "$BUILD_DIR/onap.conf" "$DIR/cloud.conf"
454
455fi