Skip to content

Commit

Permalink
Add support for PowerDNS 4 backend
Browse files Browse the repository at this point in the history
Change-Id: Ie9cc92622e1bf281fc07c97f480f5a3c16b7e6f3
  • Loading branch information
kajinamit committed Mar 2, 2022
1 parent 717cd76 commit 4d0a105
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
74 changes: 74 additions & 0 deletions manifests/backend/pdns4.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# == Class designate::backend::pdns4
#
# Configure PowerDNS 4 as backend
#
# == Parameters
#
# [*api_token*]
# (Required) Token string to authenticate with the PowerDNS Authoritative
# Server.
#
# [*pdns4_hosts*]
# (Optional) Host running DNS service.
# Defaults to ['127.0.0,1'].
#
# [*pdns4_port*]
# (Optional) TCP port to connect to DNS service.
# Defaults to 53.
#
# [*mdns_hosts*]
# (Optional) Array of hosts where designate-mdns service is running.
# Defaults to ['127.0.0.1'].
#
# [*mdns_port*]
# (Optional) TCP Port to connect to designate-mdns service.
# Defaults to 5354.
#
# [*api_endpoint*]
# (Optional) URL to access the PowerDNS Authoritative Server.
# Defaults to 'http://127.0.0.1:8081'.
#
# [*tsigkey_name*]
# (Optional) Name of TSIGKey.
# Defaults to undef.
#
# [*manage_pool*]
# (Optional) Manage pools.yaml and update pools by designate-manage command
# Defaults to true
#
class designate::backend::pdns4 (
$api_token,
$pdns4_hosts = ['127.0.0.1'],
$pdns4_port = 53,
$mdns_hosts = ['127.0.0.1'],
$mdns_port = 5354,
$api_endpoint = 'http://127.0.0.1:8081',
$tsigkey_name = undef,
$manage_pool = true,
) {

include designate::deps
include designate::params

if $manage_pool {
file { '/etc/designate/pools.yaml':
ensure => present,
path => '/etc/designate/pools.yaml',
owner => $designate::params::user,
group => $designate::params::group,
mode => '0640',
content => template('designate/pdns4-pools.yaml.erb'),
require => Anchor['designate::config::begin'],
before => Anchor['designate::config::end'],
}

exec { 'designate-manage pool update':
command => 'designate-manage pool update',
path => '/usr/bin',
user => $designate::params::user,
refreshonly => true,
require => Anchor['designate::service::end'],
subscribe => File['/etc/designate/pools.yaml'],
}
}
}
5 changes: 5 additions & 0 deletions releasenotes/notes/pdns4-07768cbace039aee.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
The new ``designate::backend::pdns4`` class has been added. This class
supports setting up PowerDNS 4 backend.
58 changes: 58 additions & 0 deletions spec/classes/designate_backend_pdns4_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Unit tests for designate::backend::pdns4
#
require 'spec_helper'

describe 'designate::backend::pdns4' do

shared_examples 'designate-backend-pdns4' do

let :params do
{ :api_token => 'mytoken' }
end

context 'with default params' do
it 'configures named and pool' do
is_expected.to contain_file('/etc/designate/pools.yaml').with(
:ensure => 'present',
:path => '/etc/designate/pools.yaml',
:owner => 'designate',
:group => 'designate',
:mode => '0640',
)
is_expected.to contain_exec('designate-manage pool update').with(
:command => 'designate-manage pool update',
:path => '/usr/bin',
:user => 'designate',
:refreshonly => true,
)
end
end

context 'with pool management disabled' do
before do
params.merge!({
:manage_pool => false
})
end
it 'does not configure pool' do
is_expected.to_not contain_file('/etc/designate/pools.yaml')
is_expected.to_not contain_exec('designate-manage pool update')
end
end

end

on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end

it_behaves_like 'designate-backend-pdns4'
end
end

end
25 changes: 25 additions & 0 deletions templates/pdns4-pools.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: default
description: Default pool
attributes: {}

targets:
<% @pdns4_hosts.each do |pdns4_host| -%>
- type: pdns4
description: PowerDNS4 DNS Server <%= pdns4_host %>

masters:
<% @mdns_hosts.each do |mdns_host| -%>
- host: <%= mdns_host %>
port: <%= @mdns_port.to_s %>
<% end -%>

options:
host: <%= pdns4_host %>
port: <%= @dns_port.to_s %>
api_endpoint: <%= @api_endpoint %>
api_token: <%= @api_token %>
<%- if @tsigkey_name -%>
tsigkey_name: <%= @tsigkey_name %>
<%- end -%>
<% end -%>

0 comments on commit 4d0a105

Please sign in to comment.