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()
26 local CURLOPTIONS="$3"
27 local EXTRA_HEADERS="$4"
31 if [ ! -z "$METHOD" ]; then
32 CMD="curl $CURLOPTIONS $METHOD"
34 CMD="curl $CURLOPTIONS -X GET"
36 if [ ! -z "$EXTRA_HEADERS" ]; then
37 CMD="$CMD $EXTRA_HEADERS"
39 if [ ! -z "$AUTH" ]; then
42 if [ ! -z "$DATA" ]; then
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()
54 local CURLOPTIONS='-kIso /dev/null -w "%{http_code}"'
56 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
60 call_api_for_response_body()
62 local CURLOPTIONS='-ksb'
64 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
68 call_api_for_response_header()
70 local CURLOPTIONS='-ks -o /dev/null -D -'
72 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
76 call_api_for_verbose()
78 local CURLOPTIONS='-kIv'
80 $(assemble_curl_command "$1" "$2" "$CURLOPTIONS" "$4" "$5" "$6")
83 #local TFILE=$(mktemp /tmp/curlcmd.XXXXXXXXX)
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
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)."
100 ACTUALRESP=$(call_api_for_response_code "$1" "$2" "$3" "$4" "$5" "$6")
102 echo "RESP CODE $ACTUALRESP, matches with expected RESP CODE $RESP."
105 # Wait till a TCP port is open
106 # parameters: HOST PORT
111 while ! nc -z -w 1 "$DEST" "$PORT"; do
122 # wait till A&AI up and ready
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'
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'
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)"
138 wait_for_multicloud_ready()
140 # wait till MultiCloud up and ready
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'
146 local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
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)"
154 register_multicloud_pod25dns_with_aai()
156 # Register MultiCloud with A&AI
157 local CLOUD_OWNER='pod25dns'
158 local CLOUD_VERSION='titanium_cloud'
161 local CLOUD_IDENTITY_URL
162 local DNSAAS_SERVICE_URL
163 local DNSAAS_USERNAME='demo'
164 local DNSAAS_PASSWORD='onapdemo'
166 CLOUD_REGION="$(cat /opt/config/dnsaas_region.txt)"
167 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
168 MCIP="$(cat /opt/config/openo_ip_addr.txt)"
169 CLOUD_IDENTITY_URL="http://${MCIP}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}/identity/v2.0"
172 DNSAAS_SERVICE_URL="$(cat /opt/config/dnsaas_keystone_url.txt)"
173 # a tenant of the same name must be set up on the Deisgnate providing OpenStack
174 DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
175 cat >"/tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json" <<EOL
177 "cloud-owner" : "$CLOUD_OWNER",
178 "cloud-region-id" : "$CLOUD_REGION",
179 "cloud-region-version" : "$CLOUD_VERSION",
180 "cloud-type" : "$CLOUD_ENV",
181 "cloud-zone" : "cloud zone",
182 "complex-name" : "complex name2",
183 "identity-url": "$CLOUD_IDENTITY_URL",
184 "owner-defined-type" : "owner-defined-type",
185 "sriov-automation" : false,
186 "esr-system-info-list" : {
187 "esr-system-info" : [
189 "esr-system-info-id": "532ac032-e996-41f2-84ed-9c7a1766eb30",
190 "cloud-domain": "Default",
191 "default-tenant" : "$DNSAAS_TENANT_NAME",
192 "user-name" : "$DNSAAS_USERNAME",
193 "password" : "$DNSAAS_PASSWORD",
194 "service-url" : "$DNSAAS_SERVICE_URL",
195 "ssl-cacert": "example-ssl-cacert-val-75021",
196 "ssl-insecure": true,
197 "system-name": "example-system-name-val-29071",
198 "system-type": "VIM",
199 "ip-address": "example-ip-address-val-44432",
200 "port": "example-port-val-93235",
201 "type": "example-type-val-85255",
202 "protocal": "example-protocal-val-52954",
203 "vendor": "example-vendor-val-94515",
204 "version": "example-version-val-71880"
214 local REGMETHOD='-X PUT'
215 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 REGAUTH='-u AAI:AAI'
220 REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
221 REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/$CLOUD_OWNER/$CLOUD_REGION"
222 REGDATA="-T /tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json"
223 echo "Register MultiCloud with A&AI owner $CLOUD_OWNER"
224 RESP=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
225 echo "RESP CODE: $RESP"
229 register_multicloud_pod25_with_aai()
231 # Register MultiCloud with A&AI
232 local CLOUD_OWNER='pod25'
233 local CLOUD_VERSION='titanium_cloud'
235 local DNSAAS_CLOUD_REGION
238 local CLOUD_IDENTITY_URL
244 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
245 DNSAAS_CLOUD_REGION="$(cat /opt/config/dnsaas_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 if [[ "$KEYSTONE_URL" == */v3 ]]; then
252 elif [[ "$KEYSTONE_URL" == */v2.0 ]]; then
255 KEYSTONE_URL="${KEYSTONE_URL}/v3"
258 USERNAME="$(cat /opt/config/openstack_user.txt)"
259 PASSWORD="$(cat /opt/config/openstack_password.txt)"
260 TENANT_NAME="$(cat /opt/config/tenant_name.txt)"
261 cat >"/tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json" <<EOL
263 "cloud-owner" : "$CLOUD_OWNER",
264 "cloud-region-id" : "$CLOUD_REGION",
265 "cloud-region-version" : "$CLOUD_VERSION",
266 "cloud-type" : "$CLOUD_ENV",
267 "cloud-zone" : "cloud zone",
268 "complex-name" : "complex name",
269 "identity-url": "$CLOUD_IDENTITY_URL",
270 "owner-defined-type" : "owner-defined-type",
271 "sriov-automation" : false,
272 "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}\"}}",
273 "esr-system-info-list" : {
274 "esr-system-info" : [
276 "esr-system-info-id": "432ac032-e996-41f2-84ed-9c7a1766eb29",
277 "cloud-domain": "Default",
278 "default-tenant" : "$TENANT_NAME",
279 "user-name" : "$USERNAME",
280 "password" : "$PASSWORD",
281 "service-url" : "$KEYSTONE_URL",
282 "ssl-cacert": "example-ssl-cacert-val-75021",
283 "ssl-insecure": true,
284 "system-name": "example-system-name-val-29070",
285 "system-type": "VIM",
286 "ip-address": "example-ip-address-val-44431",
287 "port": "example-port-val-93234",
288 "type": "example-type-val-85254",
289 "protocal": "example-protocal-val-52954",
290 "vendor": "example-vendor-val-94515",
291 "version": "example-version-val-71880"
300 local REGMETHOD='-X PUT'
301 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 REGAUTH='-u AAI:AAI'
306 REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
307 REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/$CLOUD_OWNER/$CLOUD_REGION"
308 REGDATA="-T /tmp/${CLOUD_OWNER}_${CLOUD_REGION}.json"
309 echo "Register MultiCloud with A&AI owner $CLOUD_OWNER"
310 RESP=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
311 echo "RESP CODE: $RESP"
316 verify_multicloud_registration()
318 local CLOUD_OWNER='pod25'
320 local CLOUD_VERSION='titanium_cloud'
324 local REGMETHOD='-X GET'
325 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 REGAUTH='-u AAI:AAI'
331 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
332 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
333 REGHOST="$(cat /opt/config/aai1_ip_addr.txt)"
335 REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/${CLOUD_OWNER}/${CLOUD_REGION}?depth=all"
336 # Verify MultiCloud with A&AI
337 RESPCODE=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
338 echo "Register MultiCloud with A&AI owner $CLOUD_OWNER verify response code: $RESPCODE"
340 CLOUD_OWNER='pod25dns'
341 REGURL="https://$REGHOST:8443/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/${CLOUD_OWNER}/${CLOUD_REGION}?depth=all"
342 RESPCODE=$(call_api_for_response_code "$REGURL" "$REGMETHOD" "$REGRESP" "$REGHEADERS" "$REGAUTH" "$REGDATA")
343 echo "Register MultiCloud with A&AI owner $CLOUD_OWNER verify response code: $RESPCODE"
347 register_dns_zone_proxied_designate()
349 local CLOUD_OWNER='pod25'
351 local CLOUD_VERSION='titanium_cloud'
353 local DNSAAS_TENANT_NAME
356 local MCMETHOD='-X POST'
358 local MCHEADERS='-H "Content-Type: application/json" -H "Accept: application/json"'
362 ## export endpoint prefix
363 local MULTICLOUD_PLUGIN_ENDPOINT
365 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
366 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
367 if [ -z "$1" ]; then DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"; else DCAE_ZONE="$1"; fi
368 DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
369 MCHOST=$(cat /opt/config/openo_ip_addr.txt)
370 MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
372 MCDATA='-d "{\"auth\":{\"tenantName\": \"'${DNSAAS_TENANT_NAME}'\"}}"'
373 MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
376 # 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
377 # domain outside of the first DNS server's domain
380 DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
381 ZONENAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
383 echo "===> Register DNS zone $ZONENAME under $DNSAAS_TENANT_NAME"
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"
400 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/')
401 if [ ! -z "$PROJECTID" ]; then
402 ### query the zone with zone id
403 echo "!!!!!!> zone $ZONENAME already registered by project $PROJECTID"
406 echo "=====> No zone of same name $ZONENAME found, creating new zone "
407 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"
411 echo "=====> Zone listing"
412 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
414 ### query the zone with zone name
415 #echo "=====> Querying zone $ZONENAME"
416 #curl -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones?name=${ZONENAME}"
420 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/')
421 echo "=====> After creation, zone $ZONENAME ID is $ZONEID"
423 ### query the zone with zone id
424 #echo "=====> Querying zone $ZONENAME by ID $ZONEID"
425 #curl -sv -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}"
429 register_dns_zone_designate()
431 local HEADER_CONTENT_TYPE_JSON="Content-Type: application/json"
432 local HEADER_ACCEPT_JSON="Accept: application/json"
443 local ZONE_PROJECT_ID
445 if [ -z "$1" ]; then DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"; else DCAE_ZONE="$1"; fi
446 DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
447 ZONE_NAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
449 TENANT_NAME="$(cat /opt/config/tenant_name.txt)"
450 TENANT_ID="$(cat /opt/config/tenant_id.txt)"
452 KEYSTONE_URL="$(cat /opt/config/openstack_keystone_url.txt)"
453 if [[ "$KEYSTONE_URL" == */v3 ]]; then
455 elif [[ "$KEYSTONE_URL" == */v2.0 ]]; then
458 KEYSTONE_URL="${KEYSTONE_URL}/v2.0"
462 USERNAME="$(cat /opt/config/openstack_user.txt)"
463 PASSWORD="$(cat /opt/config/openstack_password.txt)"
466 API_ENDPOINT="${KEYSTONE_URL}/tokens"
467 API_DATA="{\"auth\": {\"project\": \"${TENANT_NAME}\", \"tenantId\": \"${TENANT_ID}\", \"passwordCredentials\": {\"username\": \"${USERNAME}\", \"password\": \"${PASSWORD}\"}}}"
469 echo "===> Getting token from ${API_ENDPOINT}"
470 RESP=$(curl -s -v -H "${HEADER_CONTENT_TYPE_JSON}" -d "${API_DATA}" "${API_ENDPOINT}")
472 TOKEN="$(echo ${RESP} | jq -r .access.token.id)"
473 if [ -z "$TOKEN" ]; then
474 echo "Faile to acquire token for creating DNS zone. Exit"
477 HEADER_TOKEN="X-Auth-Token: ${TOKEN}"
480 DESIGNATE_URL=$(echo ${RESP} | jq -r '.access.serviceCatalog[] | select(.name=="designate") | .endpoints[0].publicURL')
481 if [ -z ${DESIGNATE_URL} ]; then
482 echo "Fail to find Designate API endpoint. Exit"
487 API_ENDPOINT="${DESIGNATE_URL}/v2/zones"
488 echo "===> Register DNS zone $ZONE_NAME at Designate API endpoint ${API_ENDPOINT}"
490 RESP=$(curl -v -s -H "$HEADER_TOKEN" "$API_ENDPOINT")
491 ZONE_ID=$(echo $RESP |jq -r --arg ZONE_NAME "$ZONE_NAME" '.zones[] |select(.name==$ZONE_NAME) |.id')
492 if [ -z "$ZONE_ID" ]; then
493 echo "======> Zone ${ZONE_NAME} does not exist. Create"
494 API_DATA="{\"name\": \"${ZONE_NAME}\", \"email\": \"dcae@onap.org\", \"type\": \"PRIMARY\", \"ttl\": 7200, \"description\": \"DCAE DNS zoen created for ONAP deployment $DCAE_ZONE\"}"
495 RESP=$(curl -s -v -X POST -H "$HEADER_ACCEPT_JSON" -H "$HEADER_CONTENT_TYPE_JSON" -H "$HEADER_TOKEN" -d "$API_DATA" "$API_ENDPOINT")
496 ZONE_ID=$(echo $RESP | jq .id)
498 if [ -z "$ZONE_ID" ]; then
499 echo "Fail to create DNS zone ${ZONE_NAME}. Exit"
503 echo "======> Zone ${ZONE_NAME} already exists."
504 API_ENDPOINT="${DESIGNATE_URL}/v2/zones/${ZONE_ID}"
505 RESP=$(curl -s -v -H "$HEADER_ACCEPT_JSON" -H "$HEADER_TOKEN" "$API_ENDPOINT")
506 ZONE_PROJECT_ID=$(echo $RESP | jq -r .project_id)
507 if [ "$ZONE_PROJECT_ID" != "noauth-project" ] && [ "$ZONE_PROJECT_ID" != "$TENANT_ID" ]; then
508 echo "======> Zone ${ZONE_NAME} owned by other projects, may have problem creating records"
510 echo "======> Zone ${ZONE_NAME} okay to create new records"
517 local CLOUD_OWNER='pod25'
519 local CLOUD_VERSION='titanium_cloud'
522 local DNSAAS_TENANT_NAME
525 local MCMETHOD='-X GET'
527 local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
530 local MULTICLOUD_PLUGIN_ENDPOINT
532 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
533 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
534 DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"
535 DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
536 MCHOST=$(cat /opt/config/openo_ip_addr.txt)
537 MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
541 DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
542 ZONENAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
544 MCDATA='"{\"auth\":{\"tenantName\": \"'${DNSAAS_TENANT_NAME}'\"}}"'
545 MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
549 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/^.*: //")
552 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/')
554 curl -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X DELETE "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}"
559 local CLOUD_OWNER='pod25'
561 local CLOUD_VERSION='titanium_cloud'
564 local DNSAAS_TENANT_NAME
567 local MCMETHOD='-X GET'
569 local MCHEADERS='-H "Real-Time: true" -H "Content-Type: application/json" -H "Accept: application/json"'
572 local MULTICLOUD_PLUGIN_ENDPOINT
574 CLOUD_REGION="$(cat /opt/config/openstack_region.txt)"
575 CLOUD_ENV="$(cat /opt/config/cloud_env.txt)"
576 DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"
577 DNSAAS_TENANT_NAME="$(cat /opt/config/dnsaas_tenant_name.txt)"
578 MCHOST=$(cat /opt/config/openo_ip_addr.txt)
579 MCURL="http://$MCHOST:9005/api/multicloud-titanium_cloud/v0/swagger.json"
581 MCDATA='"{\"auth\":{\"tenantName\": \"'${DNSAAS_TENANT_NAME}'\"}}"'
582 MULTICLOUD_PLUGIN_ENDPOINT=http://${MCHOST}/api/multicloud-titanium_cloud/v0/${CLOUD_OWNER}_${CLOUD_REGION}
586 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/^.*: //")
590 DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
591 ZONENAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
593 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/')
595 curl -v -s -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -X GET "${MULTICLOUD_PLUGIN_ENDPOINT}/dns-delegate/v2/zones/${ZONEID}/recordsets"
598 ################################## start of vm_init #####################################
600 # prepare the configurations needed by DCAEGEN2 installer
601 rm -rf /opt/app/config
602 mkdir -p /opt/app/config
606 sed -e 's/\\n/\n/g' /opt/config/priv_key | sed -e 's/^[ \t]*//g; s/[ \t]*$//g' > /opt/app/config/key
607 chmod 777 /opt/app/config/key
609 # move keystone url file
610 #cp /opt/config/keystone_url.txt /opt/app/config/keystone_url.txt
613 URL_ROOT='nexus.onap.org/service/local/repositories/raw/content'
614 REPO_BLUEPRINTS='org.onap.dcaegen2.platform.blueprints'
615 REPO_DEPLOYMENTS='org.onap.dcaegen2.deployments'
616 if [ -e /opt/config/dcae_deployment_profile.txt ]; then
617 DEPLOYMENT_PROFILE=$(cat /opt/config/dcae_deployment_profile.txt)
619 DEPLOYMENT_PROFILE=${DEPLOYMENT_PROFILE:-R1}
621 NEXUS_USER=$(cat /opt/config/nexus_username.txt)
622 NEXUS_PASSWORD=$(cat /opt/config/nexus_password.txt)
623 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
624 DOCKER_VERSION=$(cat /opt/config/docker_version.txt)
625 # use rand_str as zone
626 ZONE=$(cat /opt/config/rand_str.txt)
627 MYFLOATIP=$(cat /opt/config/dcae_float_ip.txt)
628 MYLOCALIP=$(cat /opt/config/dcae_ip_addr.txt)
631 # start docker image pulling while we are waiting for A&AI to come online
632 docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
635 if [ "$DEPLOYMENT_PROFILE" == "R1" ]; then
636 RELEASE_TAG='releases'
637 # download blueprint input template files
638 rm -rf /opt/app/inputs-templates
639 mkdir -p /opt/app/inputs-templates
640 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/inputs.yaml
641 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/cdapinputs.yaml
642 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/phinputs.yaml
643 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/dhinputs.yaml
644 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/invinputs.yaml
645 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/vesinput.yaml
646 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/tcainputs.yaml
647 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/he-ip.yaml
648 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_BLUEPRINTS}/${RELEASE_TAG}/input-templates/hr-ip.yaml
650 # generate blueprint input files
651 pip install --upgrade jinja2
652 wget https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/scripts/detemplate-bpinputs.py \
654 (python detemplate-bpinputs.py /opt/config /opt/app/inputs-templates /opt/app/config; \
655 rm detemplate-bpinputs.py)
657 # Run docker containers
661 docker pull "$NEXUS_DOCKER_REPO/onap/org.onap.dcaegen2.deployments.bootstrap:$DOCKER_VERSION" \
662 && docker pull nginx &
664 #########################################
665 # Wait for then register with A&AI
666 ########################################
668 DNSAAS_PROXYED=$(tr '[:upper:]' '[:lower:]' < /opt/config/dnsaas_config_enabled.txt)
669 if [ "$DNSAAS_PROXYED" == 'true' ]; then
670 echo "Using proxyed DNSaaS service, performing additional registration and configuration"
673 register_multicloud_pod25_with_aai
674 register_multicloud_pod25dns_with_aai
676 verify_multicloud_registration
678 wait_for_multicloud_ready
679 register_dns_zone_proxied_designate "$ZONE"
680 echo "Registration and configuration for proxying DNSaaS completed."
682 echo "Using Designate DNSaaS service, performing additional registration and configuration"
683 register_dns_zone_designate "$ZONE"
686 #########################################
687 # Start DCAE Bootstrap container
688 #########################################
690 chmod 777 /opt/app/config
691 rm -f /opt/config/runtime.ip.consul
692 rm -f /opt/config/runtime.ip.cm
695 #docker login -u "$NEXUS_USER" -p "$NEXUS_PASSWORD" "$NEXUS_DOCKER_REPO"
696 #docker pull "$NEXUS_DOCKER_REPO/onap/org.onap.dcaegen2.deployments.bootstrap:$DOCKER_VERSION"
697 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"
700 # waiting for bootstrap to complete then starting nginx for proxying healthcheck calls
701 echo "Waiting for Consul to become accessible"
702 while [ ! -f /opt/app/config/runtime.ip.consul ]; do echo "."; sleep 30; done
705 # start proxy for consul's health check
706 CONSULIP=$(head -1 /opt/app/config/runtime.ip.consul | sed 's/[[:space:]]//g')
707 echo "Consul is available at $CONSULIP"
710 if [[ $DEPLOYMENT_PROFILE == R2* ]]; then
713 rm -rf /opt/app/inputs-templates
714 mkdir -p /opt/app/inputs-templates
715 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-1.yaml
716 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-2.yaml
717 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-3.yaml
718 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/docker-compose-4.yaml
719 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/register.sh
720 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/setup.sh
721 wget -P /opt/app/inputs-templates https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/heat/teardown.sh
723 pip install --upgrade jinja2
724 wget https://${URL_ROOT}/${REPO_DEPLOYMENTS}/${RELEASE_TAG}/scripts/detemplate-bpinputs.py \
726 (python detemplate-bpinputs.py /opt/config /opt/app/inputs-templates /opt/app/config; \
727 rm detemplate-bpinputs.py)
729 if [ -e /opt/app/config/register.sh ]; then
730 chmod +x /opt/app/config/register.sh
732 if [ -e /opt/app/config/setup.sh ]; then
733 chmod +x /opt/app/config/setup.sh
735 if [ -e /opt/app/config/build-plugins.sh ]; then
736 chmod +x /opt/app/config/build-plugins.sh
742 /opt/docker/docker-compose -f docker-compose-1.yaml up -d
743 echo "Waiting for Consul to come up ready"
744 while ! nc -z localhost 8500; do sleep 1; done
745 echo "Waiting for DB to come up ready"
746 while ! nc -z localhost 5432; do sleep 1; done
747 echo "Waiting for CBS to come up ready"
748 while ! nc -z localhost 10000; do sleep 1; done
749 echo "All dependencies are up, proceed to the next phase"
752 echo "Setup CloudifyManager and Registrator"
757 echo "Bring up DCAE MIN service components for R2 use cases"
758 /opt/docker/docker-compose -f docker-compose-2.yaml up -d
760 if [[ "$DEPLOYMENT_PROFILE" == "R2" || "$DEPLOYMENT_PROFILE" == "R2PLUS" ]]; then
761 echo "Bring up DCAE platform components"
762 /opt/docker/docker-compose -f docker-compose-3.yaml up -d
764 if [ "$DEPLOYMENT_PROFILE" == "R2PLUS" ]; then
765 echo "Bring up additional (plus) DCAE service components"
766 /opt/docker/docker-compose -f docker-compose-4.yaml up -d
770 # start proxy for consul's health check
771 CONSULIP=$(cat /opt/config/dcae_ip_addr.txt)
772 echo "Consul is available at $CONSULIP"
775 cat >./nginx.conf <<EOL
778 server_name dcae.simpledemo.onap.org;
779 root /www/healthcheck;
781 location /healthcheck {
782 try_files /services.yaml =404;
785 proxy_pass http://${CONSULIP}:8500/v1/health/state/passing;
788 try_files /r2mvp_healthy.yaml =404;
791 try_files /r2_healthy.yaml =404;
794 try_files /r2plus_healthy.yaml =404;
802 -p ${HEALTHPORT}:80 \
803 -v "$(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf" \
804 -v "/tmp/healthcheck:/www/healthcheck" \
805 --label "SERVICE_80_NAME=dcae-health" \
806 --label "SERVICE_80_CHECK_HTTP=/healthcheck" \
807 --label "SERVICE_80_CHECK_INTERVAL=15s" \
808 --label "SERVICE_80_CHECK_INITIAL_STATUS=passing" \
811 echo "Healthcheck API available at http://${MYFLOATIP}:${HEALTHPORT}/healthcheck"
812 echo " http://${MYFLOATIP}:${HEALTHPORT}/R1"
813 echo " http://${MYFLOATIP}:${HEALTHPORT}/R2MIN"
814 echo " http://${MYFLOATIP}:${HEALTHPORT}/R2PLUS"
816 # run forever for updating health status based on consul
820 rm -rf /tmp/healthcheck/*
821 # all registered services
822 SERVICES=$(curl -s http://consul:8500/v1/agent/services |jq '. | to_entries[] | .value.Service')
824 SERVICES=$(curl -s http://consul:8500/v1/health/state/passing | jq '.[] | .ServiceName')
826 # remove empty lines/entries
827 SERVICES=$(echo "$SERVICES" | sed '/^\s*\"\"\s*$/d' |sed '/^\s*$/d')
829 SERVICES_JSON=$(echo "$SERVICES" | sed 's/\"$/\",/g' | sed '$ s/.$//')
831 echo "$(date): running healthy services:"
832 echo ">>> " $SERVICES
833 PLT_CONSUL=$(echo "$SERVICES" |grep consul)
834 PLT_CBS=$(echo "$SERVICES" |grep "config_binding_service")
835 MVP_PG_HOLMES=$(echo "$SERVICES" |grep "pgHolmes")
836 MVP_VES=$(echo "$SERVICES" |grep "mvp.*ves")
837 MVP_TCA=$(echo "$SERVICES" |grep "mvp.*tca")
838 MVP_HR=$(echo "$SERVICES" |grep "mvp.*holmes-rule")
839 MVP_HE=$(echo "$SERVICES" |grep "mvp.*holmes-engine")
841 PLT_CM=$(echo "$SERVICES" |grep "cloudify.*manager")
842 PLT_DH=$(echo "$SERVICES" |grep "deployment.*handler")
843 PLT_PH=$(echo "$SERVICES" |grep "policy.*handler")
844 PLT_SCH=$(echo "$SERVICES" |grep "service.*change.*handler")
845 PLT_INV=$(echo "$SERVICES" |grep "inventory")
846 PLT_PG_INVENTORY=$(echo "$SERVICES" |grep "pgInventory")
848 PLUS_MHB=$(echo "$SERVICES" |grep "heartbeat")
849 PLUS_PRH=$(echo "$SERVICES" |grep "prh")
850 PLUS_MPR=$(echo "$SERVICES" |grep "mapper")
851 PLUS_TRAP=$(echo "$SERVICES" |grep "snmptrap")
853 DATA="{\"healthy\" : \"$(date)\", \"healthy_services\": [${SERVICES_JSON}]}"
854 if [[ -n "$PLT_CONSUL" && -n "$PLT_CBS" && -n "$MVP_PG_HOLMES" && -n "$MVP_VES" && \
855 -n "$MVP_TCA" && -n "$MVP_HR" && -n "$MVP_HE" ]]; then
856 echo "${DATA}" > /tmp/healthcheck/r2mvp_healthy.yaml
857 echo "${DATA}" > /tmp/healthcheck/services.yaml
858 echo ">>>>>> enough services satisfying R2MIN service deployment"
860 echo ">>>>>> not enough services satisfying R2MIN service deployment"
863 if [[ -n "$PLT_CONSUL" && -n "$PLT_CBS" && -n "$PLT_CM" && -n "$PLT_DH" && \
864 -n "$PLT_PH" && -n "$PLT_SCH" && -n "$PLT_INV" && -n "$PLT_PG_INVENTORY" ]]; then
865 echo ">>>>>> enough services satisfying R2 platform deployment"
866 echo "${DATA}" > /tmp/healthcheck/r2_healthy.yaml
868 if [[ -n "$PLUS_MHB" && -n "$PLUS_PRH" && -n "$PLUS_MPR" && -n "$PLUS_TRAP" ]]; then
869 echo ">>>>>> enough services satisfying R2PLUS deployment"
870 echo "${DATA}" > /tmp/healthcheck/r2plus_healthy.yaml
872 echo ">>>>>> not enough services satisfying R2PLUS service deployment"
875 echo ">>>>>> not enough services satisfying R2 platform or R2PLUS service deployment"