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