aboutsummaryrefslogtreecommitdiffstats
path: root/boot
diff options
context:
space:
mode:
authorLusheng Ji <lji@research.att.com>2017-11-21 22:26:36 -0500
committerLusheng Ji <lji@research.att.com>2017-11-21 22:38:28 -0500
commitce34d8a702ab6fe99dab6d6a94b2600bd1464e59 (patch)
tree92741fb65a831ef34a4fc790dea27867849a8446 /boot
parenta75ed9aa10de1b3afd53839dbf5e7ccfc49c3a21 (diff)
Add direct designate zone creation code
Added DNS zone creation code for OpenStack installations with Designate support. Previously for this type of OpenStack instaalations we assumed that there was no need to create new zone. But such assumption is not consistent with the DACE blueprints. Therefore the blueprints working for proxied Designate OpenStack installation will break not work for direct Designate OpenStack installations. This new change makes the vm_init behaves consistently for both direct Designate and proxied Designate so that the same blueprint can be use in both environments. Issue-ID: DCAEGEN2-200 Change-Id: I1f82f60facad77849c67f0feb1fa07f02af1079e Signed-off-by: Lusheng Ji <lji@research.att.com>
Diffstat (limited to 'boot')
-rwxr-xr-xboot/dcae2_vm_init.sh84
1 files changed, 81 insertions, 3 deletions
diff --git a/boot/dcae2_vm_init.sh b/boot/dcae2_vm_init.sh
index 0d9bebce..570cb704 100755
--- a/boot/dcae2_vm_init.sh
+++ b/boot/dcae2_vm_init.sh
@@ -344,7 +344,7 @@ verify_multicloud_registration()
}
-register_dns_zone()
+register_dns_zone_proxied_designate()
{
local CLOUD_OWNER='pod25'
local CLOUD_REGION
@@ -426,6 +426,83 @@ register_dns_zone()
}
+register_dns_zone_designate()
+{
+ local HEADER_CONTENT_TYPE_JSON="Content-Type: application/json"
+ local HEADER_ACCEPT_JSON="Accept: application/json"
+ local HEADER_TOKEN
+ local DCAE_ZONE
+ local DCAE_DOMAIN
+ local ZONE_NAME
+ local ZONE_ID
+ local KEYSTONE_URL
+ local API_ENDPOINT
+ local API_DATA
+ local TENANT_NAME
+ local TENANT_ID
+ local ZONE_PROJECT_ID
+
+ if [ -z "$1" ]; then DCAE_ZONE="$(cat /opt/config/dcae_zone.txt)"; else DCAE_ZONE="$1"; fi
+ DCAE_DOMAIN="$(cat /opt/config/dcae_domain.txt)"
+ ZONE_NAME="${DCAE_ZONE}.${DCAE_DOMAIN}."
+
+ TENANT_NAME="$(cat /opt/config/tenant_name.txt)"
+ TENANT_ID="$(cat /opt/config/tenant_id.txt)"
+
+ KEYSTONE_URL="$(cat /opt/config/openstack_keystone_url.txt)"
+ USERNAME="$(cat /opt/config/openstack_user.txt)"
+ PASSWORD="$(cat /opt/config/openstack_password.txt)"
+
+
+ API_ENDPOINT="${KEYSTONE_URL}/tokens"
+ API_DATA="{\"auth\": {\"project\": \"${TENANT_NAME}\", \"tenantId\": \"${TENANT_ID}\", \"passwordCredentials\": {\"username\": \"${USERNAME}\", \"password\": \"${PASSWORD}\"}}}"
+
+ echo "===> Getting token from ${API_ENDPOINT}"
+ RESP=$(curl -s -v -H "${HEADER_CONTENT_TYPE_JSON}" -d "${API_DATA}" "${API_ENDPOINT}")
+
+ TOKEN="$(echo ${RESP} | jq -r .access.token.id)"
+ if [ -z "$TOKEN" ]; then
+ echo "Faile to acquire token for creating DNS zone. Exit"
+ exit 1
+ fi
+ HEADER_TOKEN="X-Auth-Token: ${TOKEN}"
+
+
+ DESIGNATE_URL=$(echo ${RESP} | jq -r '.access.serviceCatalog[] | select(.name=="designate") | .endpoints[0].publicURL')
+ if [ -z ${DESIGNATE_URL} ]; then
+ echo "Fail to find Designate API endpoint. Exit"
+ exit 1
+ fi
+
+
+ API_ENDPOINT="${DESIGNATE_URL}/v2/zones"
+ echo "===> Register DNS zone $ZONE_NAME at Designate API endpoint ${API_ENDPOINT}"
+
+ RESP=$(curl -v -s -H $HEADER_TOKEN $API_ENDPOINT)
+ ZONE_ID=$(echo $RESP |jq -r --arg ZONE_NAME "$ZONE_NAME" '.zones[] |select(.name==$ZONE_NAME) |.id')
+ if [ -z "$ZONE_ID" ]; then
+ echo "======> Zone ${ZONE_NAME} does not exist. Create"
+ API_DATA="{\"name\": \"${ZONE_NAME}\", \"email\": \"dcae@onap.org\", \"type\": \"PRIMARY\", \"ttl\": 7200, \"description\": \"DCAE DNS zoen created for ONAP deployment $DCAE_ZONE\"}"
+ RESP=$(curl -s -v -X POST -H "$HEADER_ACCEPT_JSON" -H "$HEADER_CONTENT_TYPE_JSON" -H "$HEADER_TOKEN" -d "$API_DATA" "$API_ENDPOINT")
+ ZONE_ID=$(echo $RESP | jq .id)
+
+ if [ -z "$ZONE_ID" ]; then
+ echo "Fail to create DNS zone ${ZONE_NAME}. Exit"
+ exit 1
+ fi
+ else
+ echo "======> Zone ${ZONE_NAME} already exists."
+ API_ENDPOINT="${DESIGNATE_URL}/v2/zones/${ZONE_ID}"
+ RESP=$(curl -s -v -H "$HEADER_ACCEPT_JSON" -H "$HEADER_TOKEN" "$API_ENDPOINT")
+ ZONE_PROJECT_ID=$(echo $RESP | jq -r .project_id)
+ if [ "$ZONE_PROJECT_ID" != "noauth-project" ] && [ "$ZONE_PROJECT_ID" != "$TENANT_ID" ]; then
+ echo "======> Zone ${ZONE_NAME} owned by other projects, may have problem creating records"
+ else
+ echo "======> Zone ${ZONE_NAME} okay to create new records"
+ fi
+ fi
+}
+
delete_dns_zone()
{
local CLOUD_OWNER='pod25'
@@ -541,10 +618,11 @@ if [ "$DNSAAS_PROXYED" == 'true' ]; then
verify_multicloud_registration
wait_for_multicloud_ready
- register_dns_zone "$ZONE"
+ register_dns_zone_proxied_designate "$ZONE"
echo "Registration and configuration for proxying DNSaaS completed."
else
- echo "Using proxyed DNSaaS service, performing additional registration and configuration"
+ echo "Using Designate DNSaaS service, performing additional registration and configuration"
+ register_dns_zone_designate "$ZONE"
fi