Statistics
| Branch: | Tag: | Revision:

root / snf-network-dnshook @ 8a567d09

History | View | Annotate | Download (2.5 kB)

1
#!/bin/bash
2

    
3
# Configuration Fallbacks. All can(must for some of them) be overwritten by /etc/default/snf-network
4
TTL=300
5
# the bind server IP/FQDN
6
SERVER=""
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!!!
10
FZONE=""
11
# the file with dns authorization keys
12
KEYFILE=""
13

    
14
source /etc/default/snf-network
15
source /usr/lib/snf-network/common.sh
16

    
17
if [ -z "$SERVER" -o -z "$FZONE" -o ! -e "$KEYFILE" ]; then
18
  exit 0
19
fi
20

    
21
# Query nameserver for entries related to the specific instance
22
# An example output is the following:
23
# www.google.com has address 173.194.113.114
24
# www.google.com has address 173.194.113.115
25
# www.google.com has address 173.194.113.116
26
# www.google.com has address 173.194.113.112
27
# www.google.com has address 173.194.113.113
28
# www.google.com has IPv6 address 2a00:1450:4001:80b::1012
29
query_dns () {
30

    
31
  HOSTQ="host -s -R 3 -W 3"
32
  HOST_IP_ALL=$($HOSTQ $GANETI_INSTANCE_NAME.$FZONE $SERVER | sed -n 's/.*has address //p')
33
  HOST_IP6_ALL=$($HOSTQ $GANETI_INSTANCE_NAME.$FZONE $SERVER | sed -n 's/.*has IPv6 address //p')
34

    
35
}
36

    
37

    
38
# Reset all entries related to the specific instance
39
# This should be invoced only during instance modification
40
# because we do not know which nics have been modify
41
reset_dns () {
42

    
43
  # This should remove the A, AAAA, CNAME entries
44
  send_command "update delete $GANETI_INSTANCE_NAME.$FZONE"
45
  for ip in $HOST_IP_ALL; do
46
    get_rev4_info $ip
47
    # This should remove the IPv4 reverse entry
48
    send_command "update delete $RLPART.$RZONE"
49
  done
50
  for ip6 in $HOST_IP6_ALL; do
51
    get_rev6_info $ip6
52
    # This should remove the IPv6 reverse entry
53
    send_command "update delete $R6LPART$R6ZONE."
54
  done
55

    
56
}
57

    
58
rename_instance (){
59

    
60
  for ip in $HOST_IP_ALL; do
61
    get_rev4_info $ip
62
    (
63
      GANETI_INSTANCE_NAME=$GANETI_INSTANCE_NEW_NAME
64
      IP=$ip
65
      update_arecord add
66
      update_ptrrecord add
67
    )
68
  done
69
  for ip6 in $HOST_IP6_ALL; do
70
    get_rev6_info $ip6
71
    (
72
      GANETI_INSTANCE_NAME=$GANETI_INSTANCE_NEW_NAME
73
      EUI64=$ip6
74
      update_aaaarecord add
75
      update_ptr6record add
76
    )
77
  done
78

    
79
}
80

    
81

    
82
# Main starts here
83

    
84

    
85
# Exit if we do not have instance name.
86
# It should be exported to hooks for instance related opcodes.
87
if [ -z "$GANETI_INSTANCE_NAME" ]; then
88
  exit 0
89
fi
90

    
91
if [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_REMOVE" ]; then
92
  query_dns
93
  reset_dns
94
elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_RENAME" ]; then
95
  query_dns
96
  reset_dns
97
  rename_instance
98
elif [ "x$GANETI_OP_CODE" = "xOP_INSTANCE_SHUTDOWN" ]; then
99
  query_dns
100
  reset_dns
101
fi