forked from desrod/maas-autobuilder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_dns_records.sh
executable file
·83 lines (63 loc) · 2.18 KB
/
add_dns_records.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
. functions.sh
setup_domain()
{
domains=$(maas ${maas_profile} domains read)
my_domain=$(echo $domains | jq '.[] | select(.name=="example.com")')
if [[ -z $my_domain ]] ; then
maas ${maas_profile} domains create name="example.com"
fi
}
get_ip_from_juju()
{
from_app=""
case $dns_name in
"landscape")
juju_name="landscape-haproxy"
from_app="true"
;;
"graylog"|"nagios")
juju_name=${dns_name}
from_app="true"
;;
"dashboard")
juju_name="openstack-dashboard"
;;
"neutron")
juju_name="neutron-api"
;;
"nova")
juju_name="nova-cloud-controller"
;;
*)
juju_name=${dns_name}
;;
esac
[[ -n "$from_app" ]] && juju status ${juju_name} --format json | jq .applications[\"${juju_name}\"].units[][\"public-address\"] | sed s/\"//g
[[ -z "$from_app" ]] && juju config ${juju_name} vip
}
add_record()
{
dns_name=$1
maas_dns_ip=$(get_ip_from_juju $dns_name)
dns_name_result=$(maas ${maas_profile} dnsresources read name=${dns_name}-internal)
if [[ -n $(echo $dns_name_result | jq .[]) ]] ; then
dns_id=$(echo $dns_name_result | jq .[].id)
dns_ip=$(maas ${maas_profile} dnsresource update ${dns_id} fqdn=${dns_name}-internal.example.com ip_addresses=${maas_dns_ip})
else
dns_ip=$(maas ${maas_profile} dnsresources create fqdn=${dns_name}-internal.example.com ip_addresses=${maas_dns_ip})
fi
dns_cname_result=$(maas ${maas_profile} dnsresource-records read rrtype=CNAME name=${dns_name})
if [[ -n $(echo $dns_cname_result | jq .[]) ]] ; then
dns_id=$(echo $dns_cname_result | jq .[].id)
dns_cname=$(maas ${maas_profile} dnsresource-record update ${dns_id} rrtype=cname rrdata=${dns_name}-internal.example.com.)
else
dns_cname=$(maas ${maas_profile} dnsresource-records create fqdn=${dns_name}.example.com rrtype=cname rrdata=${dns_name}-internal.example.com.)
fi
}
read_configs
maas_login
setup_domain
for app in ${maas_dns_names[*]} landscape graylog nagios ; do
add_record ${app}
done