blob: 8c5b203b44b3022b09283b222e2707976aa66edf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
|