Revision 264562c1 common.sh

b/common.sh
207 207
  fi
208 208

  
209 209
}
210

  
211

  
212
# DDNS related functions
213

  
214
# ommit zone statement
215
# nsupdate  will attempt determine the correct zone to update based on the rest of the input
216
send_command () {
217

  
218
  local command="$1"
219
  hooks-log dnshook "$command"
220
  nsupdate -k $KEYFILE > /dev/null << EOF
221
  server $SERVER
222
  $command
223
  send
224
EOF
225

  
226
}
227

  
228

  
229
update_arecord () {
230

  
231
  local action=$1
232
  local command=
233
  if [ -n "$IP" ]; then
234
    command="update $action $GANETI_INSTANCE_NAME.$FZONE $TTL A $IP"
235
    send_command "$command"
236
  fi
237

  
238
}
239

  
240

  
241
update_aaaarecord () {
242

  
243
  local action=$1
244
  local command=
245
  if [ -n "$EUI64" ]; then
246
    command="update $action $GANETI_INSTANCE_NAME.$FZONE $TTL AAAA $EUI64"
247
    send_command "$command"
248
  fi
249

  
250
}
251

  
252

  
253
update_ptrrecord () {
254

  
255
  local action=$1
256
  local command=
257
  if [ -n "$IP" ]; then
258
    command="update $action $RLPART.$RZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE"
259
    send_command "$command"
260
  fi
261

  
262
}
263

  
264
update_ptr6record () {
265

  
266
  local action=$1
267
  local command=
268
  if [ -n "$EUI64" ]; then
269
    command="update $action $R6LPART$R6ZONE. $TTL PTR $GANETI_INSTANCE_NAME.$FZONE"
270
    send_command "$command"
271
  fi
272

  
273
}
274

  
275
update_all () {
276

  
277
  local action=$1
278
  update_arecord $action
279
  update_aaaarecord $action
280
  update_ptrrecord $action
281
  update_ptr6record $action
282

  
283
}
284

  
285

  
286
# first argument is an eui64 (IPv6)
287
# sets GLOBAL args R6REC, R6ZONE, R6LPART
288
# lets assume eui64=2001:648:2ffc:1::1
289
# the following commands produce:
290
# 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
291
# R6ZONE=1.0.0.0.c.f.f.2.8.4.6.0.1.0.0.2.ip6.arpa
292
# R6LPART=1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.
293
get_rev6_info () {
294

  
295
  local eui64=$1
296
  if [ -z "$eui64" ]; then
297
    R6REC= ; R6ZONE= ; R6LPART= ;
298
  else
299
    R6REC=$(host $eui64 | egrep -o '([[:alnum:]]\.){32}ip6.arpa' )
300
    R6ZONE=$(echo $R6REC | awk -F. 'BEGIN{rpart="";} { for (i=32;i>16;i=i-1) rpart=$i "." rpart; } END{print rpart "ip6.arpa";}')
301
    R6LPART=$(echo $R6REC | awk -F. 'BEGIN{lpart="";} { for (i=16;i>0;i=i-1) lpart=$i "." lpart; } END{print lpart;}')
302
  fi
303

  
304
}
305

  
306

  
307
# first argument is an ipv4
308
# sets args RZONE, RLPART
309
# lets assume IP=203.0.113.1
310
# RZONE="113.0.203.in-add.arpa"
311
# RLPART="1"
312
get_rev4_info () {
313

  
314
  local ip=$1
315
  if [ -z "$ip" ]; then
316
    RZONE= ; RLPART= ;
317
  else
318
    OLDIFS=$IFS
319
    IFS=". "
320
    set -- $ip
321
    a=$1 ; b=$2; c=$3; d=$4;
322
    IFS=$OLDIFS
323
    RZONE="$c.$b.$a.in-addr.arpa"
324
    RLPART="$d"
325
  fi
326

  
327
}
328

  
329

  
330
# Query nameserver for entries related to the specific instance
331
# An example output is the following:
332
# www.google.com has address 173.194.113.114
333
# www.google.com has address 173.194.113.115
334
# www.google.com has address 173.194.113.116
335
# www.google.com has address 173.194.113.112
336
# www.google.com has address 173.194.113.113
337
# www.google.com has IPv6 address 2a00:1450:4001:80b::1012
338
query_dns () {
339

  
340
  HOSTQ="host -s -R 3 -W 3"
341
  HOST_IP_ALL=$($HOSTQ $GANETI_INSTANCE_NAME.$FZONE $SERVER | sed -n 's/.*has address //p')
342
  HOST_IP6_ALL=$($HOSTQ $GANETI_INSTANCE_NAME.$FZONE $SERVER | sed -n 's/.*has IPv6 address //p')
343

  
344
}

Also available in: Unified diff