Merge "Implement MultiCloud proxyed Designate"
[demo.git] / boot / dcae2_vm_init.sh
1 #!/bin/bash
2 #############################################################################
3 #
4 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #############################################################################
18
19
20 # prepare a curl command
21 # parameters: URL METHOD CURLOPTIONS EXTRA_HEADERS_AS_A_STRING AUTH_AS_USER:PASS DATA
22 assemble_curl_command()
23 {
24     local URL="$1"
25     local METHOD="$2"
26     local CURLOPTIONS="$3"
27     local EXTRA_HEADERS="$4"
28     local AUTH="$5"
29     local DATA="$6"
30     local CMD=''
31     if [ ! -z "$METHOD" ]; then
32         CMD="curl $CURLOPTIONS $METHOD"
33     else
34         CMD="curl $CURLOPTIONS -X GET"
35     fi
36     if [ ! -z "$EXTRA_HEADERS" ]; then
37         CMD="$CMD $EXTRA_HEADERS"
38     fi
39     if [ ! -z "$AUTH" ]; then
40         CMD="$CMD $AUTH"
41     fi
42     if [ ! -z "$DATA" ]; then
43         CMD="$CMD $DATA"
44     fi
45     CMD="$CMD $URL"
46     echo "$CMD"
47 }
48
49
50 # Make a rest API call
51 # parameters: URL METHOD expected_response_code EXTRA_HEADERS_AS_A_STRING AUTH_AS_USER:PASS DATA
52 call_api_for_response_code()
53 {
54     local CURLOPTIONS='-kIso /dev/null -w "%{http_code}"'
55     read -r CMDF <<-END
56 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
57 END
58     eval "$CMDF";
59 }
60 call_api_for_response_body()
61 {
62     local CURLOPTIONS='-ksb'
63     read -r CMDF <<-END
64 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
65 END
66     eval "$CMDF"
67 }
68 call_api_for_response_header()
69 {  
70     local CURLOPTIONS='-ks -o /dev/null -D -'
71     read -r CMDF <<-END
72 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
73 END
74     eval "$CMDF"
75 }
76 call_api_for_verbose()
77
78     local CURLOPTIONS='-kIv'
79     read -r CMDF <<-END
80 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
81 END
82     eval "$CMDF"
83     #local TFILE=$(mktemp /tmp/curlcmd.XXXXXXXXX)
84     #echo $CMD > $TFILE
85     #eval $(cat $TFILE)
86     #rm -f $TFILE
87 }
88
89
90 # Wait till a web service API return specified response code
91 # parameters: URL METHOD EXPECTED_RESP_CODE EXTRA_HEADERS_AS_A_STRING AUTH_AS_USER:PASS DATA
92 wait_for_api()
93 {
94     local RESP="$3" 
95     local ACTUALRESP
96     ACTUALRESP=$(call_api_for_response_code "$1" "$2" "$3" "$4" "$5" "$6")
97     while [ "$ACTUALRESP" != "$RESP" ]; do
98         echo "RESP CODE $ACTUALRESP, not as expected RESP CODE $RESP @ $(date)."
99         sleep 30
100         ACTUALRESP=$(call_api_for_response_code "$1" "$2" "$3" "$4" "$5" "$6")
101     done
102     echo "RESP CODE $ACTUALRESP, matches with expected RESP CODE $RESP."
103 }
104
105 # Wait till a TCP port is open
106 # parameters: HOST PORT
107 wait_for_tcp_port()
108 {  
109     local DEST="$1"
110     local PORT="$2"
111     while ! nc -z -w 1 "$DEST" "$PORT"; do
112         sleep 4
113         echo '.'
114     done
115 }
116
117
118
119
120 wait_for_aai_ready()
121 {
122     # wait till A&AI up and ready
123     local AAIHOST
124     AAIHOST=$(cat /opt/config/aai1_ip_addr.txt)
125     local AAIURL="https://$AAIHOST:8443/aai/v11/examples/cloud-regions"
126     local AAIMETHOD='-X GET'
127     local AAIRESP='200'
128     local AAIHEADERS='-H "X-FromAppId: AAI-Temp-Tool" -H "X-TransactionId: AAI-Temp-Tool" -H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
129     local AAIAUTH='-u AAI:AAI'
130     local AAIDATA=''
131     echo "===> Waiting for A&AI to get ready for getting $AAIRESP from $AAIURL @ $(date)"
132     wait_for_api "$AAIURL" "$AAIMETHOD" "$AAIRESP" "$AAIHEADERS" "$AAIAUTH" "$AAIDATA"
133     echo "===> A&AI ready @ $(date)"
134 }
135
136
137
138 wait_for_multicloud_ready()
139 {
140     # wait till MultiCloud up and ready
141     local MCHOST
142     MCHOST=$(cat /opt/config/openo_ip_addr.txt)
143     local MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
144     local MCMETHOD='-X GET'
145     local MCRESP='200'
146     local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
147     local MCAUTH=''
148     local MCDATA=''
149     echo "===> Waiting for MultiCloud to get ready for getting $MCRESP from $MCURL @ $(date)"
150     wait_for_api "$MCURL" "$MCMETHOD" "$MCRESP" "$MCHEADERS" "$MCAUTH" "$MCDATA"
151     echo "===> MultiCloud ready @ $(date)"
152 }
153
154 register_multicloud_pod25dns_with_aai()
155 {
156     # Register MultiCloud with A&AI
157     local CLOUD_OWNER='pod25dns'
158     local CLOUD_VERSION='titanium_cloud'
159     local CLOUD_REGION
160     local CLOUD_ENV
161     local CLOUD_IDENTITY_URL
162     local DNSAAS_SERVICE_URL
163     local DNSAAS_USERNAME
164     local DNSAAS_PASSWORD
165     local DNSAAS_TENANT_ID
166
167     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
168     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
169     MCIP="$(cat /opt/config/openo_ip_addr.txt)"
170     CLOUD_IDENTITY_URL="http://${MCIP}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}/identity/v2.0"
171
172     local RESPCODE
173     DNSAAS_SERVICE_URL="$(cat /opt/config/dnsaas_keystone_url.txt)"
174     DNSAAS_USERNAME="$(cat /opt/config/dnsaas_username.txt)"
175     DNSAAS_PASSWORD="$(cat /opt/config/dnsaas_password.txt)"
176     DNSAAS_TENANT_ID="$(cat /opt/config/dnsaas_tenant_id.txt)"
177     cat >"/tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json" <<EOL
178 {
179     "cloud-owner" : "$CLOUD_OWNER",
180     "cloud-region-id" : "$CLOUD_REGION",
181     "cloud-region-version" : "$CLOUD_VERSION",
182     "cloud-type" : "$CLOUD_ENV",
183     "cloud-zone" : "cloud zone",
184     "complex-name" : "complex name2",
185     "identity-url": "$CLOUD_IDENTITY_URL",
186     "owner-defined-type" : "owner-defined-type",
187     "sriov-automation" : false,
188     "esr-system-info-list" : {
189         "esr-system-info" : [
190             {
191                 "esr-system-info-id": "532ac032-e996-41f2-84ed-9c7a1766eb30",
192                 "cloud-domain": "Default",
193                 "default-tenant" : "$DNSAAS_TENANT_ID",
194                 "user-name" : "$DNSAAS_USERNAME",
195                 "password" : "$DNSAAS_PASSWORD",
196                 "service-url" : "$DNSAAS_SERVICE_URL",
197                 "ssl-cacert": "example-ssl-cacert-val-75021",
198                 "ssl-insecure": true,
199                 "system-name": "example-system-name-val-29071",
200                 "system-type": "VIM",
201                 "ip-address": "example-ip-address-val-44432",
202                 "port": "example-port-val-93235",
203                 "type": "example-type-val-85255",
204                 "protocal": "example-protocal-val-52954",
205                 "vendor": "example-vendor-val-94515",
206                 "version": "example-version-val-71880"
207             }
208         ]
209     }
210 }
211 EOL
212
213
214     local REGHOST
215     local REGURL
216     local REGMETHOD='-X PUT'
217     local REGHEADERS='-H "X-FromAppId: AAI-Temp-Tool" -H "X-TransactionId: AAI-Temp-Tool" -H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
218     local REGRESP='201'
219     local REGAUTH='-u AAI:AAI'
220     local REGDATA
221
222     REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
223     REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/$CLOUD_OWNER/$CLOUD_REGION"
224     REGDATA="-T /tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json"
225     echo "Register MultiCloud with A&AI owner $CLOUD_OWNER"
226     RESP=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
227     echo "RESP CODE: $RESP"
228 }
229
230
231 register_multicloud_pod25_with_aai()
232
233     # Register MultiCloud with A&AI
234     local CLOUD_OWNER='pod25'
235     local CLOUD_VERSION='titanium_cloud'
236     local CLOUD_REGION
237     local CLOUD_ENV
238     local MCIP
239     local CLOUD_IDENTITY_URL
240     local KEYSTONE_URL
241     local USERNAME
242     local PASSWORD
243     local TENANT_ID
244
245     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
246     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
247     MCIP="$(cat /opt/config/openo_ip_addr.txt)"
248     CLOUD_IDENTITY_URL="http://${MCIP}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}/identity/v2.0"
249     KEYSTONE_URL="$(cat /opt/config/openstack_keystone_url.txt)"
250     USERNAME="$(cat /opt/config/openstack_user.txt)"
251     PASSWORD="$(cat /opt/config/openstack_password.txt)"
252     TENANT_ID="$(cat /opt/config/tenant_id.txt)"
253     cat >"/tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json" <<EOL
254
255     "cloud-owner" : "$CLOUD_OWNER",
256     "cloud-region-id" : "$CLOUD_REGION",
257     "cloud-region-version" : "$CLOUD_VERSION",
258     "cloud-type" : "$CLOUD_ENV",
259     "cloud-zone" : "cloud zone",
260     "complex-name" : "complex name",
261     "identity-url": "$CLOUD_IDENTITY_URL",
262     "owner-defined-type" : "owner-defined-type",
263     "sriov-automation" : false,
264     "cloud-extra-info" : "{\"epa-caps\":{\"huge_page\":\"true\",\"cpu_pinning\":\"true\",\"cpu_thread_policy\":\"true\",\"numa_aware\":\"true\",\"sriov\":\"true\",\"dpdk_vswitch\":\"true\",\"rdt\":\"false\",\"numa_locality_pci\":\"true\"},\"dns-delegate\":{\"cloud-owner\":\"pod25dns\",\"cloud-region-id\":\"RegionOne\"}}",
265     "esr-system-info-list" : {
266         "esr-system-info" : [
267             { 
268                 "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29",
269                 "cloud-domain": "Default",
270                 "default-tenant" : "$TENANT_ID",
271                 "user-name" : "$USERNAME",
272                 "password" : "$PASSWORD",
273                 "service-url" : "$KEYSTONE_URL",
274                 "ssl-cacert": "example-ssl-cacert-val-75021",
275                 "ssl-insecure": true,
276                 "system-name": "example-system-name-val-29070",
277                 "system-type": "VIM",
278                 "ip-address": "example-ip-address-val-44431",
279                 "port": "example-port-val-93234",
280                 "type": "example-type-val-85254",
281                 "protocal": "example-protocal-val-52954",
282                 "vendor": "example-vendor-val-94515",
283                 "version": "example-version-val-71880"
284             }
285         ]
286     }
287 }
288 EOL
289  
290     local REGHOST
291     local REGURL
292     local REGMETHOD='-X PUT'
293     local REGHEADERS='-H "X-FromAppId: AAI-Temp-Tool" -H "X-TransactionId: AAI-Temp-Tool" -H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
294     local REGRESP='201'
295     local REGAUTH='-u AAI:AAI'
296     local REGDATA
297  
298     REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
299     REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/$CLOUD_OWNER/$CLOUD_REGION"
300     REGDATA="-T /tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json"
301     echo "Register MultiCloud with A&AI owner $CLOUD_OWNER"
302     RESP=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
303     echo "RESP CODE: $RESP"
304 }
305
306
307
308 verify_multicloud_registration() 
309 {
310     local CLOUD_OWNER='pod25'
311     local CLOUD_REGION
312     local CLOUD_VERSION='titanium_cloud'
313     local CLOUD_ENV
314     local REGHOST
315     local REGURL
316     local REGMETHOD='-X GET'
317     local REGHEADERS='-H "X-FromAppId: AAI-Temp-Tool" -H "X-TransactionId: AAI-Temp-Tool" -H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
318     local REGRESP='200'
319     local REGAUTH='-u AAI:AAI'
320     local REGDATA=''
321     local RESPCODE
322
323     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
324     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
325     REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
326
327     REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/${CLOUD_OWNER}/${CLOUD_REGION}?depth=all"
328     # Verify MultiCloud with A&AI
329     RESPCODE=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
330     echo "Register MultiCloud with A&AI owner $CLOUD_OWNER verify response code: $RESPCODE"
331
332     CLOUD_OWNER='pod25dns'
333     REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/${CLOUD_OWNER}/${CLOUD_REGION}?depth=all"
334     RESPCODE=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
335     echo "Register MultiCloud with A&AI owner $CLOUD_OWNER verify response code: $RESPCODE"
336 }
337
338
339 register_dns_zone()
340 {
341     local CLOUD_OWNER='pod25' 
342     local CLOUD_REGION
343     local CLOUD_VERSION='titanium_cloud'
344     local CLOUD_ENV
345     local DCAE_ZONE
346     local DNSAAS_TENANT_ID
347     local MCHOST
348     local MCURL
349     local MCMETHOD='-X POST'
350     local MCRESP='200'
351     local MCHEADERS='-H "Content-Type: application/json" -H "Accept: application/json"'
352     local MCAUTH=''
353     local MCDATA=''
354
355     ## export endpoint prefix
356     local MULTICLOUD_PLUGIN_ENDPOINT
357
358     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
359     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
360     if [ -z "$1" ]; then DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"; else DCAE_ZONE="$1"; fi
361     DNSAAS_TENANT_ID="$(cat /opt/config/dnsaas_tenant_id.txt)"
362     MCHOST=$(cat /opt/config/openo_ip_addr.txt)
363     MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
364
365     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
366     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}:9005/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
367
368
369     ### Get Token
370     local TOKEN
371
372     MCURL="${MULTICLOUD_PLUGIN_ENDPOINT}/identity/v3/auth/tokens"
373     TOKEN=$(call_api_for_response_header "$MCURL" "$MCMETHOD" "$MCRESP" "$MCHEADERS" "$MCAUTH" "$MCDATA" | grep 'X-Subject-Token' | sed "s/^.*: //")
374     #TOKEN=$(curl -v -s -H "Content-Type: application/json" -X POST -d "{\"tenantName\": \"${DNSAAS_TENANT_ID}\"}"  "${MULTICLOUD_PLUGIN_ENDPOINT}/identity/v3/auth/tokens" 2>&1 | grep X-Subject-Token | sed "s/^.*: //")
375     echo "Received Keystone token $TOKEN from $MCURL"
376
377     ### zone operations
378     local ZONENAME
379     ZONENAME="${DCAE_ZONE}.dcaeg2.simpledemo.onap.org."
380
381     ### list zones
382     curl -sv -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones"
383
384     ### create a zone
385     echo "Creating zone $ZONENAME"
386     curl -sv -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X POST -d "{ \"name\": \"$ZONENAME\", \"email\": \"lji@research.att.com\"}" "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones"
387
388     ### query the zone with zone name
389     curl -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}"
390
391     ### export ZONE id
392     local ZONEID
393     ZONEID=$(curl -v -s  -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}" |sed 's/^.*"id":"\([a-zA-Z0-9-]*\)",.*$/\1/')
394     echo "After creation, zone $ZONENAME ID is $ZONEID"
395
396     ### query the zone with zone id
397     echo "Test listing zone info for zone $ZONENAME"
398     curl -sv -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}"
399 }
400
401
402 delete_dns_zone()
403 {
404     local CLOUD_OWNER='pod25'
405     local CLOUD_REGION
406     local CLOUD_VERSION='titanium_cloud'
407     local CLOUD_ENV
408     local DCAE_ZONE
409     local DNSAAS_TENANT_ID
410     local MCHOST
411     local MCURL
412     local MCMETHOD='-X GET'
413     local MCRESP='200'
414     local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
415     local MCAUTH=''
416     local MCDATA=''
417     local MULTICLOUD_PLUGIN_ENDPOINT
418
419     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
420     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
421     DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"
422     DNSAAS_TENANT_ID="$(cat /opt/config/dnsaas_tenant_id.txt)"
423     MCHOST=$(cat /opt/config/openo_ip_addr.txt)
424     MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
425
426     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
427     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}:9005/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
428
429     ### Get Token
430     local TOKEN
431     TOKEN=$(curl -v -s -H "Content-Type: application/json" -X POST -d "{\"tenantName\": \"${DNSAAS_TENANT_ID}\"}"  "${MULTICLOUD_PLUGIN_ENDPOINT}/identity/v3/auth/tokens"  2>&1 | grep X-Subject-Token | sed "s/^.*: //")
432
433     local ZONENAME
434     ZONENAME="$1.dcae.simpledemo.onap.org."
435     local ZONEID
436     ZONEID=$(curl -v -s  -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}" |sed 's/^.*"id":"\([a-zA-Z0-9-]*\)",.*$/\1/')
437
438     curl -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X DELETE "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}"
439 }
440
441 list_dns_zone() 
442 {
443     local CLOUD_OWNER='pod25'
444     local CLOUD_REGION
445     local CLOUD_VERSION='titanium_cloud'
446     local CLOUD_ENV
447     local DCAE_ZONE
448     local DNSAAS_TENANT_ID
449     local MCHOST
450     local MCURL
451     local MCMETHOD='-X GET'
452     local MCRESP='200'
453     local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
454     local MCAUTH=''
455     local MCDATA=''
456     local MULTICLOUD_PLUGIN_ENDPOINT
457
458     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
459     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
460     DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"
461     DNSAAS_TENANT_ID="$(cat /opt/config/dnsaas_tenant_id.txt)"
462     MCHOST=$(cat /opt/config/openo_ip_addr.txt)
463     MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
464
465     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
466     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}:9005/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
467
468     ### Get Token
469     local TOKEN
470     TOKEN=$(curl -v -s -H "Content-Type: application/json" -X POST -d "{\"tenantName\": \"${DNSAAS_TENANT_ID}\"}"  "${MULTICLOUD_PLUGIN_ENDPOINT}/identity/v3/auth/tokens"  2>&1 | grep X-Subject-Token | sed "s/^.*: //")
471
472     local ZONENAME
473     ZONENAME="$1.dcae.simpledemo.onap.org."
474     local ZONEID
475     ZONEID=$(curl -v -s  -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}" |sed 's/^.*"id":"\([a-zA-Z0-9-]*\)",.*$/\1/')
476
477     curl -v -s  -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}/recordsets"
478 }
479
480
481
482
483
484 NEXUS_USER=$(cat /opt/config/nexus_username.txt)
485 NEXUS_PASSWORD=$(cat /opt/config/nexus_password.txt)
486 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
487 DOCKER_VERSION=$(cat /opt/config/docker_version.txt)
488 ZONE=$(cat /opt/config/dcae_zone.txt)
489 RANDSTR=$(cat /opt/config/rand_str.txt)
490 MYFLOATIP=$(cat /opt/config/dcae_float_ip.txt)
491 MYLOCALIP=$(cat /opt/config/dcae_ip_addr.txt)
492 TENANTNAME=$(cat /opt/config/tenant_name.txt)
493 OSUSERNAME=$(cat /opt/config/openstack_user.txt)
494 OSPASSWORD=$(cat /opt/config/openstack_password.txt)
495
496
497 #########################################
498 # Wait for then register with A&AI
499 ########################################
500
501 DNSAAS_PROXYED=$(tr '[:upper:]' '[:lower:]' < /opt/config/dnsaas_config_enabled.txt)
502 if [ "$DNSAAS_PROXYED" == 'true' ]; then
503     echo "Using proxyed DNSaaS service, performing additional registration and configuration"
504     wait_for_aai_ready
505
506     register_multicloud_pod25_with_aai
507     register_multicloud_pod25dns_with_aai
508
509     verify_multicloud_registration
510
511     wait_for_multicloud_ready
512     register_dns_zone "$ZONE" 
513     echo "Registration and configuration for proxying DNSaaS completed."
514 else
515     echo "Using proxyed DNSaaS service, performing additional registration and configuration"
516 fi
517
518
519
520
521
522 #########################################
523 # Start DCAE Bootstrap container
524 #########################################
525
526 chmod 777 /opt/app/config
527 rm -f /opt/config/runtime.ip.consul
528 rm -f /opt/config/runtime.ip.cm
529
530
531 docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
532 docker pull "$NEXUS_DOCKER_REPO/onap/org.onap.dcaegen2.deployments.bootstrap:$DOCKER_VERSION"
533 docker run -d --name boot -v /opt/app/config:/opt/app/installer/config -e "LOCATION=$ZONE" "$NEXUS_DOCKER_REPO/onap/org.onap.dcaegen2.deployments.bootstrap:$DOCKER_VERSION"
534
535
536 # waiting for bootstrap to complete then starting nginx for proxying healthcheck calls
537 echo "Waiting for Consul to become accessible"
538 while [ ! -f /opt/app/config/runtime.ip.consul ]; do echo "."; sleep 30; done
539
540
541
542 # start proxy for consul's health check
543 CONSULIP=$(head -1 /opt/config/runtime.ip.consul | sed 's/[[:space:]]//g')
544 echo "Consul is available at $CONSULIP" 
545
546 cat >./nginx.conf <<EOL
547 server {
548     listen 80;
549     server_name dcae.simpledemo.onap.org;
550     location /healthcheck {
551         proxy_pass http://${CONSULIP}:8500/v1/health/state/passing;
552     }
553 }
554 EOL
555 docker run --name dcae-proxy -p 8080:80 -v "$(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf" -d nginx
556 echo "Healthcheck API available at http://${MYFLOATIP}:8080/healthcheck"
557 echo "                          or http://${MYLOCALIP}:8080/healthcheck"