Browse Source

Add PowerDNS 4 driver

Fixes-Bug: #1590429

Change-Id: I1f6017ce83a49dc0c3827c540ac18186bb14f72b
Graham Hayes 2 years ago
parent
commit
aa23d86835

+ 82
- 0
designate/backend/impl_pdns4.py View File

@@ -0,0 +1,82 @@
1
+# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P.
2
+#
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
7
+#      http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+import urlparse
15
+
16
+import requests
17
+from oslo_log import log as logging
18
+from oslo_config import cfg
19
+
20
+from designate import exceptions
21
+from designate.backend import base
22
+
23
+
24
+LOG = logging.getLogger(__name__)
25
+CONF = cfg.CONF
26
+
27
+
28
+class PDNS4Backend(base.Backend):
29
+    __plugin_name__ = 'pdns4'
30
+
31
+    __backend_status__ = 'release-compatible'
32
+
33
+    def __init__(self, target):
34
+        super(PDNS4Backend, self).__init__(target)
35
+
36
+        self.api_endpoint = self.options.get('api_endpoint')
37
+        self.api_token = self.options.get('api_token')
38
+
39
+    def _build_url(self, zone=''):
40
+        r_url = urlparse.urlparse(self.api_endpoint)
41
+        return "%s://%s/api/v1/servers/localhost/zones%s%s" % (
42
+            r_url.scheme, r_url.netloc, '/' if zone else '', zone)
43
+
44
+    def create_zone(self, context, zone):
45
+        """Create a DNS zone"""
46
+
47
+        masters = \
48
+            ['%s:%d' % (master.host, master.port) for master in self.masters]
49
+
50
+        data = {
51
+            "name": zone.name,
52
+            "kind": "slave",
53
+            "masters": masters,
54
+
55
+        }
56
+        headers = {
57
+            "X-API-Key": self.api_token
58
+        }
59
+
60
+        try:
61
+            requests.post(
62
+                self._build_url(),
63
+                json=data,
64
+                headers=headers
65
+            ).raise_for_status()
66
+        except requests.HTTPError as e:
67
+            raise exceptions.Backend(e)
68
+
69
+    def delete_zone(self, context, zone):
70
+        """Delete a DNS zone"""
71
+
72
+        headers = {
73
+            "X-API-Key": self.api_token
74
+        }
75
+
76
+        try:
77
+            requests.delete(
78
+                self._build_url(zone.name),
79
+                headers=headers
80
+            ).raise_for_status()
81
+        except requests.HTTPError as e:
82
+            raise exceptions.Backend(e)

+ 1
- 1
designate/backend/impl_powerdns/__init__.py View File

@@ -40,7 +40,7 @@ def _map_col(keys, col):
40 40
 class PowerDNSBackend(base.Backend):
41 41
     __plugin_name__ = 'powerdns'
42 42
 
43
-    __backend_status__ = 'integrated'
43
+    __backend_status__ = 'deprecated'
44 44
 
45 45
     @classmethod
46 46
     def get_cfg_opts(cls):

+ 181
- 0
devstack/designate_plugins/backend-pdns4 View File

@@ -0,0 +1,181 @@
1
+# Configure the powerdns backend
2
+
3
+# Enable with:
4
+# DESIGNATE_BACKEND_DRIVER=powerdns
5
+
6
+# Dependencies:
7
+# ``functions`` file
8
+# ``designate`` configuration
9
+
10
+# install_designate_backend - install any external requirements
11
+# configure_designate_backend - make configuration changes, including those to other services
12
+# init_designate_backend - initialize databases, etc.
13
+# start_designate_backend - start any external services
14
+# stop_designate_backend - stop any external services
15
+# cleanup_designate_backend - remove transient data and cache
16
+
17
+# Save trace setting
18
+DP_PDNS_XTRACE=$(set +o | grep xtrace)
19
+set +o xtrace
20
+
21
+# Defaults
22
+# --------
23
+if is_fedora; then
24
+    POWERDNS_CFG_DIR=/etc/pdns
25
+else
26
+    POWERDNS_CFG_DIR=/etc/powerdns
27
+fi
28
+
29
+# Entry Points
30
+# ------------
31
+
32
+# install_designate_backend - install any external requirements
33
+function install_designate_backend {
34
+    if is_ubuntu; then
35
+        GetOSVersion
36
+        if  [ "$os_CODENAME" = "trusty" ]; then
37
+            sudo tee /etc/apt/sources.list.d/pdns.list > /dev/null <<EOF
38
+deb [arch=amd64] http://repo.powerdns.com/ubuntu trusty-auth-40 main
39
+EOF
40
+            sudo tee /etc/apt/preferences.d/pdns > /dev/null <<EOF
41
+Package: pdns-*
42
+Pin: origin repo.powerdns.com
43
+Pin-Priority: 600
44
+EOF
45
+            curl https://repo.powerdns.com/FD380FBB-pub.asc | sudo apt-key add - &&
46
+            sudo apt-get update
47
+        elif [ "$os_CODENAME" = "xenial" ]; then
48
+            echo "Use PDNS4 from apt repo"
49
+        else
50
+            die $LINENO "PDNS4 backend only supports trusty or xenial"
51
+        fi
52
+        PDNS=pdns-server
53
+    else
54
+        die $LINENO "PDNS4 Backend plugin backend only supports Ubuntu"
55
+    fi
56
+
57
+    if is_service_enabled mysql; then
58
+        PDNS+=" pdns-backend-mysql"
59
+    else
60
+        die $LINENO "PDNS4 backend only supports MySQL"
61
+    fi
62
+
63
+    install_package $PDNS
64
+    sudo rm -rf $POWERDNS_CFG_DIR/pdns.d
65
+}
66
+
67
+# configure_designate_backend - make configuration changes, including those to other services
68
+function configure_designate_backend {
69
+    # Generate Designate pool.yaml file
70
+    sudo tee $DESIGNATE_CONF_DIR/pools.yaml > /dev/null <<EOF
71
+---
72
+- name: default
73
+  description: DevStack PowerDNS Pool
74
+  attributes: {}
75
+
76
+  ns_records:
77
+    - hostname: $DESIGNATE_DEFAULT_NS_RECORD
78
+      priority: 1
79
+
80
+  nameservers:
81
+    - host: $DESIGNATE_SERVICE_HOST
82
+      port: $DESIGNATE_SERVICE_PORT_DNS
83
+
84
+  targets:
85
+    - type: pdns4
86
+      description: PowerDNS Database Cluster
87
+
88
+      masters:
89
+        - host: $DESIGNATE_SERVICE_HOST
90
+          port: $DESIGNATE_SERVICE_PORT_MDNS
91
+
92
+      options:
93
+        host: $DESIGNATE_SERVICE_HOST
94
+        port: $DESIGNATE_SERVICE_PORT_DNS
95
+        api_endpoint: http://$DESIGNATE_SERVICE_HOST:8081
96
+        api_token: changeme
97
+EOF
98
+
99
+    # Generate PowerDNS pdns.conf file
100
+    sudo tee $POWERDNS_CFG_DIR/pdns.conf > /dev/null <<EOF
101
+# General Config
102
+setgid=pdns
103
+setuid=pdns
104
+config-dir=$POWERDNS_CFG_DIR
105
+socket-dir=/var/run
106
+guardian=yes
107
+daemon=yes
108
+disable-axfr=no
109
+local-address=$DESIGNATE_SERVICE_HOST
110
+local-port=$DESIGNATE_SERVICE_PORT_DNS
111
+master=no
112
+slave=yes
113
+cache-ttl=0
114
+query-cache-ttl=0
115
+negquery-cache-ttl=0
116
+out-of-zone-additional-processing=no
117
+webserver=yes
118
+webserver-address=$DESIGNATE_SERVICE_HOST
119
+api=yes
120
+api-key=changeme
121
+EOF
122
+
123
+    if is_service_enabled mysql; then
124
+        sudo tee -a $POWERDNS_CFG_DIR/pdns.conf > /dev/null <<EOF
125
+# Launch gmysql backend
126
+launch=gmysql
127
+
128
+# gmysql parameters
129
+gmysql-host=$DATABASE_HOST
130
+gmysql-user=$DATABASE_USER
131
+gmysql-password=$DATABASE_PASSWORD
132
+gmysql-dbname=designate_pdns
133
+gmysql-dnssec=yes
134
+EOF
135
+    else
136
+        die $LINENO "PDNS4 backend only supports MySQL"
137
+    fi
138
+    restart_service pdns
139
+}
140
+
141
+# init_designate_backend - initialize databases, etc.
142
+function init_designate_backend {
143
+    # Stop pdns so that the migration succeeds, if not you get a error
144
+    # that the schema is still in use.
145
+    if is_service_enabled postgresql; then
146
+        stop_designate_backend
147
+    fi
148
+
149
+    # (Re)create designate_pdns database
150
+    recreate_database designate_pdns utf8
151
+    if is_service_enabled mysql; then
152
+            sudo mysql -u root designate_pdns < $DESIGNATE_PLUGINS/backend-pdns4-mysql-db.sql
153
+    else
154
+        die $LINENO "PDNS4 backend only supports MySQL"
155
+    fi
156
+}
157
+
158
+# create_designate_pool_configuration_backend - Perform post-pool config tasks
159
+function create_designate_pool_configuration_backend {
160
+    # Init and migrate designate_pdns database
161
+    :
162
+}
163
+
164
+# start_designate_backend - start any external services
165
+function start_designate_backend {
166
+    start_service pdns
167
+}
168
+
169
+
170
+# stop_designate_backend - stop any external services
171
+function stop_designate_backend {
172
+    stop_service pdns
173
+}
174
+
175
+# cleanup_designate_backend - remove transient data and cache
176
+function cleanup_designate_backend {
177
+    :
178
+}
179
+
180
+# Restore xtrace
181
+$DP_PDNS_XTRACE

+ 92
- 0
devstack/designate_plugins/backend-pdns4-mysql-db.sql View File

@@ -0,0 +1,92 @@
1
+CREATE TABLE domains (
2
+  id                    INT AUTO_INCREMENT,
3
+  name                  VARCHAR(255) NOT NULL,
4
+  master                VARCHAR(128) DEFAULT NULL,
5
+  last_check            INT DEFAULT NULL,
6
+  type                  VARCHAR(6) NOT NULL,
7
+  notified_serial       INT DEFAULT NULL,
8
+  account               VARCHAR(40) DEFAULT NULL,
9
+  PRIMARY KEY (id)
10
+) Engine=InnoDB;
11
+
12
+CREATE UNIQUE INDEX name_index ON domains(name);
13
+
14
+
15
+CREATE TABLE records (
16
+  id                    INT AUTO_INCREMENT,
17
+  domain_id             INT DEFAULT NULL,
18
+  name                  VARCHAR(255) DEFAULT NULL,
19
+  type                  VARCHAR(10) DEFAULT NULL,
20
+  -- Changed to "TEXT", as VARCHAR(65000) is too big for most MySQL installs
21
+  content               TEXT DEFAULT NULL,
22
+  ttl                   INT DEFAULT NULL,
23
+  prio                  INT DEFAULT NULL,
24
+  change_date           INT DEFAULT NULL,
25
+  disabled              TINYINT(1) DEFAULT 0,
26
+  ordername             VARCHAR(255) BINARY DEFAULT NULL,
27
+  auth                  TINYINT(1) DEFAULT 1,
28
+  PRIMARY KEY (id)
29
+) Engine=InnoDB;
30
+
31
+CREATE INDEX nametype_index ON records(name,type);
32
+CREATE INDEX domain_id ON records(domain_id);
33
+CREATE INDEX recordorder ON records (domain_id, ordername);
34
+
35
+
36
+CREATE TABLE supermasters (
37
+  ip                    VARCHAR(64) NOT NULL,
38
+  nameserver            VARCHAR(255) NOT NULL,
39
+  account               VARCHAR(40) NOT NULL,
40
+  PRIMARY KEY (ip, nameserver)
41
+) Engine=InnoDB;
42
+
43
+
44
+CREATE TABLE comments (
45
+  id                    INT AUTO_INCREMENT,
46
+  domain_id             INT NOT NULL,
47
+  name                  VARCHAR(255) NOT NULL,
48
+  type                  VARCHAR(10) NOT NULL,
49
+  modified_at           INT NOT NULL,
50
+  account               VARCHAR(40) NOT NULL,
51
+  -- Changed to "TEXT", as VARCHAR(65000) is too big for most MySQL installs
52
+  comment               TEXT NOT NULL,
53
+  PRIMARY KEY (id)
54
+) Engine=InnoDB;
55
+
56
+CREATE INDEX comments_domain_id_idx ON comments (domain_id);
57
+CREATE INDEX comments_name_type_idx ON comments (name, type);
58
+CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
59
+
60
+
61
+CREATE TABLE domainmetadata (
62
+  id                    INT AUTO_INCREMENT,
63
+  domain_id             INT NOT NULL,
64
+  kind                  VARCHAR(32),
65
+  content               TEXT,
66
+  PRIMARY KEY (id)
67
+) Engine=InnoDB;
68
+
69
+CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);
70
+
71
+
72
+CREATE TABLE cryptokeys (
73
+  id                    INT AUTO_INCREMENT,
74
+  domain_id             INT NOT NULL,
75
+  flags                 INT NOT NULL,
76
+  active                BOOL,
77
+  content               TEXT,
78
+  PRIMARY KEY(id)
79
+) Engine=InnoDB;
80
+
81
+CREATE INDEX domainidindex ON cryptokeys(domain_id);
82
+
83
+
84
+CREATE TABLE tsigkeys (
85
+  id                    INT AUTO_INCREMENT,
86
+  name                  VARCHAR(255),
87
+  algorithm             VARCHAR(50),
88
+  secret                VARCHAR(255),
89
+  PRIMARY KEY (id)
90
+) Engine=InnoDB;
91
+
92
+CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);

+ 57
- 0
doc/source/backends/pdns4.rst View File

@@ -0,0 +1,57 @@
1
+..
2
+    Copyright 2016 Hewlett Packard Enterprise Development, L.P.
3
+
4
+    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+    not use this file except in compliance with the License. You may obtain
6
+    a copy of the License at
7
+
8
+        http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+    Unless required by applicable law or agreed to in writing, software
11
+    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+    License for the specific language governing permissions and limitations
14
+    under the License.
15
+
16
+.. _backend-pdns4:
17
+
18
+PDNS4 Backend
19
+=============
20
+
21
+PDNS4 Configuration
22
+-------------------
23
+
24
+The version PowerDNS in Ubuntu Xenial is pdns4.
25
+This has a different DB schema, and is incompatible with the legacy PowerDNS
26
+driver. In PDNS 4 the API was marked stable, and this is what we will use.
27
+
28
+You will need to configure PowerDNS, and its database before perfoming these
29
+steps.
30
+
31
+You will need to use a database backend for PowerDNS's API to function.
32
+
33
+See `PowerDNS Docs`_ for details.
34
+
35
+1. Enable the API in the ``pdns.conf`` file.
36
+
37
+.. code-block:: ini
38
+
39
+    webserver=yes
40
+    api=yes
41
+    api-key=changeme
42
+
43
+2. Configure the PowerDNS Backend using this sample target snippet
44
+
45
+.. literalinclude:: sample_yaml_snippets/pdns4.yaml
46
+   :language: yaml
47
+
48
+3. Then update the pools in designate
49
+
50
+.. code-block:: console
51
+
52
+    $ designate-manage pool update
53
+
54
+See :ref:`designate_manage_pool` for further details on the ``designate-manage pool``
55
+command, and :ref:`pools` for information about the yaml file syntax
56
+
57
+.. _PowerDNS Docs: https://doc.powerdns.com/md/authoritative/installation/

+ 3
- 0
doc/source/backends/powerdns.rst View File

@@ -18,6 +18,9 @@
18 18
 PowerDNS Backend
19 19
 ================
20 20
 
21
+.. warning:: This backend will not work with PowerDNS version 4 or greater. Use the ``pdns4`` backend.
22
+
23
+
21 24
 
22 25
 PowerDNS Configuration
23 26
 ----------------------

+ 16
- 0
doc/source/backends/sample_yaml_snippets/pdns4.yaml View File

@@ -0,0 +1,16 @@
1
+  targets:
2
+    - type: pdns4
3
+      description: PowerDNS4 DNS Server
4
+
5
+      # List out the designate-mdns servers from which PowerDNS servers should
6
+      # request zone transfers (AXFRs) from.
7
+      masters:
8
+        - host: 192.0.2.1
9
+          port: 5354
10
+
11
+      # PowerDNS Configuration options
12
+      options:
13
+        host: 192.0.2.1
14
+        port: 53
15
+        api_endpoint: http://127.0.0.1:8081
16
+        api_token: changeme

+ 11
- 1
doc/source/support-matrix.ini View File

@@ -45,6 +45,7 @@ in-tree=True
45 45
 [backends]
46 46
 backend-impl-bind9=Bind9
47 47
 backend-impl-powerdns-mysql=Power DNS (MySQL)
48
+backend-impl-pdns4=Power DNS 4
48 49
 backend-impl-designate=Designate to Designate
49 50
 backend-impl-dynect=DynECT
50 51
 backend-impl-akamai=Akamai eDNS
@@ -61,7 +62,10 @@ backend-impl-msdns-agent=Microsoft DNS (Agent)
61 62
 
62 63
 [backends.backend-impl-bind9]
63 64
 
65
+[backends.backend-impl-pdns4]
66
+
64 67
 [backends.backend-impl-powerdns-mysql]
68
+notes=This has been replaced by the pdns4 backend for future releases
65 69
 
66 70
 [backends.backend-impl-designate]
67 71
 
@@ -101,7 +105,7 @@ type=agent
101 105
 type=agent
102 106
 
103 107
 [grades]
104
-valid-grades=integrated,master-compatible,release-compatible,untested,failing,known-broken,experimental
108
+valid-grades=integrated,master-compatible,release-compatible,untested,failing,known-broken,experimental,deprecated
105 109
 
106 110
 [grades.integrated]
107 111
 title=Integrated
@@ -144,3 +148,9 @@ title=Experimental
144 148
 notes=Backends that are under development, and may change at any time
145 149
 in-tree=optional
146 150
 css-class=warning
151
+
152
+[grades.deprecated]
153
+title=Deprecated
154
+notes=Backends have been superseded, and will be removed in the future
155
+in-tree=optional
156
+css-class=warning

+ 1
- 0
setup.cfg View File

@@ -86,6 +86,7 @@ designate.backend =
86 86
     bind9 = designate.backend.impl_bind9:Bind9Backend
87 87
     designate = designate.backend.impl_designate:DesignateBackend
88 88
     powerdns = designate.backend.impl_powerdns:PowerDNSBackend
89
+    pdns4 = designate.backend.impl_pdns4:PDNS4Backend
89 90
     dynect = designate.backend.impl_dynect:DynECTBackend
90 91
     akamai = designate.backend.impl_akamai:AkamaiBackend
91 92
     nsd4 = designate.backend.impl_nsd4:NSD4Backend

Loading…
Cancel
Save