From 32086f62131e1b813e2f3d97bc2c78f66c6a3154 Mon Sep 17 00:00:00 2001 From: Carlos Konstanski Date: Wed, 13 Dec 2017 18:54:21 -0700 Subject: adding files --- files/dns.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 files/dns.sh (limited to 'files/dns.sh') diff --git a/files/dns.sh b/files/dns.sh new file mode 100755 index 0000000..8c5b203 --- /dev/null +++ b/files/dns.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +instance_name="${1}" +floating_ip="${2}" + +if [ "${instance_name}" == "" ]; then + echo "No instance name supplied." >&2 + exit 1 +elif [ "${floating_ip}" == "" ]; then + echo "No floating IP supplied." >&2 + exit 1 +fi + +domain_id=$(designate domain-list 2>/dev/null | grep -F "cloud.twc.net" | awk '{print $2;}') +if [ "${domain_id}" == "" ]; then + echo -n "Could not find the domain. It must be created in Horizon " >&2 + echo -n "prior to running this playbook so that the project will " >&2 + echo "get correctly wired up to infoblox." >&2 + exit 1 +else + domain_name=$(designate domain-list 2>/dev/null | grep -F "cloud.twc.net" | awk '{print $4;}') + fqdn="${instance_name}.${domain_name}" +fi + +record_id=$(designate record-list ${domain_id} 2>/dev/null | grep -F "${fqdn}" | grep -F ' A ' | awk '{print $2;}') +if [ "${record_id}" == "" ]; then + designate record-create ${domain_id} --type A --name "${fqdn}" --data ${floating_ip} >/dev/null 2>&1 + record_id=$(designate record-list ${domain_id} 2>/dev/null | grep -F "${fqdn}" | grep -F ' A ' | awk '{print $2;}') + if [ "${record_id}" == "" ]; then + echo "No existing A record. Cannot create A record." >&2 + exit 1 + fi +else + target_ip=$(designate record-list ${domain_id} 2>/dev/null | grep -F "${fqdn}" | grep -F ' A ' | awk '{print $8;}') + if [ "${target_ip}" != "${floating_ip}" ]; then + designate record-delete ${domain_id} ${record_id} >/dev/null 2>&1 + designate record-create ${domain_id} --type A --name "${fqdn}" --data ${floating_ip} >/dev/null 2>&1 + record_id=$(designate record-list ${domain_id} 2>/dev/null |grep -F "${fqdn}" | grep -F ' A ' | awk '{print $2;}') + if [ "${record_id}" == "" ]; then + echo "Existing A record had wrong IP. Cannot create A record." >&2 + exit 1 + fi + fi +fi + +echo "${fqdn::-1}" + +exit 0 -- cgit v1.3