2 #############################################################################
4 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
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
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.
17 #############################################################################
20 # prepare a curl command
21 # parameters: URL METHOD CURLOPTIONS EXTRA_HEADERS_AS_A_STRING AUTH_AS_USER:PASS DATA
22 assemble_curl_command()
29 local CURLOPTIONS="$3"
30 local EXTRA_HEADERS="$4"
34 if [ ! -z "$METHOD" ]; then
35 CMD="curl $CURLOPTIONS $METHOD"
37 CMD="curl $CURLOPTIONS -X GET"
39 if [ ! -z "$EXTRA_HEADERS" ]; then
40 CMD="$CMD $EXTRA_HEADERS"
42 if [ ! -z "$AUTH" ]; then
45 if [ ! -z "$DATA" ]; then
53 # Make a rest API call
54 # parameters: URL METHOD expected_response_code EXTRA_HEADERS_AS_A_STRING AUTH_AS_USER:PASS DATA
55 call_api_for_response_code()
60 local CURLOPTIONS='-kIso /dev/null -w "%{http_code}"'
62 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
66 call_api_for_response_body()
71 local CURLOPTIONS='-ksb'
73 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
77 call_api_for_response_header()
82 local CURLOPTIONS='-ks -o /dev/null -D -'
84 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
88 call_api_for_verbose()
93 local CURLOPTIONS='-kIv'
95 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
98 #local TFILE=$(mktemp /tmp/curlcmd.XXXXXXXXX)
105 # Wait till a web service API return specified response code
106 # parameters: URL METHOD EXPECTED_RESP_CODE EXTRA_HEADERS_AS_A_STRING AUTH_AS_USER:PASS DATA
110 export https_proxy=""
114 ACTUALRESP=$(call_api_for_response_code "$1" "$2" "$3" "$4" "$5" "$6")
115 while [ "$ACTUALRESP" != "$RESP" ]; do
116 echo "RESP CODE $ACTUALRESP, not as expected RESP CODE $RESP @ $(date)."
118 ACTUALRESP=$(call_api_for_response_code "$1" "$2" "$3" "$4" "$5" "$6")
120 echo "RESP CODE $ACTUALRESP, matches with expected RESP CODE $RESP."
123 # Wait till a TCP port is open
124 # parameters: HOST PORT
128 export https_proxy=""
132 while ! nc -z -w 1 "$DEST" "$PORT"; do
144 export https_proxy=""
146 # wait till A&AI up and ready
148 AAIHOST=$(cat /opt/config/aai1_ip_addr.txt)
149 local AAIURL="https://$AAIHOST:8443/aai/v11/examples/cloud-regions"
150 local AAIMETHOD='-X GET'
152 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"'
153 local AAIAUTH='-u AAI:AAI'
155 echo "===> Waiting for A&AI to get ready for getting $AAIRESP from $AAIURL @ $(date)"
156 wait_for_api "$AAIURL" "$AAIMETHOD" "$AAIRESP" "$AAIHEADERS" "$AAIAUTH" "$AAIDATA"
157 echo "===> A&AI ready @ $(date)"
162 wait_for_multicloud_ready()
165 export https_proxy=""
167 # wait till MultiCloud up and ready
169 MCHOST=$(cat /opt/config/openo_ip_addr.txt)
170 local MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
171 local MCMETHOD='-X GET'
173 local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
176 echo "===> Waiting for MultiCloud to get ready for getting $MCRESP from $MCURL @ $(date)"
177 wait_for_api "$MCURL" "$MCMETHOD" "$MCRESP" "$MCHEADERS" "$MCAUTH" "$MCDATA"
178 echo "===> MultiCloud ready @ $(date)"
181 register_multicloud_pod25dns_with_aai()
184 export https_proxy=""
186 # Register MultiCloud with A&AI
187 local CLOUD_OWNER='pod25dns'
188 local CLOUD_VERSION='titanium_cloud'
191 local CLOUD_IDENTITY_URL
192 local DNSAAS_SERVICE_URL
193 local DNSAAS_USERNAME='demo'
194 local DNSAAS_PASSWORD='onapdemo'
196 CLOUD_REGION="$(cat /opt/config/dnsaas_region.txt)"
197 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
198 MCIP="$(cat /opt/config/openo_ip_addr.txt)"
199 CLOUD_IDENTITY_URL="http://${MCIP}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}/identity/v2.0"
202 DNSAAS_SERVICE_URL="$(cat /opt/config/dnsaas_keystone_url.txt)"
203 # a tenant of the same name must be set up on the Deisgnate providing OpenStack
204 DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
205 cat >"/tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json" <<EOL
207 "cloud-owner" : "$CLOUD_OWNER",
208 "cloud-region-id" : "$CLOUD_REGION",
209 "cloud-region-version" : "$CLOUD_VERSION",
210 "cloud-type" : "$CLOUD_ENV",
211 "cloud-zone" : "cloud zone",
212 "complex-name" : "complex name2",
213 "identity-url": "$CLOUD_IDENTITY_URL",
214 "owner-defined-type" : "owner-defined-type",
215 "sriov-automation" : false,
216 "esr-system-info-list" : {
217 "esr-system-info" : [
219 "esr-system-info-id": "532ac032-e996-41f2-84ed-9c7a1766eb30",
220 "cloud-domain": "Default",
221 "default-tenant" : "$DNSAAS_TENANT_NAME",
222 "user-name" : "$DNSAAS_USERNAME",
223 "password" : "$DNSAAS_PASSWORD",
224 "service-url" : "$DNSAAS_SERVICE_URL",
225 "ssl-cacert": "example-ssl-cacert-val-75021",
226 "ssl-insecure": true,
227 "system-name": "example-system-name-val-29071",
228 "system-type": "VIM",
229 "ip-address": "example-ip-address-val-44432",
230 "port": "example-port-val-93235",
231 "type": "example-type-val-85255",
232 "protocal": "example-protocal-val-52954",
233 "vendor": "example-vendor-val-94515",
234 "version": "example-version-val-71880"
244 local REGMETHOD='-X PUT'
245 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"'
247 local REGAUTH='-u AAI:AAI'
250 REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
251 REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/$CLOUD_OWNER/$CLOUD_REGION"
252 REGDATA="-T /tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json"
253 echo "Register MultiCloud with A&AI owner $CLOUD_OWNER"
254 RESP=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
255 echo "RESP CODE: $RESP"
259 register_multicloud_pod25_with_aai()
262 export https_proxy=""
264 # Register MultiCloud with A&AI
265 local CLOUD_OWNER='pod25'
266 local CLOUD_VERSION='titanium_cloud'
268 local DNSAAS_CLOUD_REGION
271 local CLOUD_IDENTITY_URL
277 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
278 DNSAAS_CLOUD_REGION="$(cat /opt/config/dnsaas_region.txt)"
279 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
280 MCIP="$(cat /opt/config/openo_ip_addr.txt)"
281 CLOUD_IDENTITY_URL="http://${MCIP}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}/identity/v2.0"
282 KEYSTONE_URL="$(cat /opt/config/openstack_keystone_url.txt)"
283 if [[ "$KEYSTONE_URL" == */v3 ]]; then
285 elif [[ "$KEYSTONE_URL" == */v2.0 ]]; then
288 KEYSTONE_URL="${KEYSTONE_URL}/v3"
291 USERNAME="$(cat /opt/config/openstack_user.txt)"
292 PASSWORD="$(cat /opt/config/openstack_password.txt)"
293 TENANT_NAME="$(cat /opt/config/tenant_name.txt)"
294 cat >"/tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json" <<EOL
296 "cloud-owner" : "$CLOUD_OWNER",
297 "cloud-region-id" : "$CLOUD_REGION",
298 "cloud-region-version" : "$CLOUD_VERSION",
299 "cloud-type" : "$CLOUD_ENV",
300 "cloud-zone" : "cloud zone",
301 "complex-name" : "complex name",
302 "identity-url": "$CLOUD_IDENTITY_URL",
303 "owner-defined-type" : "owner-defined-type",
304 "sriov-automation" : false,
305 "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}\"}}",
306 "esr-system-info-list" : {
307 "esr-system-info" : [
309 "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29",
310 "cloud-domain": "Default",
311 "default-tenant" : "$TENANT_NAME",
312 "user-name" : "$USERNAME",
313 "password" : "$PASSWORD",
314 "service-url" : "$KEYSTONE_URL",
315 "ssl-cacert": "example-ssl-cacert-val-75021",
316 "ssl-insecure": true,
317 "system-name": "example-system-name-val-29070",
318 "system-type": "VIM",
319 "ip-address": "example-ip-address-val-44431",
320 "port": "example-port-val-93234",
321 "type": "example-type-val-85254",
322 "protocal": "example-protocal-val-52954",
323 "vendor": "example-vendor-val-94515",
324 "version": "example-version-val-71880"
333 local REGMETHOD='-X PUT'
334 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"'
336 local REGAUTH='-u AAI:AAI'
339 REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
340 REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/$CLOUD_OWNER/$CLOUD_REGION"
341 REGDATA="-T /tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json"
342 echo "Register MultiCloud with A&AI owner $CLOUD_OWNER"
343 RESP=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
344 echo "RESP CODE: $RESP"
349 verify_multicloud_registration()
352 export https_proxy=""
354 local CLOUD_OWNER='pod25'
356 local CLOUD_VERSION='titanium_cloud'
360 local REGMETHOD='-X GET'
361 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"'
363 local REGAUTH='-u AAI:AAI'
367 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
368 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
369 REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
371 REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/${CLOUD_OWNER}/${CLOUD_REGION}?depth=all"
372 # Verify MultiCloud with A&AI
373 RESPCODE=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
374 echo "Register MultiCloud with A&AI owner $CLOUD_OWNER verify response code: $RESPCODE"
376 CLOUD_OWNER='pod25dns'
377 REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/${CLOUD_OWNER}/${CLOUD_REGION}?depth=all"
378 RESPCODE=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
379 echo "Register MultiCloud with A&AI owner $CLOUD_OWNER verify response code: $RESPCODE"
383 register_dns_zone_proxied_designate()
386 export https_proxy=""
388 local CLOUD_OWNER='pod25'
390 local CLOUD_VERSION='titanium_cloud'
392 local DNSAAS_TENANT_NAME
395 local MCMETHOD='-X POST'
397 local MCHEADERS='-H "Content-Type: application/json" -H "Accept: application/json"'
401 ## export endpoint prefix
402 local MULTICLOUD_PLUGIN_ENDPOINT
404 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
405 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
406 if [ -z "$1" ]; then DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"; else DCAE_ZONE="$1"; fi
407 DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
408 MCHOST=$(cat /opt/config/openo_ip_addr.txt)
409 MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
411 MCDATA='-d "{\"auth\":{\"tenantName\": \"'${DNSAAS_TENANT_NAME}'\"}}"'
412 MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
415 # 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
416 # domain outside of the first DNS server's domain
419 DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
420 ZONENAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
422 echo "===> Register DNS zone $ZONENAME under $DNSAAS_TENANT_NAME"
428 MCURL="${MULTICLOUD_PLUGIN_ENDPOINT}/identity/v3/auth/tokens"
429 echo "=====> Getting token from $MCURL"
430 #TOKEN=$(call_api_for_response_header "$MCURL" "$MCMETHOD" "$MCRESP" "$MCHEADERS" "$MCAUTH" "$MCDATA" | grep 'X-Subject-Token' | sed "s/^.*: //")
431 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/^.*: //")
432 echo "Received Keystone token $TOKEN from $MCURL"
433 if [ -z "$TOKEN" ]; then
434 echo "Faile to acquire token for creating DNS zone. Exit"
439 PROJECTID=$(curl -v -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}" |grep 'project_id' |sed 's/^.*"project_id":"\([a-zA-Z0-9-]*\)",.*$/\1/')
440 if [ ! -z "$PROJECTID" ]; then
441 ### query the zone with zone id
442 echo "!!!!!!> zone $ZONENAME already registered by project $PROJECTID"
445 echo "=====> No zone of same name $ZONENAME found, creating new zone "
446 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"
450 echo "=====> Zone listing"
451 curl -sv -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones" | python -m json.tool
453 ### query the zone with zone name
454 #echo "=====> Querying zone $ZONENAME"
455 #curl -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}"
459 ZONEID=$(curl -v -sb -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}" |grep 'id' |sed 's/^.*"id":"\([a-zA-Z0-9-]*\)",.*$/\1/')
460 echo "=====> After creation, zone $ZONENAME ID is $ZONEID"
462 ### query the zone with zone id
463 #echo "=====> Querying zone $ZONENAME by ID $ZONEID"
464 #curl -sv -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}"
468 register_dns_zone_designate()
471 export https_proxy=""
473 local HEADER_CONTENT_TYPE_JSON="Content-Type: application/json"
474 local HEADER_ACCEPT_JSON="Accept: application/json"
485 local ZONE_PROJECT_ID
487 if [ -z "$1" ]; then DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"; else DCAE_ZONE="$1"; fi
488 DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
489 ZONE_NAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
491 TENANT_NAME="$(cat /opt/config/tenant_name.txt)"
492 TENANT_ID="$(cat /opt/config/tenant_id.txt)"
494 KEYSTONE_URL="$(cat /opt/config/openstack_keystone_url.txt)"
495 if [[ "$KEYSTONE_URL" == */v3 ]]; then
497 elif [[ "$KEYSTONE_URL" == */v2.0 ]]; then
500 KEYSTONE_URL="${KEYSTONE_URL}/v2.0"
504 USERNAME="$(cat /opt/config/openstack_user.txt)"
505 PASSWORD="$(cat /opt/config/openstack_password.txt)"
508 API_ENDPOINT="${KEYSTONE_URL}/tokens"
509 API_DATA="{\"auth\": {\"project\": \"${TENANT_NAME}\", \"tenantId\": \"${TENANT_ID}\", \"passwordCredentials\": {\"username\": \"${USERNAME}\", \"password\": \"${PASSWORD}\"}}}"
511 echo "===> Getting token from ${API_ENDPOINT}"
512 RESP=$(curl -s -v -H "${HEADER_CONTENT_TYPE_JSON}" -d "${API_DATA}" "${API_ENDPOINT}")
514 TOKEN="$(echo ${RESP} | jq -r .access.token.id)"
515 if [ -z "$TOKEN" ]; then
516 echo "Faile to acquire token for creating DNS zone. Exit"
519 HEADER_TOKEN="X-Auth-Token: ${TOKEN}"
522 DESIGNATE_URL=$(echo ${RESP} | jq -r '.access.serviceCatalog[] | select(.name=="designate") | .endpoints[0].publicURL')
523 if [ -z ${DESIGNATE_URL} ]; then
524 echo "Fail to find Designate API endpoint. Exit"
529 API_ENDPOINT="${DESIGNATE_URL}/v2/zones"
530 echo "===> Register DNS zone $ZONE_NAME at Designate API endpoint ${API_ENDPOINT}"
532 RESP=$(curl -v -s -H "$HEADER_TOKEN" "$API_ENDPOINT")
533 ZONE_ID=$(echo $RESP |jq -r --arg ZONE_NAME "$ZONE_NAME" '.zones[] |select(.name==$ZONE_NAME) |.id')
534 if [ -z "$ZONE_ID" ]; then
535 echo "======> Zone ${ZONE_NAME} does not exist. Create"
536 API_DATA="{\"name\": \"${ZONE_NAME}\", \"email\": \"dcae@onap.org\", \"type\": \"PRIMARY\", \"ttl\": 7200, \"description\": \"DCAE DNS zoen created for ONAP deployment $DCAE_ZONE\"}"
537 RESP=$(curl -s -v -X POST -H "$HEADER_ACCEPT_JSON" -H "$HEADER_CONTENT_TYPE_JSON" -H "$HEADER_TOKEN" -d "$API_DATA" "$API_ENDPOINT")
538 ZONE_ID=$(echo $RESP | jq .id)
540 if [ -z "$ZONE_ID" ]; then
541 echo "Fail to create DNS zone ${ZONE_NAME}. Exit"
545 echo "======> Zone ${ZONE_NAME} already exists."
546 API_ENDPOINT="${DESIGNATE_URL}/v2/zones/${ZONE_ID}"
547 RESP=$(curl -s -v -H "$HEADER_ACCEPT_JSON" -H "$HEADER_TOKEN" "$API_ENDPOINT")
548 ZONE_PROJECT_ID=$(echo $RESP | jq -r .project_id)
549 if [ "$ZONE_PROJECT_ID" != "noauth-project" ] && [ "$ZONE_PROJECT_ID" != "$TENANT_ID" ]; then
550 echo "======> Zone ${ZONE_NAME} owned by other projects, may have problem creating records"
552 echo "======> Zone ${ZONE_NAME} okay to create new records"
560 export https_proxy=""
562 local CLOUD_OWNER='pod25'
564 local CLOUD_VERSION='titanium_cloud'
567 local DNSAAS_TENANT_NAME
570 local MCMETHOD='-X GET'
572 local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
575 local MULTICLOUD_PLUGIN_ENDPOINT
577 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
578 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
579 DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"
580 DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
581 MCHOST=$(cat /opt/config/openo_ip_addr.txt)
582 MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
586 DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
587 ZONENAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
589 MCDATA='"{\"auth\":{\"tenantName\": \"'${DNSAAS_TENANT_NAME}'\"}}"'
590 MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
594 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/^.*: //")
597 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/')
599 curl -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X DELETE "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}"
605 export https_proxy=""
607 local CLOUD_OWNER='pod25'
609 local CLOUD_VERSION='titanium_cloud'
612 local DNSAAS_TENANT_NAME
615 local MCMETHOD='-X GET'
617 local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
620 local MULTICLOUD_PLUGIN_ENDPOINT
622 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
623 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
624 DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"
625 DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
626 MCHOST=$(cat /opt/config/openo_ip_addr.txt)
627 MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
629 MCDATA='"{\"auth\":{\"tenantName\": \"'${DNSAAS_TENANT_NAME}'\"}}"'
630 MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
634 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/^.*: //")
638 DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
639 ZONENAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
641 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/')
643 curl -v -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}/recordsets"
646 ################################## start of vm_init #####################################
648 # prepare the configurations needed by DCAEGEN2 installer
649 rm -rf /opt/app/config
650 mkdir -p /opt/app/config
654 sed -e 's/\\n/\n/g' /opt/config/priv_key | sed -e 's/^[ \t]*//g; s/[ \t]*$//g' > /opt/app/config/key
655 chmod 777 /opt/app/config/key
657 # move keystone url file
658 #cp /opt/config/keystone_url.txt /opt/app/config/keystone_url.txt
661 URL_ROOT='nexus.onap.org/service/local/repositories/raw/content'
662 REPO_BLUEPRINTS='org.onap.dcaegen2.platform.blueprints'
663 REPO_DEPLOYMENTS='org.onap.dcaegen2.deployments'
664 if [ -e /opt/config/dcae_deployment_profile.txt ]; then
665 DEPLOYMENT_PROFILE=$(cat /opt/config/dcae_deployment_profile.txt)
667 DEPLOYMENT_PROFILE=${DEPLOYMENT_PROFILE:-R1}
669 NEXUS_USER=$(cat /opt/config/nexus_username.txt)
670 NEXUS_PASSWORD=$(cat /opt/config/nexus_password.txt)
671 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
672 DOCKER_VERSION=$(cat /opt/config/docker_version.txt)
673 # use rand_str as zone
674 ZONE=$(cat /opt/config/rand_str.txt)
675 MYFLOATIP=$(cat /opt/config/dcae_float_ip.txt)
676 MYLOCALIP=$(cat /opt/config/dcae_ip_addr.txt)
677 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
678 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
680 if [ $HTTP_PROXY != "no_proxy" ]
682 export http_proxy=$HTTP_PROXY
683 export https_proxy=$HTTPS_PROXY
686 # start docker image pulling while we are waiting for A&AI to come online
687 docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
690 if [ "$DEPLOYMENT_PROFILE" == "R1" ]; then
691 RELEASE_TAG='releases'
692 # download blueprint input template files
693 rm -rf /opt/app/inputs-templates
694 mkdir -p /opt/app/inputs-templates
695 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/inputs.yaml
696 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/cdapinputs.yaml
697 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/phinputs.yaml
698 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/dhinputs.yaml
699 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/invinputs.yaml
700 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/vesinput.yaml
701 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/tcainputs.yaml
702 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/he-ip.yaml
703 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/hr-ip.yaml
705 # generate blueprint input files
706 pip install --upgrade jinja2
707 wget https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/scripts/detemplate-bpinputs.py \
709 (python detemplate-bpinputs.py /opt/config /opt/app/inputs-templates /opt/app/config; \
710 rm detemplate-bpinputs.py)
712 # Run docker containers
716 docker pull "$NEXUS_DOCKER_REPO/onap/org.onap.dcaegen2.deployments.bootstrap:$DOCKER_VERSION" \
717 && docker pull nginx &
719 #########################################
720 # Wait for then register with A&AI
721 ########################################
723 DNSAAS_PROXYED=$(tr '[:upper:]' '[:lower:]' < /opt/config/dnsaas_config_enabled.txt)
724 if [ "$DNSAAS_PROXYED" == 'true' ]; then
725 echo "Using proxyed DNSaaS service, performing additional registration and configuration"
728 register_multicloud_pod25_with_aai
729 register_multicloud_pod25dns_with_aai
731 verify_multicloud_registration
733 wait_for_multicloud_ready
734 register_dns_zone_proxied_designate "$ZONE"
735 echo "Registration and configuration for proxying DNSaaS completed."
737 echo "Using Designate DNSaaS service, performing additional registration and configuration"
738 register_dns_zone_designate "$ZONE"
741 #########################################
742 # Start DCAE Bootstrap container
743 #########################################
745 chmod 777 /opt/app/config
746 rm -f /opt/config/runtime.ip.consul
747 rm -f /opt/config/runtime.ip.cm
750 #docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
751 #docker pull "$NEXUS_DOCKER_REPO/onap/org.onap.dcaegen2.deployments.bootstrap:$DOCKER_VERSION"
752 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"
755 # waiting for bootstrap to complete then starting nginx for proxying healthcheck calls
756 echo "Waiting for Consul to become accessible"
757 while [ ! -f /opt/app/config/runtime.ip.consul ]; do echo "."; sleep 30; done
760 # start proxy for consul's health check
761 CONSULIP=$(head -1 /opt/app/config/runtime.ip.consul | sed 's/[[:space:]]//g')
762 echo "Consul is available at $CONSULIP"
765 if [[ $DEPLOYMENT_PROFILE == R2* ]]; then
768 rm -rf /opt/app/inputs-templates
769 mkdir -p /opt/app/inputs-templates
770 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-1.yaml
771 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-2.yaml
772 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-3.yaml
773 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-4.yaml
774 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/register.sh
775 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/setup.sh
776 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/teardown.sh
778 pip install --upgrade jinja2
779 wget https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/scripts/detemplate-bpinputs.py \
781 (python detemplate-bpinputs.py /opt/config /opt/app/inputs-templates /opt/app/config; \
782 rm detemplate-bpinputs.py)
784 if [ -e /opt/app/config/register.sh ]; then
785 chmod +x /opt/app/config/register.sh
787 if [ -e /opt/app/config/setup.sh ]; then
788 chmod +x /opt/app/config/setup.sh
790 if [ -e /opt/app/config/build-plugins.sh ]; then
791 chmod +x /opt/app/config/build-plugins.sh
797 /opt/docker/docker-compose -f docker-compose-1.yaml up -d
798 echo "Waiting for Consul to come up ready"
799 while ! nc -z localhost 8500; do sleep 1; done
800 echo "Waiting for DB to come up ready"
801 while ! nc -z localhost 5432; do sleep 1; done
802 echo "Waiting for CBS to come up ready"
803 while ! nc -z localhost 10000; do sleep 1; done
804 echo "All dependencies are up, proceed to the next phase"
807 echo "Setup CloudifyManager and Registrator"
812 export https_proxy=""
817 echo "Bring up DCAE MIN service components for R2 use cases"
818 /opt/docker/docker-compose -f docker-compose-2.yaml up -d
820 if [[ "$DEPLOYMENT_PROFILE" == "R2" || "$DEPLOYMENT_PROFILE" == "R2PLUS" ]]; then
821 echo "Bring up DCAE platform components"
822 /opt/docker/docker-compose -f docker-compose-3.yaml up -d
824 if [ "$DEPLOYMENT_PROFILE" == "R2PLUS" ]; then
825 echo "Bring up additional (plus) DCAE service components"
826 /opt/docker/docker-compose -f docker-compose-4.yaml up -d
830 # start proxy for consul's health check
831 CONSULIP=$(cat /opt/config/dcae_ip_addr.txt)
832 echo "Consul is available at $CONSULIP"
835 cat >./nginx.conf <<EOL
838 server_name dcae.simpledemo.onap.org;
839 root /www/healthcheck;
841 location /healthcheck {
842 try_files /services.yaml =404;
845 proxy_pass http://${CONSULIP}:8500/v1/health/state/passing;
848 try_files /r2mvp_healthy.yaml =404;
851 try_files /r2_healthy.yaml =404;
854 try_files /r2plus_healthy.yaml =404;
862 -p ${HEALTHPORT}:80 \
863 -v "$(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf" \
864 -v "/tmp/healthcheck:/www/healthcheck" \
865 --label "SERVICE_80_NAME=dcae-health" \
866 --label "SERVICE_80_CHECK_HTTP=/healthcheck" \
867 --label "SERVICE_80_CHECK_INTERVAL=15s" \
868 --label "SERVICE_80_CHECK_INITIAL_STATUS=passing" \
871 echo "Healthcheck API available at http://${MYFLOATIP}:${HEALTHPORT}/healthcheck"
872 echo " http://${MYFLOATIP}:${HEALTHPORT}/R1"
873 echo " http://${MYFLOATIP}:${HEALTHPORT}/R2MIN"
874 echo " http://${MYFLOATIP}:${HEALTHPORT}/R2PLUS"
876 # run forever for updating health status based on consul
880 rm -rf /tmp/healthcheck/*
881 # all registered services
882 SERVICES=$(curl -s http://consul:8500/v1/agent/services |jq '. | to_entries[] | .value.Service')
884 SERVICES=$(curl -s http://consul:8500/v1/health/state/passing | jq '.[] | .ServiceName')
886 # remove empty lines/entries
887 SERVICES=$(echo "$SERVICES" | sed '/^\s*\"\"\s*$/d' |sed '/^\s*$/d')
889 SERVICES_JSON=$(echo "$SERVICES" | sed 's/\"$/\",/g' | sed '$ s/.$//')
891 echo "$(date): running healthy services:"
892 echo ">>> " $SERVICES
893 PLT_CONSUL=$(echo "$SERVICES" |grep consul)
894 PLT_CBS=$(echo "$SERVICES" |grep "config_binding_service")
895 MVP_PG_HOLMES=$(echo "$SERVICES" |grep "pgHolmes")
896 MVP_VES=$(echo "$SERVICES" |grep "mvp.*ves")
897 MVP_TCA=$(echo "$SERVICES" |grep "mvp.*tca")
898 MVP_HR=$(echo "$SERVICES" |grep "mvp.*holmes-rule")
899 MVP_HE=$(echo "$SERVICES" |grep "mvp.*holmes-engine")
901 PLT_CM=$(echo "$SERVICES" |grep "cloudify.*manager")
902 PLT_DH=$(echo "$SERVICES" |grep "deployment.*handler")
903 PLT_PH=$(echo "$SERVICES" |grep "policy.*handler")
904 PLT_SCH=$(echo "$SERVICES" |grep "service.*change.*handler")
905 PLT_INV=$(echo "$SERVICES" |grep "inventory")
906 PLT_PG_INVENTORY=$(echo "$SERVICES" |grep "pgInventory")
908 PLUS_MHB=$(echo "$SERVICES" |grep "heartbeat")
909 PLUS_PRH=$(echo "$SERVICES" |grep "prh")
910 PLUS_MPR=$(echo "$SERVICES" |grep "mapper")
911 PLUS_TRAP=$(echo "$SERVICES" |grep "snmptrap")
913 DATA="{\"healthy\" : \"$(date)\", \"healthy_services\": [${SERVICES_JSON}]}"
914 if [[ -n "$PLT_CONSUL" && -n "$PLT_CBS" && -n "$MVP_PG_HOLMES" && -n "$MVP_VES" && \
915 -n "$MVP_TCA" && -n "$MVP_HR" && -n "$MVP_HE" ]]; then
916 echo "${DATA}" > /tmp/healthcheck/r2mvp_healthy.yaml
917 echo "${DATA}" > /tmp/healthcheck/services.yaml
918 echo ">>>>>> enough services satisfying R2MIN service deployment"
920 echo ">>>>>> not enough services satisfying R2MIN service deployment"
923 if [[ -n "$PLT_CONSUL" && -n "$PLT_CBS" && -n "$PLT_CM" && -n "$PLT_DH" && \
924 -n "$PLT_PH" && -n "$PLT_SCH" && -n "$PLT_INV" && -n "$PLT_PG_INVENTORY" ]]; then
925 echo ">>>>>> enough services satisfying R2 platform deployment"
926 echo "${DATA}" > /tmp/healthcheck/r2_healthy.yaml
928 if [[ -n "$PLUS_MHB" && -n "$PLUS_PRH" && -n "$PLUS_MPR" && -n "$PLUS_TRAP" ]]; then
929 echo ">>>>>> enough services satisfying R2PLUS deployment"
930 echo "${DATA}" > /tmp/healthcheck/r2plus_healthy.yaml
932 echo ">>>>>> not enough services satisfying R2PLUS service deployment"
935 echo ">>>>>> not enough services satisfying R2 platform or R2PLUS service deployment"