1 |
1 |
#!/bin/bash
|
2 |
2 |
|
3 |
|
set -e
|
4 |
|
|
5 |
3 |
# Configuration Fallbacks. All can(must for some of them) be overwritten by /etc/default/snf-network
|
6 |
4 |
TTL=300
|
7 |
5 |
# the bind server IP/FQDN
|
... | ... | |
16 |
14 |
|
17 |
15 |
source /etc/default/snf-network
|
18 |
16 |
|
19 |
|
if [ -z "$SERVER" -o -z "$FZONE" -o -z "$KEYFILE" ]; then
|
|
17 |
if [ -z "$SERVER" -o -z "$FZONE" -o ! -e "$KEYFILE" ]; then
|
20 |
18 |
exit 0
|
21 |
19 |
fi
|
22 |
20 |
|
... | ... | |
36 |
34 |
# nsupdate will attempt determine the correct zone to update based on the rest of the input
|
37 |
35 |
send_command () {
|
38 |
36 |
|
39 |
|
local command="$1"
|
40 |
|
nsupdate -k $KEYFILE > /dev/null << EOF
|
41 |
|
server $SERVER
|
42 |
|
$command
|
43 |
|
send
|
|
37 |
local command="$1"
|
|
38 |
hooks-log dnshook "$command"
|
|
39 |
nsupdate -k $KEYFILE > /dev/null << EOF
|
|
40 |
server $SERVER
|
|
41 |
$command
|
|
42 |
send
|
44 |
43 |
EOF
|
45 |
44 |
|
46 |
45 |
}
|
47 |
46 |
|
48 |
47 |
|
49 |
|
addremove_arecord () {
|
|
48 |
update_arecord () {
|
50 |
49 |
|
51 |
50 |
local action=$1
|
52 |
51 |
local command=
|
... | ... | |
54 |
53 |
command="update $action $GANETI_INSTANCE_NAME.$FZONE $TTL A $IP"
|
55 |
54 |
send_command "$command"
|
56 |
55 |
fi
|
|
56 |
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
update_aaaarecord () {
|
|
61 |
|
|
62 |
local action=$1
|
|
63 |
local command=
|
57 |
64 |
if [ -n "$EUI64" ]; then
|
58 |
65 |
command="update $action $GANETI_INSTANCE_NAME.$FZONE $TTL AAAA $EUI64"
|
59 |
66 |
send_command "$command"
|
... | ... | |
61 |
68 |
|
62 |
69 |
}
|
63 |
70 |
|
64 |
|
addremove_ptrrecord () {
|
|
71 |
|
|
72 |
update_ptrrecord () {
|
65 |
73 |
|
66 |
74 |
local action=$1
|
67 |
75 |
local command=
|
68 |
76 |
if [ -n "$IP" ]; then
|
69 |
|
command="update $action $RLPART.$RZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE"
|
|
77 |
command="update $action $RLPART.$RZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE"
|
70 |
78 |
send_command "$command"
|
71 |
79 |
fi
|
|
80 |
|
|
81 |
}
|
|
82 |
|
|
83 |
update_ptr6record () {
|
|
84 |
|
|
85 |
local action=$1
|
|
86 |
local command=
|
72 |
87 |
if [ -n "$EUI64" ]; then
|
73 |
|
command="update $action $R6LPART.$R6ZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE"
|
|
88 |
command="update $action $R6LPART$R6ZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE"
|
74 |
89 |
send_command "$command"
|
75 |
90 |
fi
|
76 |
91 |
|
77 |
92 |
}
|
78 |
93 |
|
|
94 |
update_all () {
|
|
95 |
|
|
96 |
local action=$1
|
|
97 |
update_arecord $action
|
|
98 |
update_aaaarecord $action
|
|
99 |
update_ptrrecord $action
|
|
100 |
update_ptr6record $action
|
|
101 |
|
|
102 |
}
|
|
103 |
|
79 |
104 |
|
80 |
105 |
# first argument is an eui64 (IPv6)
|
81 |
106 |
# sets GLOBAL args R6REC, R6ZONE, R6LPART
|
82 |
|
# lets assume eui64=eui64=2001:648:2ffc:1::1
|
|
107 |
# lets assume eui64=2001:648:2ffc:1::1
|
83 |
108 |
# the following commands produce:
|
84 |
109 |
# R6REC=1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.c.f.f.2.8.4.6.0.1.0.0.2.ip6.arpa
|
85 |
110 |
# R6ZONE=1.0.0.0.c.f.f.2.8.4.6.0.1.0.0.2.ip6.arpa
|
... | ... | |
124 |
149 |
update_dns () {
|
125 |
150 |
|
126 |
151 |
if [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_CREATE" ]; then
|
127 |
|
update_arecord add
|
128 |
|
update_ptrrecord add
|
|
152 |
update_all add
|
129 |
153 |
elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_REMOVE" ]; then
|
130 |
|
update_arecord delete
|
131 |
|
update_ptrrecord delete
|
|
154 |
update_all delete
|
132 |
155 |
elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_RENAME" ]; then
|
133 |
|
update_arecord delete
|
134 |
|
update_ptrrecord delete
|
|
156 |
update_all delete
|
135 |
157 |
# Let's override a variable and add ourselves
|
136 |
158 |
GANETI_INSTANCE_NAME=$GANETI_INSTANCE_NEW_NAME
|
137 |
|
update_arecord add
|
138 |
|
update_ptrrecord add
|
|
159 |
update_all add
|
139 |
160 |
elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_STARTUP" ]; then
|
140 |
|
update_arecord add
|
141 |
|
update_ptrrecord add
|
|
161 |
update_all add
|
142 |
162 |
elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_SHUTDOWN" ]; then
|
143 |
|
update_arecord delete
|
144 |
|
update_ptrrecord delete
|
|
163 |
update_all delete
|
145 |
164 |
elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_REBOOT" ]; then
|
146 |
|
update_arecord add
|
147 |
|
update_ptrrecord add
|
|
165 |
update_all add
|
148 |
166 |
elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_SET_PARAMS" ]; then
|
149 |
|
update_arecord add
|
150 |
|
update_ptrrecord add
|
|
167 |
update_all add
|
151 |
168 |
fi
|
152 |
169 |
|
153 |
170 |
}
|
... | ... | |
178 |
195 |
if [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_SET_PARAMS" ]; then
|
179 |
196 |
query_dns
|
180 |
197 |
# This should remove the A, AAAA, CNAME entries
|
181 |
|
run_action "update delete $GANETI_INSTANCE_NAME.$FZONE"
|
|
198 |
send_command "update delete $GANETI_INSTANCE_NAME.$FZONE"
|
182 |
199 |
for ip in $HOST_IP_ALL; do
|
183 |
200 |
get_rev4_info $ip
|
184 |
201 |
# This should remove the IPv4 reverse entry
|
185 |
|
run_action "update delete $RLPART.$RZONE"
|
|
202 |
send_command "update delete $RLPART.$RZONE"
|
186 |
203 |
done
|
187 |
204 |
for ip6 in $HOST_IP6_ALL; do
|
188 |
205 |
get_rev6_info $ip6
|
189 |
206 |
# This should remove the IPv6 reverse entry
|
190 |
|
run_action "update delete $R6LPART$R6ZONE."
|
|
207 |
send_command "update delete $R6LPART$R6ZONE."
|
191 |
208 |
done
|
192 |
209 |
fi
|
193 |
210 |
|
... | ... | |
214 |
231 |
|
215 |
232 |
# Main starts here
|
216 |
233 |
|
|
234 |
|
217 |
235 |
# Exit if we do not have instance name.
|
218 |
236 |
# It should be exported to hooks for instance related opcodes.
|
219 |
|
if [ -z "$GANETI_INSTNACE_NAME" ]; then
|
|
237 |
if [ -z "$GANETI_INSTANCE_NAME" ]; then
|
220 |
238 |
exit 0
|
221 |
239 |
fi
|
222 |
240 |
|
... | ... | |
249 |
267 |
get_rev4_info "$IP"
|
250 |
268 |
get_eui64 "$MAC" "$SUBNET6"
|
251 |
269 |
get_rev6_info "$EUI64"
|
|
270 |
hooks-log dnshook "update dns for $GANETI_INSTANCE_NAME $IP $EUI64"
|
252 |
271 |
update_dns
|
253 |
272 |
|
254 |
273 |
;;
|