Add fix for separating name from ID
[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='demo'
164     local DNSAAS_PASSWORD='onapdemo'
165     local DNSAAS_TENANT_ID
166
167     CLOUD_REGION="$(cat /opt/config/dnsaas_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     # a tenant of the same name must be set up on the Deisgnate providing OpenStack
175     DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
176     cat >"/tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json" <<EOL
177 {
178     "cloud-owner" : "$CLOUD_OWNER",
179     "cloud-region-id" : "$CLOUD_REGION",
180     "cloud-region-version" : "$CLOUD_VERSION",
181     "cloud-type" : "$CLOUD_ENV",
182     "cloud-zone" : "cloud zone",
183     "complex-name" : "complex name2",
184     "identity-url": "$CLOUD_IDENTITY_URL",
185     "owner-defined-type" : "owner-defined-type",
186     "sriov-automation" : false,
187     "esr-system-info-list" : {
188         "esr-system-info" : [
189             {
190                 "esr-system-info-id": "532ac032-e996-41f2-84ed-9c7a1766eb30",
191                 "cloud-domain": "Default",
192                 "default-tenant" : "$DNSAAS_TENANT_NAME",
193                 "user-name" : "$DNSAAS_USERNAME",
194                 "password" : "$DNSAAS_PASSWORD",
195                 "service-url" : "$DNSAAS_SERVICE_URL",
196                 "ssl-cacert": "example-ssl-cacert-val-75021",
197                 "ssl-insecure": true,
198                 "system-name": "example-system-name-val-29071",
199                 "system-type": "VIM",
200                 "ip-address": "example-ip-address-val-44432",
201                 "port": "example-port-val-93235",
202                 "type": "example-type-val-85255",
203                 "protocal": "example-protocal-val-52954",
204                 "vendor": "example-vendor-val-94515",
205                 "version": "example-version-val-71880"
206             }
207         ]
208     }
209 }
210 EOL
211
212
213     local REGHOST
214     local REGURL
215     local REGMETHOD='-X PUT'
216     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"'
217     local REGRESP='201'
218     local REGAUTH='-u AAI:AAI'
219     local REGDATA
220
221     REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
222     REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/$CLOUD_OWNER/$CLOUD_REGION"
223     REGDATA="-T /tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json"
224     echo "Register MultiCloud with A&AI owner $CLOUD_OWNER"
225     RESP=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
226     echo "RESP CODE: $RESP"
227 }
228
229
230 register_multicloud_pod25_with_aai()
231
232     # Register MultiCloud with A&AI
233     local CLOUD_OWNER='pod25'
234     local CLOUD_VERSION='titanium_cloud'
235     local CLOUD_REGION
236     local DNSAAS_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_NAME
244
245     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
246     DNSAAS_CLOUD_REGION="$(cat /opt/config/dnsaas_region.txt)"
247     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
248     MCIP="$(cat /opt/config/openo_ip_addr.txt)"
249     CLOUD_IDENTITY_URL="http://${MCIP}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}/identity/v2.0"
250     KEYSTONE_URL="$(cat /opt/config/openstack_keystone_url.txt)"
251     if [[ "$KEYSTONE_URL" == */v3 ]]; then
252         echo $KEYSTONE_URL
253     elif [[ "$KEYSTONE_URL" == */v2.0 ]]; then
254         echo $KEYSTONE_URL
255     else
256         KEYSTONE_URL="${KEYSTONE_URL}/v3"
257         echo $KEYSTONE_URL
258     fi
259     USERNAME="$(cat /opt/config/openstack_user.txt)"
260     PASSWORD="$(cat /opt/config/openstack_password.txt)"
261     TENANT_NAME="$(cat /opt/config/tenant_name.txt)"
262     cat >"/tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json" <<EOL
263 {
264     "cloud-owner" : "$CLOUD_OWNER",
265     "cloud-region-id" : "$CLOUD_REGION",
266     "cloud-region-version" : "$CLOUD_VERSION",
267     "cloud-type" : "$CLOUD_ENV",
268     "cloud-zone" : "cloud zone",
269     "complex-name" : "complex name",
270     "identity-url": "$CLOUD_IDENTITY_URL",
271     "owner-defined-type" : "owner-defined-type",
272     "sriov-automation" : false,
273     "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\":\"${DNSAAS_CLOUD_REGION}\"}}",
274     "esr-system-info-list" : {
275         "esr-system-info" : [
276             {
277                 "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29",
278                 "cloud-domain": "Default",
279                 "default-tenant" : "$TENANT_NAME",
280                 "user-name" : "$USERNAME",
281                 "password" : "$PASSWORD",
282                 "service-url" : "$KEYSTONE_URL",
283                 "ssl-cacert": "example-ssl-cacert-val-75021",
284                 "ssl-insecure": true,
285                 "system-name": "example-system-name-val-29070",
286                 "system-type": "VIM",
287                 "ip-address": "example-ip-address-val-44431",
288                 "port": "example-port-val-93234",
289                 "type": "example-type-val-85254",
290                 "protocal": "example-protocal-val-52954",
291                 "vendor": "example-vendor-val-94515",
292                 "version": "example-version-val-71880"
293             }
294         ]
295     }
296 }
297 EOL
298  
299     local REGHOST
300     local REGURL
301     local REGMETHOD='-X PUT'
302     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"'
303     local REGRESP='201'
304     local REGAUTH='-u AAI:AAI'
305     local REGDATA
306  
307     REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
308     REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/$CLOUD_OWNER/$CLOUD_REGION"
309     REGDATA="-T /tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json"
310     echo "Register MultiCloud with A&AI owner $CLOUD_OWNER"
311     RESP=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
312     echo "RESP CODE: $RESP"
313 }
314
315
316
317 verify_multicloud_registration() 
318 {
319     local CLOUD_OWNER='pod25'
320     local CLOUD_REGION
321     local CLOUD_VERSION='titanium_cloud'
322     local CLOUD_ENV
323     local REGHOST
324     local REGURL
325     local REGMETHOD='-X GET'
326     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"'
327     local REGRESP='200'
328     local REGAUTH='-u AAI:AAI'
329     local REGDATA=''
330     local RESPCODE
331
332     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
333     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
334     REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
335
336     REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/${CLOUD_OWNER}/${CLOUD_REGION}?depth=all"
337     # Verify MultiCloud with A&AI
338     RESPCODE=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
339     echo "Register MultiCloud with A&AI owner $CLOUD_OWNER verify response code: $RESPCODE"
340
341     CLOUD_OWNER='pod25dns'
342     REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/${CLOUD_OWNER}/${CLOUD_REGION}?depth=all"
343     RESPCODE=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
344     echo "Register MultiCloud with A&AI owner $CLOUD_OWNER verify response code: $RESPCODE"
345 }
346
347
348 register_dns_zone()
349 {
350     local CLOUD_OWNER='pod25' 
351     local CLOUD_REGION
352     local CLOUD_VERSION='titanium_cloud'
353     local CLOUD_ENV
354     local DCAE_ZONE
355     local DNSAAS_TENANT_NAME
356     local MCHOST
357     local MCURL
358     local MCMETHOD='-X POST'
359     local MCRESP='200'
360     local MCHEADERS='-H "Content-Type: application/json" -H "Accept: application/json"'
361     local MCAUTH=''
362     local MCDATA=''
363
364     ## export endpoint prefix
365     local MULTICLOUD_PLUGIN_ENDPOINT
366
367     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
368     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
369     if [ -z "$1" ]; then DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"; else DCAE_ZONE="$1"; fi
370     DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
371     MCHOST=$(cat /opt/config/openo_ip_addr.txt)
372     MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
373
374     MCDATA='-d "{\"auth\":{\"tenantName\": \"${DNSAAS_TENANT_NAME}\"}}"'
375     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
376
377      ### zone operations
378      # because all VM's use 10.0.100.1 as their first DNS server, the designate DNS server as seocnd, we need to use a
379      # domain outside of the first DNS server's domain
380     local ZONENAME
381     ZONENAME="${DCAE_ZONE}.dcaeg2.simpledemo.onap.org."
382
383     echo "===> Register DNS zone $ZONENAME under $DNSAAS_TENANT_NAME"
384
385
386     ### Get Token
387     local TOKEN
388
389     MCURL="${MULTICLOUD_PLUGIN_ENDPOINT}/identity/v3/auth/tokens"
390     echo "=====> Getting token from $MCURL"
391     #TOKEN=$(call_api_for_response_header "$MCURL" "$MCMETHOD" "$MCRESP" "$MCHEADERS" "$MCAUTH" "$MCDATA" | grep 'X-Subject-Token' | sed "s/^.*: //")
392     TOKEN=$(curl -v -s -H "Content-Type: application/json" -X POST -d "{\"auth\":{\"tenantName\": \"${DNSAAS_TENANT_NAME}\"}}" "${MCURL}" 2>&1 | grep X-Subject-Token | sed "s/^.*: //")
393     echo "Received Keystone token $TOKEN from $MCURL"
394     if [ -z "$TOKEN" ]; then
395         echo "Faile to acquire token for creating DNS zone.  Exit"
396         exit 1
397     fi
398
399     ### list zones
400     echo "=====> Get current zone listing"
401     curl -sv -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones"
402
403     ### create a zone
404     echo "=====> Creating zone $ZONENAME"
405     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"
406
407     ### query the zone with zone name
408     echo "=====> Querying zone $ZONENAME"
409     curl -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}"
410
411     ### export ZONE id
412     local ZONEID
413     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/')
414     echo "=====> After creation, zone $ZONENAME ID is $ZONEID"
415
416     ### query the zone with zone id
417     echo "=====> Querying zone $ZONENAME by ID $ZONEID"
418     curl -sv -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}"
419 }
420
421
422 delete_dns_zone()
423 {
424     local CLOUD_OWNER='pod25'
425     local CLOUD_REGION
426     local CLOUD_VERSION='titanium_cloud'
427     local CLOUD_ENV
428     local DCAE_ZONE
429     local DNSAAS_TENANT_NAME
430     local MCHOST
431     local MCURL
432     local MCMETHOD='-X GET'
433     local MCRESP='200'
434     local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
435     local MCAUTH=''
436     local MCDATA=''
437     local MULTICLOUD_PLUGIN_ENDPOINT
438
439     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
440     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
441     DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"
442     DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
443     MCHOST=$(cat /opt/config/openo_ip_addr.txt)
444     MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
445
446     MCDATA='"{\"auth\":{\"tenantName\": \"${DNSAAS_TENANT_NAME}\"}}"'
447     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
448
449     ### Get Token
450     local TOKEN
451     TOKEN=$(curl -v -s -H "Content-Type: application/json" -X POST -d "{\"auth\":{\"tenantName\": \"${DNSAAS_TENANT_NAME}\"}}" "${MULTICLOUD_PLUGIN_ENDPOINT}/identity/v3/auth/tokens"  2>&1 | grep X-Subject-Token | sed "s/^.*: //")
452
453     local ZONENAME
454     ZONENAME="$1.dcaeg2.simpledemo.onap.org."
455     local ZONEID
456     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/')
457
458     curl -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X DELETE "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}"
459 }
460
461 list_dns_zone() 
462 {
463     local CLOUD_OWNER='pod25'
464     local CLOUD_REGION
465     local CLOUD_VERSION='titanium_cloud'
466     local CLOUD_ENV
467     local DCAE_ZONE
468     local DNSAAS_TENANT_NAME
469     local MCHOST
470     local MCURL
471     local MCMETHOD='-X GET'
472     local MCRESP='200'
473     local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
474     local MCAUTH=''
475     local MCDATA=''
476     local MULTICLOUD_PLUGIN_ENDPOINT
477
478     CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
479     CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
480     DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"
481     DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
482     MCHOST=$(cat /opt/config/openo_ip_addr.txt)
483     MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
484
485     MCDATA='"{\"auth\":{\"tenantName\": \"${DNSAAS_TENANT_NAME}\"}}"'
486     MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
487
488     ### Get Token
489     local TOKEN
490     TOKEN=$(curl -v -s -H "Content-Type: application/json" -X POST -d "{\"auth\":{\"tenantName\": \"${DNSAAS_TENANT_NAME}\"}}" "${MULTICLOUD_PLUGIN_ENDPOINT}/identity/v3/auth/tokens"  2>&1 | grep X-Subject-Token | sed "s/^.*: //")
491
492     local ZONENAME
493     ZONENAME="$1.dcaeg2.simpledemo.onap.org."
494     local ZONEID
495     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/')
496
497     curl -v -s  -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}/recordsets"
498 }
499
500
501
502
503
504 NEXUS_USER=$(cat /opt/config/nexus_username.txt)
505 NEXUS_PASSWORD=$(cat /opt/config/nexus_password.txt)
506 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
507 DOCKER_VERSION=$(cat /opt/config/docker_version.txt)
508 # use rand_str as zone
509 ZONE=$(cat /opt/config/rand_str.txt)
510 MYFLOATIP=$(cat /opt/config/dcae_float_ip.txt)
511 MYLOCALIP=$(cat /opt/config/dcae_ip_addr.txt)
512
513
514 docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
515 docker pull "$NEXUS_DOCKER_REPO/onap/org.onap.dcaegen2.deployments.bootstrap:$DOCKER_VERSION" && docker pull nginx &
516
517 #########################################
518 # Wait for then register with A&AI
519 ########################################
520
521 DNSAAS_PROXYED=$(tr '[:upper:]' '[:lower:]' < /opt/config/dnsaas_config_enabled.txt)
522 if [ "$DNSAAS_PROXYED" == 'true' ]; then
523     echo "Using proxyed DNSaaS service, performing additional registration and configuration"
524     wait_for_aai_ready
525
526     register_multicloud_pod25_with_aai
527     register_multicloud_pod25dns_with_aai
528
529     verify_multicloud_registration
530
531     wait_for_multicloud_ready
532     register_dns_zone "$ZONE" 
533     echo "Registration and configuration for proxying DNSaaS completed."
534 else
535     echo "Using proxyed DNSaaS service, performing additional registration and configuration"
536 fi
537
538
539
540
541
542 #########################################
543 # Start DCAE Bootstrap container
544 #########################################
545
546 chmod 777 /opt/app/config
547 rm -f /opt/config/runtime.ip.consul
548 rm -f /opt/config/runtime.ip.cm
549
550
551 docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
552 docker pull "$NEXUS_DOCKER_REPO/onap/org.onap.dcaegen2.deployments.bootstrap:$DOCKER_VERSION"
553 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"
554
555
556 # waiting for bootstrap to complete then starting nginx for proxying healthcheck calls
557 echo "Waiting for Consul to become accessible"
558 while [ ! -f /opt/app/config/runtime.ip.consul ]; do echo "."; sleep 30; done
559
560
561
562 # start proxy for consul's health check
563 CONSULIP=$(head -1 /opt/app/config/runtime.ip.consul | sed 's/[[:space:]]//g')
564 echo "Consul is available at $CONSULIP" 
565
566 cat >./nginx.conf <<EOL
567 server {
568     listen 80;
569     server_name dcae.simpledemo.onap.org;
570     location /healthcheck {
571         proxy_pass http://${CONSULIP}:8500/v1/health/state/passing;
572     }
573 }
574 EOL
575 docker run --name dcae-proxy -p 8080:80 -v "$(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf" -d nginx
576 echo "Healthcheck API available at http://${MYFLOATIP}:8080/healthcheck"
577 echo "                          or http://${MYLOCALIP}:8080/healthcheck"