blob: 555ba12cca616267b00ab83dc852369af2c3e4f3 [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"
136OPENSTACK_USER = "$OPENSTACK_USER"
137OPENSTACK_PASS = "$OPENSTACK_PASS"
138OPENSTACK_TENANT = "$OPENSTACK_TENANT"
139IMAGE_LIST = "$IMAGE_LIST"
140
141# ONAP PARAMS
142CLLI = "$CLLI"
143CLOUD_OWNER = "$CLOUD_OWNER"
144CLOUD_REGION = "$CLOUD_REGION"
145CUSTOMER = "$CUSTOMER"
146SUBSCRIBER = "$SUBSCRIBER"
147SERVICE_TYPE = "$SERVICE_TYPE"
148AZ = "$AZ"
149OE = "$OE"
150LOB = "$LOB"
151PLATFORM = "$PLATFORM"
152OS_ID = "$OS_ID"
153OS_TENANT_ROLE = "$OS_TENANT_ROLE"
154OS_KEYSTONE = "$OS_KEYSTONE"
155OPENSTACK_REGION = "$OPENSTACK_REGION"
156PROJECT = "$PROJECT"
157OOM_BRANCH = "$OOM_BRANCH"
158CHART_VERSION = "$CHART_VERSION"
159OOM_OVERRIDES = "$OOM_OVERRIDES"
160DOCKER_REPOSITORY = "$DOCKER_REPOSITORY"
161
162EOF
163
164if [ $NO_PROMPT = 0 ]; then
165 read -p "Would you like to proceed? [y/n]" -n 1 -r
166 echo " "
167 if [[ ! $REPLY =~ ^[Yy]$ ]]
168 then
169 exit 0
170 fi
171fi
172
173echo "Starting instantiation. This will take a little while..."
174sleep 3
175
176set -x
177set -e
178
179mkdir -p $BUILD_DIR
180
181echo "#!/bin/bash" > $BUILD_DIR/clean.sh
182echo "" >> $BUILD_DIR/clean.sh
183chmod 755 $BUILD_DIR/clean.sh
184
185ssh-keygen -t rsa -N "" -f $BUILD_DIR/id_rsa
186
187PUBLIC_KEY=$BUILD_DIR/id_rsa.pub
188PRIVATE_KEY=$BUILD_DIR/id_rsa
189
190
191echo "az group delete --resource-group $DEVSTACK_RG --yes" >> $BUILD_DIR/clean.sh
192echo "" >> $BUILD_DIR/clean.sh
193
194echo "Creating DEVSTACK Server $DEVSTACK_NAME in $LOCATION"
195$DIR/create_devstack.sh --name "$DEVSTACK_NAME" \
196 --resource-group "$DEVSTACK_RG" \
197 --size "$DEVSTACK_VM_SIZE" \
198 --location "$DEVSTACK_LOCATION" \
199 --cidr "$DEVSTACK_CIDR" \
200 --admin-user "$DEVSTACK_ADMIN_USER" \
201 --directory "$BUILD_DIR" \
202 --vnet-name "$DEVSTACK_VNET_NAME" \
203 --public-key "$PUBLIC_KEY" \
204 --user-public-ip "$USER_PUBLIC_IP_PREFIX" \
205 --devstack-private-ip "$DEVSTACK_PRIVATE_IP" \
206 --devstack-subnet-name "$DEVSTACK_SUBNET_NAME" \
207 --devstack-disk-size "$DEVSTACK_DISK_SIZE" \
208 --openstack-username "$OPENSTACK_USER" \
209 --openstack-password "$OPENSTACK_PASS" \
210 --openstack-tenant "$OPENSTACK_TENANT" \
211 --image-list "$IMAGE_LIST" \
212 --no-prompt
213
214
215echo "az group delete --resource-group $NFS_RG --yes" >> $BUILD_DIR/clean.sh
216echo "" >> $BUILD_DIR/clean.sh
217
218echo "Creating NFS Server $NFS_NAME in $LOCATION"
219$DIR/create_nfs.sh --name "$NFS_NAME" \
220 --resource-group "$NFS_RG" \
221 --size "$NFS_VM_SIZE" \
222 --location "$NFS_LOCATION" \
223 --cidr "$NFS_CIDR" \
224 --admin-user "$NFS_ADMIN_USER" \
225 --directory "$BUILD_DIR" \
226 --vnet-name "$NFS_VNET_NAME" \
227 --public-key "$PUBLIC_KEY" \
228 --user-public-ip "$USER_PUBLIC_IP_PREFIX" \
229 --nfs-subnet-name "$NFS_SUBNET_NAME" \
230 --aks-node-cidr "$AKS_NODE_CIDR" \
231 --nfs-disk-size "$NFS_DISK_SIZE" \
232 --no-prompt
233
234
235echo "az group delete --resource-group $AKS_RESOURCE_GROUP_NAME --yes" >> $BUILD_DIR/clean.sh
236echo "" >> $BUILD_DIR/clean.sh
237
238echo "Creating AKS $AKS_NAME in $LOCATION"
239$DIR/create_aks.sh --name "$AKS_NAME" \
240 --resource-group "$AKS_RESOURCE_GROUP_NAME" \
241 --kube-version "$AKS_K8_VERSION" \
242 --location "$LOCATION" \
243 --node-count "$AKS_NODE_COUNT" \
244 --size "$AKS_NODE_SIZE" \
245 --service-cidr "$AKS_SERVICE_CIDR" \
246 --pod-cidr "$AKS_POD_CIDR" \
247 --dns-ip "$AKS_DNS_IP" \
248 --node-cidr "$AKS_NODE_CIDR" \
249 --vnet-name "$AKS_VNET_NAME" \
250 --user-public-ip "$USER_PUBLIC_IP_PREFIX" \
251 --public-key "$PUBLIC_KEY" \
252 --admin-user "$AKS_ADMIN_USER" \
253 --no-prompt
254
255
256AKS_MANAGEMENT_RESOURCE_GROUP_NAME=`az group list --query "[?starts_with(name, 'MC_${AKS_RESOURCE_GROUP_NAME}')].name | [0]" --output tsv`
257AKS_VNET_ID=`az network vnet show --resource-group ${AKS_RESOURCE_GROUP_NAME} --name ${AKS_VNET_NAME} --query 'id' --output tsv`
258NFS_VNET_ID=`az network vnet show --name ${NFS_VNET_NAME} --resource-group ${NFS_RG} --query "id" --output tsv`
259DEVSTACK_VNET_ID=`az network vnet show --name ${DEVSTACK_VNET_NAME} --resource-group ${DEVSTACK_RG} --query "id" --output tsv`
260AKS_ROUTE_TABLE_NAME=`az resource list --resource-group ${AKS_MANAGEMENT_RESOURCE_GROUP_NAME} --resource-type "Microsoft.Network/routeTables" --query "[0] | name" --output tsv`
261DEVSTACK_PRIVATE_IP=`az vm show --name ${DEVSTACK_NAME} --resource-group ${DEVSTACK_RG} -d --query "privateIps" --output tsv`
262NFS_PRIVATE_IP=`az vm show --name ${NFS_NAME} --resource-group ${NFS_RG} -d --query "privateIps" --output tsv`
263NFS_PUBLIC_IP=`az vm show --name ${NFS_NAME} --resource-group ${NFS_RG} -d --query "publicIps" --output tsv`
264DEVSTACK_PUBLIC_IP=`az vm show --name ${DEVSTACK_NAME} --resource-group ${DEVSTACK_RG} -d --query "publicIps" --output tsv`
265
266# adding public ip to aks
267NIC_NAME0=`az resource list --resource-group ${AKS_MANAGEMENT_RESOURCE_GROUP_NAME} --resource-type "Microsoft.Network/networkInterfaces" --query "[0] | name" --output tsv`
268AKS_NSG_NAME=`az resource list --resource-group ${AKS_MANAGEMENT_RESOURCE_GROUP_NAME} --resource-type "Microsoft.Network/networkSecurityGroups" --query "[0] | name" --output tsv`
269$DIR/create_public_ip.sh "AKSPUBLICIP1" "$AKS_MANAGEMENT_RESOURCE_GROUP_NAME" "$NIC_NAME0"
270$DIR/create_sg_rule.sh "$AKS_MANAGEMENT_RESOURCE_GROUP_NAME" "$AKS_NSG_NAME" '*' "30000-32000" "$USER_PUBLIC_IP_PREFIX" '*' '*' "ONAP" "120"
271
272AKS_PUBLIC_IP_ADDRESS=`az network public-ip show --resource-group ${AKS_MANAGEMENT_RESOURCE_GROUP_NAME} -n AKSPUBLICIP1 --query "ipAddress" --output tsv`
273
274### Peering networks ###
275# peering requires source = VNet NAME, destination = VNet ID
276
277echo "creating peering from AKS Vnet to NFS Vnet..."
278$DIR/create_peering.sh "$AKS_VNET_NAME" \
279 "$AKS_RESOURCE_GROUP_NAME" \
280 "$NFS_VNET_ID" \
281 "kube-to-nfs"
282
283echo "creating peering from AKS Vnet to Devstack Vnet..."
284$DIR/create_peering.sh "$AKS_VNET_NAME" \
285 "$AKS_RESOURCE_GROUP_NAME" \
286 "$DEVSTACK_VNET_ID" \
287 "kube-to-devstack"
288
289echo "creating peering from NFS Vnet to AKS Vnet..."
290$DIR/create_peering.sh "$NFS_VNET_NAME" \
291 "$NFS_RG" \
292 "$AKS_VNET_ID" \
293 "nfs-to-kube"
294
295echo "creating peering from NFS Vnet to AKS Vnet..."
296$DIR/create_peering.sh "$DEVSTACK_VNET_NAME" \
297 "$DEVSTACK_RG" \
298 "$AKS_VNET_ID" \
299 "devstack-to-kube"
300
301
302### Adding next hop to kubernetes for devstack ###
303echo "creating route from AKS Vnet to Devstack Vnet..."
304$DIR/create_route.sh "$DEVSTACK_CIDR" \
305 "guestvms" \
306 "$AKS_MANAGEMENT_RESOURCE_GROUP_NAME" \
307 "$AKS_ROUTE_TABLE_NAME" \
308 "$DEVSTACK_PRIVATE_IP"
309
310
311
312# TODO
313# Lets find a better place for this
314az aks get-credentials --resource-group "$AKS_RESOURCE_GROUP_NAME" \
315 --name "$AKS_NAME" \
316 --file "$BUILD_DIR"/"kubeconfig"
317
318$DIR/configure_nfs_pod.sh "$PRIVATE_KEY" \
319 "$BUILD_DIR"/"kubeconfig" \
320 "$NFS_PRIVATE_IP" \
321 "$AKS_ADMIN_USER"
322
323# TODO
324# add this to post-install or post-configure phase
325# to support adding multiple devstacks to same ONAP
326cat > "$BUILD_DIR/openstack_rc" <<EOF
327export OS_USERNAME="$OPENSTACK_USER"
328export OS_PROJECT_NAME="$OPENSTACK_TENANT"
329export OS_AUTH_URL="http://$DEVSTACK_PRIVATE_IP/identity"
330export OS_PASSWORD="$OPENSTACK_PASS"
331export OS_USER_DOMAIN_NAME=default
332export OS_PROJECT_DOMAIN_ID=default
333EOF
334
335$DIR/util/create_openstack_cli.sh "$BUILD_DIR/kubeconfig" \
336 "$BUILD_DIR/openstack_rc" \
337 "$OPENSTACK_CLI_POD"
338
stark, stevenf3519422019-12-05 14:14:32 -0800339
stark, steven6754bc12019-09-19 15:43:00 -0700340if [ $OVERRIDE = 1 ]; then
341
342$DIR/util/create_integration_override.sh "$BUILD_DIR" \
343 "$OPENSTACK_CLI_POD" \
344 "$BUILD_DIR/openstack_rc" \
345 "$DOCKER_REPOSITORY" \
346 "$NFS_PRIVATE_IP" \
347 "$AKS_PUBLIC_IP_ADDRESS" \
348 "$BUILD_DIR/kubeconfig"
349
350fi
351
stark, stevenf3519422019-12-05 14:14:32 -0800352
stark, steven6754bc12019-09-19 15:43:00 -0700353if [ $NO_INSTALL = 0 ]; then
354
355### Starting OOM install ###
356echo "Installing ONAP..."
357$DIR/create_onap.sh "$BUILD" \
358 "$BUILD_DIR/kubeconfig" \
stark, steven6754bc12019-09-19 15:43:00 -0700359 "$OOM_BRANCH" \
360 "$BUILD_DIR" \
361 "$CHART_VERSION" \
362 "$OOM_OVERRIDES"
363
stark, steven6754bc12019-09-19 15:43:00 -0700364fi
365
stark, stevenf3519422019-12-05 14:14:32 -0800366
stark, steven6754bc12019-09-19 15:43:00 -0700367set +x
368
369cat > "$BUILD_DIR/deployment.notes" <<EOF
370==================================================================
371Phew, all done (yay!). ONAP and DevStack might still be installing
372but here are the access details...
373
374--------DEVSTACK ACCESS--------
375ssh -i ${PRIVATE_KEY} ${DEVSTACK_ADMIN_USER}@${DEVSTACK_PUBLIC_IP}
376horizon: http://${DEVSTACK_PUBLIC_IP}
377cli: kubectl exec $OPENSTACK_CLI_POD -- sh -lc "<openstack command>"
378
379--------NFS ACCESS--------
380ssh -i ${PRIVATE_KEY} ${NFS_ADMIN_USER}@${NFS_PUBLIC_IP}
381
382--------KUBERNETES ACCESS--------
383kubeconfig: export KUBECONFIG=$BUILD_DIR/kubeconfig
384dashboard: az aks browse --resource-group ${AKS_RESOURCE_GROUP_NAME} --name ${AKS_NAME}
385
386--------BUILD DETAILS--------
387Build directory: $BUILD_DIR
388Integration repo: $BUILD_DIR/integration
389OOM repo: $BUILD_DIR/oom
390
391--------ADD TO /etc/hosts--------
392$AKS_PUBLIC_IP_ADDRESS portal.api.simpledemo.onap.org
393$AKS_PUBLIC_IP_ADDRESS sdc.api.simpledemo.onap.org
394$AKS_PUBLIC_IP_ADDRESS sdc.api.fe.simpledemo.onap.org
395$AKS_PUBLIC_IP_ADDRESS sdc.api.be.simpledemo.onap.org
396$AKS_PUBLIC_IP_ADDRESS vid.api.simpledemo.onap.org
397$AKS_PUBLIC_IP_ADDRESS policy.api.simpledemo.onap.org
398$AKS_PUBLIC_IP_ADDRESS aai.api.simpledemo.onap.org
399$AKS_PUBLIC_IP_ADDRESS cli.api.simpledemo.onap.org
400$AKS_PUBLIC_IP_ADDRESS so.api.simpledemo.onap.org
401$AKS_PUBLIC_IP_ADDRESS so.monitoring.api.simpledemo.onap.org
402$AKS_PUBLIC_IP_ADDRESS so-monitoring
403$AKS_PUBLIC_IP_ADDRESS sdnc.api.simpledemo.onap.org
404$AKS_PUBLIC_IP_ADDRESS clamp.api.simpledemo.onap.org
405$AKS_PUBLIC_IP_ADDRESS dcae.api.simpledemo.onap.org
406$AKS_PUBLIC_IP_ADDRESS appc.api.simpledemo.onap.org
407$AKS_PUBLIC_IP_ADDRESS aaf.api.simpledemo.onap.org
408$AKS_PUBLIC_IP_ADDRESS portal-sdk.simpledemo.onap.org
409$AKS_PUBLIC_IP_ADDRESS robot.api.simpledemo.onap.org
410$AKS_PUBLIC_IP_ADDRESS msb.api.discovery.simpledemo.onap.org
411$AKS_PUBLIC_IP_ADDRESS msb.api.simpledemo.onap.org
412$AKS_PUBLIC_IP_ADDRESS aai.ui.simpledemo.onap.org
413$AKS_PUBLIC_IP_ADDRESS policy.api.simpledemo.onap.org
414
415EOF
416
417cat "$BUILD_DIR/deployment.notes"
stark, stevenf3519422019-12-05 14:14:32 -0800418
419
420if [ $POST_INSTALL = 1 ]; then
421
422echo "Executing post installation scripts..."
423sleep 3
424
425cat > "$BUILD_DIR/onap.conf" <<EOF
426export CLLI=$CLLI
427export CLOUD_OWNER=$CLOUD_OWNER
428export CLOUD_REGION=$CLOUD_REGION
429export OPENSTACK_IP=$DEVSTACK_PRIVATE_IP
430export OPENSTACK_USER=$OPENSTACK_USER
431export OPENSTACK_PASS=$OPENSTACK_PASS
432export OPENSTACK_TENANT=$OPENSTACK_TENANT
433export OPENSTACK_REGION=$OPENSTACK_REGION
434export CUSTOMER=$CUSTOMER
435export SUBSCRIBER=$SUBSCRIBER
436export SERVICE_TYPE=$SERVICE_TYPE
437export AZ=$AZ
438export OE=$OE
439export LOB=$LOB
440export PLATFORM=$PLATFORM
441export PROJECT=$PROJECT
442export OS_ID=$OS_ID
443export OS_TENANT_ROLE=$OS_TENANT_ROLE
444export OS_KEYSTONE=$OS_KEYSTONE
445export KUBECONFIG=$BUILD_DIR/kubeconfig
446export NFS_PRIVATE_IP=$NFS_PRIVATE_IP
447export DEVSTACK_PRIVATE_IP=$DEVSTACK_PRIVATE_IP
448export PRIVATE_KEY=$PRIVATE_KEY
449EOF
450
451$DIR/post_install.sh "$BUILD_DIR/onap.conf" "$DIR/cloud.conf"
452
453fi
454