summaryrefslogtreecommitdiff
path: root/devstack/designate_plugins/backend-pdns4
blob: 3b75b2446a164b723da1cc113ade24452e31e25e (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Configure the powerdns backend

# Enable with:
# DESIGNATE_BACKEND_DRIVER=powerdns

# Dependencies:
# ``functions`` file
# ``designate`` configuration

# install_designate_backend - install any external requirements
# configure_designate_backend - make configuration changes, including those to other services
# init_designate_backend - initialize databases, etc.
# start_designate_backend - start any external services
# stop_designate_backend - stop any external services
# cleanup_designate_backend - remove transient data and cache

# Save trace setting
DP_PDNS_XTRACE=$(set +o | grep xtrace)
set +o xtrace

# Defaults
# --------
if is_fedora; then
    POWERDNS_CFG_DIR=/etc/pdns
else
    POWERDNS_CFG_DIR=/etc/powerdns
fi

# Entry Points
# ------------

# install_designate_backend - install any external requirements
function install_designate_backend {
    if is_ubuntu; then
        PDNS=pdns-server
    else
        die $LINENO "PDNS4 Backend plugin backend only supports Ubuntu"
    fi

    if is_service_enabled mysql; then
        PDNS+=" pdns-backend-mysql"
    elif is_service_enabled postgresql; then
        PDNS+=" pdns-backend-pgsql"
    else
        die $LINENO "PDNS4 backend only supports MySQL / pgSQL"
    fi

    install_package $PDNS
    sudo rm -rf $POWERDNS_CFG_DIR/pdns.d
}

# configure_designate_backend - make configuration changes, including those to other services
function configure_designate_backend {
    # Generate Designate pool.yaml file
    sudo tee $DESIGNATE_CONF_DIR/pools.yaml > /dev/null <<EOF
---
- name: default
  description: DevStack PowerDNS Pool
  attributes: {}

  ns_records:
    - hostname: $DESIGNATE_DEFAULT_NS_RECORD
      priority: 1

  nameservers:
    - host: $(ipv6_unquote $DESIGNATE_SERVICE_HOST)
      port: $DESIGNATE_SERVICE_PORT_DNS

  targets:
    - type: pdns4
      description: PowerDNS Database Cluster

      masters:
        - host: $(ipv6_unquote $DESIGNATE_SERVICE_HOST)
          port: $DESIGNATE_SERVICE_PORT_MDNS

      options:
        host: $(ipv6_unquote $DESIGNATE_SERVICE_HOST)
        port: $DESIGNATE_SERVICE_PORT_DNS
        api_endpoint: http://$DESIGNATE_SERVICE_HOST:8081
        api_token: changeme
EOF

    # Generate PowerDNS pdns.conf file
    sudo tee $POWERDNS_CFG_DIR/pdns.conf > /dev/null <<EOF
# General Config
setgid=pdns
setuid=pdns
config-dir=$POWERDNS_CFG_DIR
socket-dir=/var/run
guardian=yes
daemon=yes
disable-axfr=no
local-address=$HOST_IP
local-ipv6=$HOST_IPV6
local-port=$DESIGNATE_SERVICE_PORT_DNS
master=no
slave=yes
cache-ttl=0
query-cache-ttl=0
negquery-cache-ttl=0
webserver=yes
webserver-address=$(ipv6_unquote $DESIGNATE_SERVICE_HOST)
webserver-allow-from=$(ipv6_unquote $DESIGNATE_SERVICE_HOST),127.0.0.1,::1
api=yes
api-key=changeme
EOF

    if is_service_enabled mysql; then
        sudo tee -a $POWERDNS_CFG_DIR/pdns.conf > /dev/null <<EOF
# Launch gmysql backend
launch=gmysql

# gmysql parameters
gmysql-host=$MYSQL_HOST
gmysql-user=$DATABASE_USER
gmysql-password=$DATABASE_PASSWORD
gmysql-dbname=designate_pdns
gmysql-dnssec=yes
EOF
    elif is_service_enabled postgresql; then
        sudo tee -a $POWERDNS_CFG_DIR/pdns.conf > /dev/null <<EOF
# Launch gpgsql backend
launch=gpgsql

# gpgsql parameters
gpgsql-host=$DATABASE_HOST
gpgsql-user=$DATABASE_USER
gpgsql-password=$DATABASE_PASSWORD
gpgsql-dbname=designate_pdns
gpgsql-dnssec=yes
EOF
    else
        die $LINENO "PDNS4 backend only supports MySQL / pgSQL"
    fi
    restart_service pdns
}

# init_designate_backend - initialize databases, etc.
function init_designate_backend {
    # Stop pdns so that the migration succeeds, if not you get a error
    # that the schema is still in use.
    if is_service_enabled postgresql; then
        stop_designate_backend
    fi

    # (Re)create designate_pdns database
    recreate_database designate_pdns utf8
    if is_service_enabled mysql; then
            sudo mysql -u$DATABASE_USER -p$DATABASE_PASSWORD -h$MYSQL_HOST designate_pdns < $DESIGNATE_PLUGINS/backend-pdns4-mysql-db.sql
    elif is_service_enabled postgresql; then
            sudo psql -U root -d designate_pdns -f $DESIGNATE_PLUGINS/backend-pdns4-pgsql-db.sql
    else
        die $LINENO "PDNS4 backend only supports MySQL"
    fi
}

# create_designate_pool_configuration_backend - Perform post-pool config tasks
function create_designate_pool_configuration_backend {
    # Init and migrate designate_pdns database
    :
}

# start_designate_backend - start any external services
function start_designate_backend {
    start_service pdns
}


# stop_designate_backend - stop any external services
function stop_designate_backend {
    stop_service pdns
}

# cleanup_designate_backend - remove transient data and cache
function cleanup_designate_backend {
    :
}

# Restore xtrace
$DP_PDNS_XTRACE