Remove the non-pools bind9 backend
Change-Id: Id04a0d6b76244d5f3b22b637e79bf05209287ad3
This commit is contained in:
parent
9b7a253460
commit
39c49c057e
@ -4,20 +4,13 @@ set -ex
|
||||
|
||||
pushd $BASE/new/devstack
|
||||
|
||||
DEVSTACK_GATE_DESIGNATE_DRIVER=${DEVSTACK_GATE_DESIGNATE_DRIVER:-powerdns}
|
||||
|
||||
export KEEP_LOCALRC=1
|
||||
export ENABLED_SERVICES=designate,designate-api,designate-central,designate-sink,designate-mdns,designate-pool-manager
|
||||
|
||||
echo "DESIGNATE_SERVICE_PORT_DNS=5322" >> $BASE/new/devstack/localrc
|
||||
|
||||
DEVSTACK_GATE_DESIGNATE_DRIVER=${DEVSTACK_GATE_DESIGNATE_DRIVER:-powerdns}
|
||||
|
||||
if [ "$DEVSTACK_GATE_DESIGNATE_DRIVER" == "powerdns" ]; then
|
||||
echo "DESIGNATE_BACKEND_DRIVER=powerdns" >> $BASE/new/devstack/localrc
|
||||
|
||||
elif [ "$DEVSTACK_GATE_DESIGNATE_DRIVER" == "bind9" ]; then
|
||||
echo "DESIGNATE_BACKEND_DRIVER=bind9_pool" >> $BASE/new/devstack/localrc
|
||||
|
||||
fi
|
||||
echo "DESIGNATE_BACKEND_DRIVER=$DEVSTACK_GATE_DESIGNATE_DRIVER" >> $BASE/new/devstack/localrc
|
||||
|
||||
popd
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# lib/designate_plugins/backend-bind9
|
||||
# Configure the bind9 backend
|
||||
# Configure the bind9 pool backend
|
||||
|
||||
# Enable with:
|
||||
# DESIGNATE_BACKEND_DRIVER=bind9
|
||||
@ -75,11 +75,18 @@ EOF
|
||||
|
||||
# configure_designate_backend - make configuration changes, including those to other services
|
||||
function configure_designate_backend {
|
||||
iniset $DESIGNATE_CONF service:pool_manager backends bind9
|
||||
iniset $DESIGNATE_CONF service:mdns slave_nameserver_ips_and_ports "$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT_DNS"
|
||||
|
||||
iniset $DESIGNATE_CONF backend:bind9 masters $DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT_MDNS
|
||||
iniset $DESIGNATE_CONF backend:bind9 server_ids $DESIGNATE_SERVER_ID
|
||||
iniset $DESIGNATE_CONF backend:bind9 rndc_port $DESIGNATE_SERVICE_PORT_RNDC
|
||||
iniset $DESIGNATE_CONF backend:bind9 rndc_host $DESIGNATE_SERVICE_HOST
|
||||
iniset $DESIGNATE_CONF backend:bind9 rndc_config_file "$BIND_CFG_DIR/rndc.conf"
|
||||
iniset $DESIGNATE_CONF backend:bind9 rndc_key_file "$BIND_CFG_DIR/rndc.key"
|
||||
iniset $DESIGNATE_CONF backend:bind9 nzf_path "$BIND_VAR_DIR"
|
||||
|
||||
iniset $DESIGNATE_CONF backend:bind9:$DESIGNATE_SERVER_ID host $DESIGNATE_SERVICE_HOST
|
||||
iniset $DESIGNATE_CONF backend:bind9:$DESIGNATE_SERVER_ID port $DESIGNATE_SERVICE_PORT_DNS
|
||||
|
||||
sudo chown $STACK_USER $BIND_CFG_DIR
|
||||
|
||||
@ -140,7 +147,7 @@ function stop_designate_backend {
|
||||
# cleanup_designate_backend - remove transient data and cache
|
||||
function cleanup_designate_backend {
|
||||
sudo sh -c "rm -rf $BIND_VAR_DIR/*.nzf"
|
||||
sudo sh -c "rm -rf $DESIGNATE_STATE_PATH/*.zone"
|
||||
sudo sh -c "rm -rf $BIND_VAR_DIR/slave.*"
|
||||
sudo rm -f $BIND_CFG_DIR/rndc.key
|
||||
}
|
||||
|
||||
|
@ -1,155 +0,0 @@
|
||||
# lib/designate_plugins/backend-bind9_pool
|
||||
# Configure the bind9 pool backend
|
||||
|
||||
# Enable with:
|
||||
# DESIGNATE_BACKEND_DRIVER=bind9_pool
|
||||
|
||||
# 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_BIND9_XTRACE=$(set +o | grep xtrace)
|
||||
set +o xtrace
|
||||
|
||||
# Defaults
|
||||
# --------
|
||||
BIND_SERVICE_NAME=bind9
|
||||
BIND_CFG_DIR=/etc/bind
|
||||
BIND_VAR_DIR=/var/cache/bind
|
||||
BIND_CFG_FILE=$BIND_CFG_DIR/named.conf.options
|
||||
BIND_USER=bind
|
||||
BIND_GROUP=bind
|
||||
DESIGNATE_SERVICE_PORT_RNDC=${DESIGNATE_SERVICE_PORT_RNDC:-953}
|
||||
|
||||
if is_fedora; then
|
||||
BIND_SERVICE_NAME=named
|
||||
BIND_CFG_DIR=/etc/named
|
||||
BIND_CFG_FILE=/etc/named.conf
|
||||
BIND_VAR_DIR=/var/named
|
||||
BIND_USER=named
|
||||
BIND_GROUP=named
|
||||
fi
|
||||
|
||||
# Entry Points
|
||||
# ------------
|
||||
|
||||
# install_designate_backend - install any external requirements
|
||||
function install_designate_backend {
|
||||
if is_ubuntu; then
|
||||
install_package bind9
|
||||
elif is_fedora; then
|
||||
install_package named
|
||||
fi
|
||||
|
||||
# The user that designate runs as needs to be member of **$BIND_GROUP** group.
|
||||
# The designate bind9 backend needs read/write access to $BIND_VAR_DIR
|
||||
if ! getent group $BIND_GROUP >/dev/null; then
|
||||
sudo groupadd $BIND_GROUP
|
||||
fi
|
||||
add_user_to_group $STACK_USER $BIND_GROUP
|
||||
if [[ ! -d $BIND_CFG_DIR ]]; then
|
||||
sudo mkdir -p $BIND_CFG_DIR
|
||||
sudo chown $BIND_USER:$BIND_GROUP $BIND_CFG_DIR
|
||||
fi
|
||||
|
||||
sudo chown -R $BIND_USER:$BIND_GROUP $BIND_CFG_DIR $BIND_VAR_DIR
|
||||
sudo chmod -R g+r $BIND_CFG_DIR
|
||||
sudo chmod -R g+rw $BIND_VAR_DIR
|
||||
|
||||
# Customize Bind9 apparmor profile if installed
|
||||
if [[ -d /etc/apparmor.d ]]; then
|
||||
sudo tee /etc/apparmor.d/local/usr.sbin.named > /dev/null << EOF
|
||||
$DESIGNATE_STATE_PATH/bind9/** rw,
|
||||
EOF
|
||||
restart_service apparmor
|
||||
fi
|
||||
}
|
||||
|
||||
# configure_designate_backend - make configuration changes, including those to other services
|
||||
function configure_designate_backend {
|
||||
iniset $DESIGNATE_CONF service:pool_manager backends bind9_pool
|
||||
iniset $DESIGNATE_CONF service:mdns slave_nameserver_ips_and_ports "$DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT_DNS"
|
||||
|
||||
iniset $DESIGNATE_CONF backend:bind9_pool masters $DESIGNATE_SERVICE_HOST:$DESIGNATE_SERVICE_PORT_MDNS
|
||||
iniset $DESIGNATE_CONF backend:bind9_pool server_ids $DESIGNATE_SERVER_ID
|
||||
iniset $DESIGNATE_CONF backend:bind9_pool rndc_port $DESIGNATE_SERVICE_PORT_RNDC
|
||||
iniset $DESIGNATE_CONF backend:bind9_pool rndc_host $DESIGNATE_SERVICE_HOST
|
||||
iniset $DESIGNATE_CONF backend:bind9_pool rndc_config_file "$BIND_CFG_DIR/rndc.conf"
|
||||
iniset $DESIGNATE_CONF backend:bind9_pool rndc_key_file "$BIND_CFG_DIR/rndc.key"
|
||||
|
||||
iniset $DESIGNATE_CONF backend:bind9_pool:$DESIGNATE_SERVER_ID host $DESIGNATE_SERVICE_HOST
|
||||
iniset $DESIGNATE_CONF backend:bind9_pool:$DESIGNATE_SERVER_ID port $DESIGNATE_SERVICE_PORT_DNS
|
||||
|
||||
sudo chown $STACK_USER $BIND_CFG_DIR
|
||||
|
||||
# create rndc key and config
|
||||
sudo rndc-confgen -a -c $BIND_CFG_DIR/rndc.key
|
||||
sudo chown $BIND_USER:$BIND_GROUP $BIND_CFG_DIR/rndc.key
|
||||
sudo chmod g+r $BIND_CFG_DIR/rndc.key
|
||||
|
||||
# Configure Bind
|
||||
sudo tee $BIND_CFG_FILE > /dev/null <<EOF
|
||||
include "$BIND_CFG_DIR/rndc.key";
|
||||
|
||||
options {
|
||||
directory "$BIND_VAR_DIR";
|
||||
allow-new-zones yes;
|
||||
dnssec-validation auto;
|
||||
auth-nxdomain no; # conform to RFC1035
|
||||
listen-on port $DESIGNATE_SERVICE_PORT_DNS { $DESIGNATE_SERVICE_HOST; };
|
||||
};
|
||||
|
||||
controls {
|
||||
inet $DESIGNATE_SERVICE_HOST port $DESIGNATE_SERVICE_PORT_RNDC allow { $DESIGNATE_SERVICE_HOST; } keys { "rndc-key"; };
|
||||
};
|
||||
EOF
|
||||
|
||||
# Configure RNDC
|
||||
sudo tee $BIND_CFG_DIR/rndc.conf > /dev/null << EOF
|
||||
include "$BIND_CFG_DIR/rndc.key";
|
||||
|
||||
options {
|
||||
default-key "rndc-key";
|
||||
default-server $DESIGNATE_SERVICE_HOST;
|
||||
default-port $DESIGNATE_SERVICE_PORT_RNDC;
|
||||
};
|
||||
EOF
|
||||
|
||||
sudo chown $BIND_USER:$BIND_GROUP $BIND_CFG_FILE $BIND_CFG_DIR/rndc.conf
|
||||
sudo chmod g+r $BIND_CFG_FILE $BIND_CFG_DIR/rndc.conf
|
||||
|
||||
restart_service $BIND_SERVICE_NAME
|
||||
}
|
||||
|
||||
# init_designate_backend - initialize databases, etc.
|
||||
function init_designate_backend {
|
||||
:
|
||||
}
|
||||
|
||||
# start_designate_backend - start any external services
|
||||
function start_designate_backend {
|
||||
start_service bind9
|
||||
}
|
||||
|
||||
# stop_designate_backend - stop any external services
|
||||
function stop_designate_backend {
|
||||
stop_service bind9
|
||||
}
|
||||
|
||||
# cleanup_designate_backend - remove transient data and cache
|
||||
function cleanup_designate_backend {
|
||||
sudo sh -c "rm -rf $BIND_VAR_DIR/*.nzf"
|
||||
sudo sh -c "rm -rf $BIND_VAR_DIR/slave.*"
|
||||
sudo rm -f $BIND_CFG_DIR/rndc.key
|
||||
}
|
||||
|
||||
# Restore xtrace
|
||||
$DP_BIND9_XTRACE
|
@ -1,6 +1,6 @@
|
||||
# Copyright 2012 Managed I.T.
|
||||
# Copyright 2014 eBay Inc.
|
||||
#
|
||||
# Author: Kiall Mac Innes <kiall@managedit.ie>
|
||||
# Author: Ron Rickard <rrickard@ebay.com>
|
||||
#
|
||||
# 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
|
||||
@ -13,214 +13,113 @@
|
||||
# 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 os
|
||||
import glob
|
||||
import shutil
|
||||
import time
|
||||
import socket
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo_concurrency import lockutils
|
||||
|
||||
from designate.openstack.common import log as logging
|
||||
from designate.i18n import _LW
|
||||
from designate import exceptions
|
||||
from designate import utils
|
||||
from designate.backend import base
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
CONF = cfg.CONF
|
||||
CFG_GROUP = 'backend:bind9_pool'
|
||||
DEFAULT_PORT = 5354
|
||||
|
||||
|
||||
class Bind9Backend(base.Backend):
|
||||
class Bind9Backend(base.PoolBackend):
|
||||
__plugin_name__ = 'bind9'
|
||||
|
||||
@classmethod
|
||||
def get_cfg_opts(cls):
|
||||
group = cfg.OptGroup(
|
||||
name='backend:bind9', title="Configuration for BIND9 Backend"
|
||||
)
|
||||
|
||||
opts = [
|
||||
def _get_common_cfg_opts(cls):
|
||||
return [
|
||||
cfg.StrOpt('rndc-host', default='127.0.0.1', help='RNDC Host'),
|
||||
cfg.IntOpt('rndc-port', default=953, help='RNDC Port'),
|
||||
cfg.StrOpt('rndc-config-file', default=None,
|
||||
help='RNDC Config File'),
|
||||
cfg.StrOpt('rndc-key-file', default=None, help='RNDC Key File'),
|
||||
cfg.StrOpt('nzf-path', default='/var/cache/bind',
|
||||
help='Path where Bind9 stores the nzf files'),
|
||||
]
|
||||
|
||||
return [(group, opts)]
|
||||
def __init__(self, backend_options):
|
||||
super(Bind9Backend, self).__init__(backend_options)
|
||||
self.masters = [self._parse_master(master)
|
||||
for master in self.get_backend_option('masters')]
|
||||
self.rndc_host = self.get_backend_option('rndc_host')
|
||||
self.rndc_port = self.get_backend_option('rndc_port')
|
||||
self.rndc_config_file = self.get_backend_option('rndc_config_file')
|
||||
self.rndc_key_file = self.get_backend_option('rndc_key_file')
|
||||
|
||||
def start(self):
|
||||
super(Bind9Backend, self).start()
|
||||
|
||||
domains = self.central_service.find_domains(self.admin_context)
|
||||
|
||||
for domain in domains:
|
||||
rndc_op = 'reload'
|
||||
rndc_call = self._rndc_base() + [rndc_op]
|
||||
rndc_call.extend([domain['name']])
|
||||
|
||||
try:
|
||||
LOG.debug('Calling RNDC with: %s' % " ".join(rndc_call))
|
||||
utils.execute(*rndc_call)
|
||||
except utils.processutils.ProcessExecutionError as proc_exec_err:
|
||||
stderr = proc_exec_err.stderr
|
||||
if stderr.count("rndc: 'reload' failed: not found") is not 0:
|
||||
LOG.warn(_LW("Domain %(d_name)s (%(d_id)s) "
|
||||
"missing from backend, recreating") %
|
||||
{'d_name': domain['name'], 'd_id': domain['id']})
|
||||
self._sync_domain(domain, new_domain_flag=True)
|
||||
else:
|
||||
raise proc_exec_err
|
||||
@staticmethod
|
||||
def _parse_master(master):
|
||||
try:
|
||||
(ip_address, port) = master.split(':', 1)
|
||||
except ValueError:
|
||||
ip_address = str(master)
|
||||
port = DEFAULT_PORT
|
||||
try:
|
||||
port = int(port)
|
||||
except ValueError:
|
||||
raise exceptions.ConfigurationError(
|
||||
'Invalid port "%s" in masters option.' % port)
|
||||
if port < 0 or port > 65535:
|
||||
raise exceptions.ConfigurationError(
|
||||
'Port "%s" is not between 0 and 65535 in masters option.' %
|
||||
port)
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET, ip_address)
|
||||
except socket.error:
|
||||
raise exceptions.ConfigurationError(
|
||||
'Invalid IP address "%s" in masters option.' % ip_address)
|
||||
return {'ip-address': ip_address, 'port': port}
|
||||
|
||||
def create_domain(self, context, domain):
|
||||
LOG.debug('Create Domain')
|
||||
self._sync_domain(domain, new_domain_flag=True)
|
||||
|
||||
def update_domain(self, context, domain):
|
||||
LOG.debug('Update Domain')
|
||||
self._sync_domain(domain)
|
||||
masters = []
|
||||
for master in self.masters:
|
||||
ip_address = master['ip-address']
|
||||
port = master['port']
|
||||
masters.append('%s port %s' % (ip_address, port))
|
||||
rndc_op = [
|
||||
'addzone',
|
||||
'%s { type slave; masters { %s;}; file "slave.%s%s"; };' %
|
||||
(domain['name'].rstrip('.'), '; '.join(masters), domain['name'],
|
||||
domain['id']),
|
||||
]
|
||||
self._execute_rndc(rndc_op)
|
||||
|
||||
def delete_domain(self, context, domain):
|
||||
LOG.debug('Delete Domain')
|
||||
self._sync_delete_domain(domain)
|
||||
|
||||
def create_recordset(self, context, domain, recordset):
|
||||
LOG.debug('Create RecordSet')
|
||||
self._sync_domain(domain)
|
||||
|
||||
def update_recordset(self, context, domain, recordset):
|
||||
LOG.debug('Update RecordSet')
|
||||
self._sync_domain(domain)
|
||||
|
||||
def delete_recordset(self, context, domain, recordset):
|
||||
LOG.debug('Delete RecordSet')
|
||||
self._sync_domain(domain)
|
||||
|
||||
def create_record(self, context, domain, recordset, record):
|
||||
LOG.debug('Create Record')
|
||||
self._sync_domain(domain)
|
||||
|
||||
def update_record(self, context, domain, recordset, record):
|
||||
LOG.debug('Update Record')
|
||||
self._sync_domain(domain)
|
||||
|
||||
def delete_record(self, context, domain, recordset, record):
|
||||
LOG.debug('Delete Record')
|
||||
self._sync_domain(domain)
|
||||
rndc_op = [
|
||||
'delzone',
|
||||
'%s' % domain['name'].rstrip('.'),
|
||||
]
|
||||
self._execute_rndc(rndc_op)
|
||||
|
||||
def _rndc_base(self):
|
||||
rndc_call = [
|
||||
'rndc',
|
||||
'-s', cfg.CONF[self.name].rndc_host,
|
||||
'-p', str(cfg.CONF[self.name].rndc_port),
|
||||
'-s', self.rndc_host,
|
||||
'-p', str(self.rndc_port),
|
||||
]
|
||||
|
||||
if cfg.CONF[self.name].rndc_config_file:
|
||||
rndc_call.extend(['-c', cfg.CONF[self.name].rndc_config_file])
|
||||
if self.rndc_config_file:
|
||||
rndc_call.extend(
|
||||
['-c', self.rndc_config_file])
|
||||
|
||||
if cfg.CONF[self.name].rndc_key_file:
|
||||
rndc_call.extend(['-k', cfg.CONF[self.name].rndc_key_file])
|
||||
if self.rndc_key_file:
|
||||
rndc_call.extend(
|
||||
['-k', self.rndc_key_file])
|
||||
|
||||
return rndc_call
|
||||
|
||||
def _sync_delete_domain(self, domain, new_domain_flag=False):
|
||||
"""Remove domain zone files and reload bind config"""
|
||||
LOG.debug('Delete Domain: %s' % domain['id'])
|
||||
|
||||
output_folder = os.path.join(os.path.abspath(cfg.CONF.state_path),
|
||||
'bind9')
|
||||
|
||||
output_path = os.path.join(output_folder, '%s.zone' %
|
||||
"_".join([domain['name'], domain['id']]))
|
||||
|
||||
os.remove(output_path)
|
||||
|
||||
rndc_op = 'delzone'
|
||||
|
||||
rndc_call = self._rndc_base() + [rndc_op, domain['name']]
|
||||
|
||||
utils.execute(*rndc_call)
|
||||
|
||||
# This goes and gets the name of the .nzf file that is a mirror of the
|
||||
# zones.config file we wish to maintain. The file name can change as it
|
||||
# is a hash of rndc view name, we're only interested in the first file
|
||||
# name this returns because there is only one .nzf file
|
||||
nzf_name = glob.glob('%s/*.nzf' % cfg.CONF[self.name].nzf_path)
|
||||
|
||||
output_file = os.path.join(output_folder, 'zones.config')
|
||||
|
||||
shutil.copyfile(nzf_name[0], output_file)
|
||||
|
||||
def _sync_domain(self, domain, new_domain_flag=False):
|
||||
"""Sync a single domain's zone file and reload bind config"""
|
||||
|
||||
# NOTE: Only one thread should be working with the Zonefile at a given
|
||||
# time. The sleep(1) below introduces a not insignificant risk
|
||||
# of more than 1 thread working with a zonefile at a given time.
|
||||
with lockutils.lock('bind9-%s' % domain['id']):
|
||||
LOG.debug('Synchronising Domain: %s' % domain['id'])
|
||||
|
||||
recordsets = self.central_service.find_recordsets(
|
||||
self.admin_context, {'domain_id': domain['id']})
|
||||
|
||||
records = []
|
||||
|
||||
for recordset in recordsets:
|
||||
criterion = {
|
||||
'domain_id': domain['id'],
|
||||
'recordset_id': recordset['id']
|
||||
}
|
||||
|
||||
raw_records = self.central_service.find_records(
|
||||
self.admin_context, criterion)
|
||||
|
||||
for record in raw_records:
|
||||
records.append({
|
||||
'name': recordset['name'],
|
||||
'type': recordset['type'],
|
||||
'ttl': recordset['ttl'],
|
||||
'data': record['data'],
|
||||
})
|
||||
|
||||
output_folder = os.path.join(os.path.abspath(cfg.CONF.state_path),
|
||||
'bind9')
|
||||
|
||||
output_name = "_".join([domain['name'], domain['id']])
|
||||
output_path = os.path.join(output_folder, '%s.zone' % output_name)
|
||||
|
||||
utils.render_template_to_file('bind9-zone.jinja2',
|
||||
output_path,
|
||||
domain=domain,
|
||||
records=records)
|
||||
|
||||
def _execute_rndc(self, rndc_op):
|
||||
try:
|
||||
rndc_call = self._rndc_base()
|
||||
|
||||
if new_domain_flag:
|
||||
rndc_op = [
|
||||
'addzone',
|
||||
'%s { type master; file "%s"; };' % (domain['name'],
|
||||
output_path),
|
||||
]
|
||||
rndc_call.extend(rndc_op)
|
||||
else:
|
||||
rndc_op = 'reload'
|
||||
rndc_call.extend([rndc_op])
|
||||
rndc_call.extend([domain['name']])
|
||||
|
||||
if not new_domain_flag:
|
||||
# NOTE: Bind9 will only ever attempt to re-read a zonefile if
|
||||
# the file's timestamp has changed since the previous
|
||||
# reload. A one second sleep ensures we cross over a
|
||||
# second boundary before allowing the next change.
|
||||
time.sleep(1)
|
||||
|
||||
LOG.debug('Calling RNDC with: %s' % " ".join(rndc_call))
|
||||
rndc_call.extend(rndc_op)
|
||||
LOG.debug('Executing RNDC call: %s' % " ".join(rndc_call))
|
||||
utils.execute(*rndc_call)
|
||||
|
||||
nzf_name = glob.glob('%s/*.nzf' % cfg.CONF[self.name].nzf_path)
|
||||
|
||||
output_file = os.path.join(output_folder, 'zones.config')
|
||||
|
||||
shutil.copyfile(nzf_name[0], output_file)
|
||||
except utils.processutils.ProcessExecutionError as e:
|
||||
LOG.debug('RNDC call failure: %s' % e)
|
||||
raise exceptions.Backend(e)
|
||||
|
@ -1,123 +0,0 @@
|
||||
# Copyright 2014 eBay Inc.
|
||||
#
|
||||
# Author: Ron Rickard <rrickard@ebay.com>
|
||||
#
|
||||
# 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 socket
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from designate.openstack.common import log as logging
|
||||
from designate import exceptions
|
||||
from designate import utils
|
||||
from designate.backend import base
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
DEFAULT_PORT = 5354
|
||||
|
||||
|
||||
class Bind9PoolBackend(base.PoolBackend):
|
||||
__plugin_name__ = 'bind9_pool'
|
||||
|
||||
@classmethod
|
||||
def _get_common_cfg_opts(cls):
|
||||
return [
|
||||
cfg.StrOpt('rndc-host', default='127.0.0.1', help='RNDC Host'),
|
||||
cfg.IntOpt('rndc-port', default=953, help='RNDC Port'),
|
||||
cfg.StrOpt('rndc-config-file', default=None,
|
||||
help='RNDC Config File'),
|
||||
cfg.StrOpt('rndc-key-file', default=None, help='RNDC Key File'),
|
||||
]
|
||||
|
||||
def __init__(self, backend_options):
|
||||
super(Bind9PoolBackend, self).__init__(backend_options)
|
||||
self.masters = [self._parse_master(master)
|
||||
for master in self.get_backend_option('masters')]
|
||||
self.rndc_host = self.get_backend_option('rndc_host')
|
||||
self.rndc_port = self.get_backend_option('rndc_port')
|
||||
self.rndc_config_file = self.get_backend_option('rndc_config_file')
|
||||
self.rndc_key_file = self.get_backend_option('rndc_key_file')
|
||||
|
||||
@staticmethod
|
||||
def _parse_master(master):
|
||||
try:
|
||||
(ip_address, port) = master.split(':', 1)
|
||||
except ValueError:
|
||||
ip_address = str(master)
|
||||
port = DEFAULT_PORT
|
||||
try:
|
||||
port = int(port)
|
||||
except ValueError:
|
||||
raise exceptions.ConfigurationError(
|
||||
'Invalid port "%s" in masters option.' % port)
|
||||
if port < 0 or port > 65535:
|
||||
raise exceptions.ConfigurationError(
|
||||
'Port "%s" is not between 0 and 65535 in masters option.' %
|
||||
port)
|
||||
try:
|
||||
socket.inet_pton(socket.AF_INET, ip_address)
|
||||
except socket.error:
|
||||
raise exceptions.ConfigurationError(
|
||||
'Invalid IP address "%s" in masters option.' % ip_address)
|
||||
return {'ip-address': ip_address, 'port': port}
|
||||
|
||||
def create_domain(self, context, domain):
|
||||
LOG.debug('Create Domain')
|
||||
masters = []
|
||||
for master in self.masters:
|
||||
ip_address = master['ip-address']
|
||||
port = master['port']
|
||||
masters.append('%s port %s' % (ip_address, port))
|
||||
rndc_op = [
|
||||
'addzone',
|
||||
'%s { type slave; masters { %s;}; file "slave.%s%s"; };' %
|
||||
(domain['name'].rstrip('.'), '; '.join(masters), domain['name'],
|
||||
domain['id']),
|
||||
]
|
||||
self._execute_rndc(rndc_op)
|
||||
|
||||
def delete_domain(self, context, domain):
|
||||
LOG.debug('Delete Domain')
|
||||
rndc_op = [
|
||||
'delzone',
|
||||
'%s' % domain['name'].rstrip('.'),
|
||||
]
|
||||
self._execute_rndc(rndc_op)
|
||||
|
||||
def _rndc_base(self):
|
||||
rndc_call = [
|
||||
'rndc',
|
||||
'-s', self.rndc_host,
|
||||
'-p', str(self.rndc_port),
|
||||
]
|
||||
|
||||
if self.rndc_config_file:
|
||||
rndc_call.extend(
|
||||
['-c', self.rndc_config_file])
|
||||
|
||||
if self.rndc_key_file:
|
||||
rndc_call.extend(
|
||||
['-k', self.rndc_key_file])
|
||||
|
||||
return rndc_call
|
||||
|
||||
def _execute_rndc(self, rndc_op):
|
||||
try:
|
||||
rndc_call = self._rndc_base()
|
||||
rndc_call.extend(rndc_op)
|
||||
LOG.debug('Executing RNDC call: %s' % " ".join(rndc_call))
|
||||
utils.execute(*rndc_call)
|
||||
except utils.processutils.ProcessExecutionError as e:
|
||||
LOG.debug('RNDC call failure: %s' % e)
|
||||
raise exceptions.Backend(e)
|
@ -1,3 +0,0 @@
|
||||
{% for domain in domains %}
|
||||
zone "{{domain.name}}" { type master; file "{{state_path}}/bind9/{{domain.id}}.zone"; };
|
||||
{%- endfor %}
|
@ -22,7 +22,6 @@ from designate.tests.test_backend import BackendTestMixin
|
||||
|
||||
class BackendTestCase(tests.TestCase, BackendTestMixin):
|
||||
scenarios = [
|
||||
('bind9', dict(backend_driver='bind9', group='service:agent')),
|
||||
('fake', dict(backend_driver='fake', group='service:agent')),
|
||||
('nsd4slave', dict(backend_driver='nsd4slave', group='service:agent',
|
||||
server_fixture=NSD4Fixture)),
|
||||
|
@ -26,7 +26,7 @@ from designate import utils
|
||||
|
||||
class TestUtils(TestCase):
|
||||
def test_resource_string(self):
|
||||
name = ['templates', 'bind9-config.jinja2']
|
||||
name = ['templates', 'bind9-zone.jinja2']
|
||||
|
||||
resource_string = utils.resource_string(*name)
|
||||
|
||||
@ -48,14 +48,14 @@ class TestUtils(TestCase):
|
||||
utils.load_schema('v1', 'missing')
|
||||
|
||||
def test_load_template(self):
|
||||
name = 'bind9-config.jinja2'
|
||||
name = 'bind9-zone.jinja2'
|
||||
|
||||
template = utils.load_template(name)
|
||||
|
||||
self.assertIsInstance(template, Template)
|
||||
|
||||
def test_load_template_keep_trailing_newline(self):
|
||||
name = 'bind9-config.jinja2'
|
||||
name = 'bind9-zone.jinja2'
|
||||
template = utils.load_template(name)
|
||||
self.assertTrue(template.environment.keep_trailing_newline)
|
||||
|
||||
|
@ -109,7 +109,7 @@ debug = False
|
||||
#-----------------------
|
||||
[service:agent]
|
||||
# Driver used for backend communication (e.g. bind9, powerdns)
|
||||
#backend_driver = bind9
|
||||
#backend_driver = powerdns
|
||||
|
||||
#-----------------------
|
||||
# Sink Service
|
||||
@ -132,7 +132,7 @@ debug = False
|
||||
# Pool Manager Service
|
||||
#-----------------------
|
||||
[service:pool_manager]
|
||||
#backends = bind9_pool
|
||||
#backends = bind9
|
||||
#workers = None
|
||||
#pool_name = default
|
||||
#threshold-percentage = 100
|
||||
@ -213,27 +213,6 @@ debug = False
|
||||
########################
|
||||
## Backend Configuration
|
||||
########################
|
||||
#-----------------------
|
||||
# Bind9 Backend
|
||||
#-----------------------
|
||||
[backend:bind9]
|
||||
#rndc_host = 127.0.0.1
|
||||
#rndc_port = 953
|
||||
#rndc_config_file = /etc/rndc.conf
|
||||
#rndc_key_file = /etc/rndc.key
|
||||
|
||||
#-----------------------
|
||||
# Bind9+MySQL Backend
|
||||
#-----------------------
|
||||
[backend:mysqlbind9]
|
||||
#connection = mysql://user:password@host/schema
|
||||
#rndc_host = 127.0.0.1
|
||||
#rndc_port = 953
|
||||
#rndc_config_file = /etc/rndc.conf
|
||||
#rndc_key_file = /etc/rndc.key
|
||||
#write_database = True
|
||||
#dns_server_type = master
|
||||
|
||||
#-----------------------
|
||||
# PowerDNS Backend
|
||||
#-----------------------
|
||||
@ -268,7 +247,7 @@ debug = False
|
||||
#-----------------------
|
||||
# Global Bind9 Pool Backend
|
||||
#-----------------------
|
||||
[backend:bind9_pool]
|
||||
[backend:bind9]
|
||||
#server_ids = 6a5032b6-2d96-43ee-b25b-7d784e2bf3b2
|
||||
#masters = 127.0.0.1:5354
|
||||
#rndc_host = 127.0.0.1
|
||||
@ -279,6 +258,6 @@ debug = False
|
||||
#-----------------------
|
||||
# Server Specific Bind9 Pool Backend
|
||||
#-----------------------
|
||||
[backend:bind9_pool:6a5032b6-2d96-43ee-b25b-7d784e2bf3b2]
|
||||
[backend:bind9:6a5032b6-2d96-43ee-b25b-7d784e2bf3b2]
|
||||
# host = 127.0.0.1
|
||||
# port = 53
|
||||
|
@ -69,7 +69,6 @@ designate.notification.handler =
|
||||
|
||||
designate.backend =
|
||||
bind9 = designate.backend.impl_bind9:Bind9Backend
|
||||
bind9_pool = designate.backend.impl_bind9_pool:Bind9PoolBackend
|
||||
powerdns = designate.backend.impl_powerdns:PowerDNSBackend
|
||||
rpc = designate.backend.impl_rpc:RPCBackend
|
||||
fake = designate.backend.impl_fake:FakeBackend
|
||||
|
Loading…
Reference in New Issue
Block a user