diff --git a/designate/backend/impl_pdns4.py b/designate/backend/impl_pdns4.py new file mode 100644 index 000000000..a983d5b4f --- /dev/null +++ b/designate/backend/impl_pdns4.py @@ -0,0 +1,82 @@ +# Copyright 2016 Hewlett Packard Enterprise Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +import urlparse + +import requests +from oslo_log import log as logging +from oslo_config import cfg + +from designate import exceptions +from designate.backend import base + + +LOG = logging.getLogger(__name__) +CONF = cfg.CONF + + +class PDNS4Backend(base.Backend): + __plugin_name__ = 'pdns4' + + __backend_status__ = 'release-compatible' + + def __init__(self, target): + super(PDNS4Backend, self).__init__(target) + + self.api_endpoint = self.options.get('api_endpoint') + self.api_token = self.options.get('api_token') + + def _build_url(self, zone=''): + r_url = urlparse.urlparse(self.api_endpoint) + return "%s://%s/api/v1/servers/localhost/zones%s%s" % ( + r_url.scheme, r_url.netloc, '/' if zone else '', zone) + + def create_zone(self, context, zone): + """Create a DNS zone""" + + masters = \ + ['%s:%d' % (master.host, master.port) for master in self.masters] + + data = { + "name": zone.name, + "kind": "slave", + "masters": masters, + + } + headers = { + "X-API-Key": self.api_token + } + + try: + requests.post( + self._build_url(), + json=data, + headers=headers + ).raise_for_status() + except requests.HTTPError as e: + raise exceptions.Backend(e) + + def delete_zone(self, context, zone): + """Delete a DNS zone""" + + headers = { + "X-API-Key": self.api_token + } + + try: + requests.delete( + self._build_url(zone.name), + headers=headers + ).raise_for_status() + except requests.HTTPError as e: + raise exceptions.Backend(e) diff --git a/designate/backend/impl_powerdns/__init__.py b/designate/backend/impl_powerdns/__init__.py index 41ca3f650..908cf224a 100644 --- a/designate/backend/impl_powerdns/__init__.py +++ b/designate/backend/impl_powerdns/__init__.py @@ -40,7 +40,7 @@ def _map_col(keys, col): class PowerDNSBackend(base.Backend): __plugin_name__ = 'powerdns' - __backend_status__ = 'integrated' + __backend_status__ = 'deprecated' @classmethod def get_cfg_opts(cls): diff --git a/devstack/designate_plugins/backend-pdns4 b/devstack/designate_plugins/backend-pdns4 new file mode 100644 index 000000000..37247b8b6 --- /dev/null +++ b/devstack/designate_plugins/backend-pdns4 @@ -0,0 +1,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 + GetOSVersion + if [ "$os_CODENAME" = "trusty" ]; then + sudo tee /etc/apt/sources.list.d/pdns.list > /dev/null < /dev/null < /dev/null < /dev/null < /dev/null <