3 # Configuration Fallbacks. All can(must for some of them) be overwritten by /etc/default/snf-network
5 # the bind server IP/FQDN
7 # this is the .vm.synnefo.live.
8 # Leave empty if only reverse dns management is needed.
9 # TODO: make this zone to be instance specific!!!
11 # the file with dns authorization keys
13 MAC2EUI64="/usr/bin/mac2eui64"
15 source /etc/default/snf-network
16 source /usr/lib/snf-network/common.sh
18 if [ -z "$SERVER" -o -z "$FZONE" -o ! -e "$KEYFILE" ]; then
25 nsupdate -k $KEYFILE > /dev/null << EOF
34 # ommit zone statement
35 # nsupdate will attempt determine the correct zone to update based on the rest of the input
39 hooks-log dnshook "$command"
40 nsupdate -k $KEYFILE > /dev/null << EOF
54 command="update $action $GANETI_INSTANCE_NAME.$FZONE $TTL A $IP"
55 send_command "$command"
61 update_aaaarecord () {
65 if [ -n "$EUI64" ]; then
66 command="update $action $GANETI_INSTANCE_NAME.$FZONE $TTL AAAA $EUI64"
67 send_command "$command"
78 command="update $action $RLPART.$RZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE"
79 send_command "$command"
84 update_ptr6record () {
88 if [ -n "$EUI64" ]; then
89 command="update $action $R6LPART$R6ZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE"
90 send_command "$command"
98 update_arecord $action
99 update_aaaarecord $action
100 update_ptrrecord $action
101 update_ptr6record $action
106 # first argument is an eui64 (IPv6)
107 # sets GLOBAL args R6REC, R6ZONE, R6LPART
108 # lets assume eui64=2001:648:2ffc:1::1
109 # the following commands produce:
110 # 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
111 # R6ZONE=1.0.0.0.c.f.f.2.8.4.6.0.1.0.0.2.ip6.arpa
112 # R6LPART=1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.
116 if [ -z "$eui64" ]; then
117 R6REC= ; R6ZONE= ; R6LPART= ;
119 R6REC=$(host $eui64 | egrep -o '([[:alnum:]]\.){32}ip6.arpa' )
120 R6ZONE=$(echo $R6REC | awk -F. 'BEGIN{rpart="";} { for (i=32;i>16;i=i-1) rpart=$i "." rpart; } END{print rpart "ip6.arpa";}')
121 R6LPART=$(echo $R6REC | awk -F. 'BEGIN{lpart="";} { for (i=16;i>0;i=i-1) lpart=$i "." lpart; } END{print lpart;}')
127 # first argument is an ipv4
128 # sets args RZONE, RLPART
129 # lets assume IP=203.0.113.1
130 # RZONE="113.0.203.in-add.arpa"
135 if [ -z "$ip" ]; then
141 a=$1 ; b=$2; c=$3; d=$4;
143 RZONE="$c.$b.$a.in-addr.arpa"
152 if [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_CREATE" ]; then
154 elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_REMOVE" ]; then
156 elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_RENAME" ]; then
158 # Let's override a variable and add ourselves
159 GANETI_INSTANCE_NAME=$GANETI_INSTANCE_NEW_NAME
161 elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_STARTUP" ]; then
163 elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_SHUTDOWN" ]; then
165 elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_REBOOT" ]; then
167 elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_SET_PARAMS" ]; then
174 # Query nameserver for entries related to the specific instance
175 # An example output is the following:
176 # www.google.com has address 173.194.113.114
177 # www.google.com has address 173.194.113.115
178 # www.google.com has address 173.194.113.116
179 # www.google.com has address 173.194.113.112
180 # www.google.com has address 173.194.113.113
181 # www.google.com has IPv6 address 2a00:1450:4001:80b::1012
184 HOSTQ="host -s -R 3 -W 3"
185 HOST_IP_ALL=$($HOSTQ $GANETI_INSTANCE_NAME.$FZONE $SERVER | sed -n 's/.*has address //p')
186 HOST_IP6_ALL=$($HOSTQ $GANETI_INSTANCE_NAME.$FZONE $SERVER | sed -n 's/.*has IPv6 address //p')
191 # Reset all entries related to the specific instance
192 # This should be invoced only during instance modification
193 # because we do not know which nics have been modify
196 if [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_SET_PARAMS" ]; then
198 # This should remove the A, AAAA, CNAME entries
199 send_command "update delete $GANETI_INSTANCE_NAME.$FZONE"
200 for ip in $HOST_IP_ALL; do
202 # This should remove the IPv4 reverse entry
203 send_command "update delete $RLPART.$RZONE"
205 for ip6 in $HOST_IP6_ALL; do
207 # This should remove the IPv6 reverse entry
208 send_command "update delete $R6LPART$R6ZONE."
218 # Exit if we do not have instance name.
219 # It should be exported to hooks for instance related opcodes.
220 if [ -z "$GANETI_INSTANCE_NAME" ]; then
224 # This runs only for instance modification
227 # If GANETI_INSTANCE_NIC_COUNT is not set then nothing happens
229 LAST=$((GANETI_INSTANCE_NIC_COUNT - 1))
230 for idx in $(seq $FIRST $LAST); do
231 ip=GANETI_INSTANCE_NIC${idx}_IP
232 mac=GANETI_INSTANCE_NIC${idx}_MAC
233 mode=GANETI_INSTANCE_NIC${idx}_MODE
234 link=GANETI_INSTANCE_NIC${idx}_LINK
235 subnet=GANETI_INSTANCE_NIC${idx}_NETWORK_SUBNET
236 subnet6=GANETI_INSTANCE_NIC${idx}_NETWORK_SUBNET6
237 tags=GANETI_INSTANCE_NIC${idx}_NETWORK_TAGS
242 eval SUBNET=\$$subnet
243 eval SUBNET6=\$$subnet6
251 get_eui64 "$MAC" "$SUBNET6"
252 get_rev6_info "$EUI64"
253 hooks-log dnshook "update dns for $GANETI_INSTANCE_NAME $IP $EUI64"