Create resource_record type

Abstract out the nsupdate provider logic and implement a new resource_record
type around it which applies no semantic value to its title.

Also: support SPF and TXT records, include isrequired on required parameters
(though it doesn't seem to work as advertised)
This commit is contained in:
Nate Riffe
2014-09-10 13:02:31 -05:00
parent 9741dd509e
commit c0143b2ca7
5 changed files with 252 additions and 97 deletions
+5 -4
View File
@@ -10,14 +10,14 @@ Puppet::Type.newtype(:dns_rr) do
if (value =~ /^([A-Z]+)\/([A-Z]+)\/[a-zA-Z0-9._-]+$/)
rrclass = $1
if ( !%w(IN CH HS).include? rrclass )
raise ArgumentError, "Invalid resource record class: %s" % rrdata
Util::Errors.fail "Invalid resource record class: %s" % rrdata
end
type = $2
if ( !%w(A AAAA CNAME NS MX SRV NAPTR PTR).include? type)
raise ArgumentError, "Invalid resource record type: %s" % type
if ( !%w(A AAAA CNAME NS MX SPF SRV NAPTR PTR TXT).include? type)
Util::Errors.fail "Invalid resource record type: %s" % type
end
else
raise ArgumentError, "%s must be of the form Class/Type/Name" % value
Util::Errors.fail "%s must be of the form Class/Type/Name" % value
end
end
end
@@ -33,6 +33,7 @@ Puppet::Type.newtype(:dns_rr) do
newproperty(:rrdata, :array_matching => :all) do
desc 'The resource record\'s data'
isrequired
def insync?(is)
Array(is).sort == Array(@should).sort
+72
View File
@@ -0,0 +1,72 @@
Puppet::Type.newtype(:resource_record) do
@doc = 'A Resource Record in the Domain Name System'
ensurable
newparam(:title, :namevar => true) do
desc 'A unique name for the puppet resource'
end
newparam(:rrclass) do
desc 'The record class'
defaultto 'IN'
newvalues 'IN', 'CH', 'HS'
end
newparam(:type) do
desc 'The record type'
isrequired
newvalues 'A', 'AAAA', 'CNAME', 'NS', 'MX', 'SPF', 'SRV', 'NAPTR', 'PTR', 'TXT'
end
newparam(:record) do
desc 'The fully-qualified record name'
isrequired
validate do |value|
Util::Errors.fail "Invalid value for record: #{value}" unless value =~ /^([a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+$/
end
end
newparam(:zone) do
desc 'The zone to update'
end
newparam(:server) do
desc 'The master server for the resource record'
defaultto 'localhost'
end
newparam(:keyname) do
desc 'Keyname for the TSIG key used to update the record'
defaultto 'update'
end
newparam(:hmac) do
desc 'The HMAC type of the update key'
defaultto 'HMAC-SHA1'
end
newparam(:secret) do
desc 'The secret of the update key'
end
newproperty(:ttl) do
desc 'Time to live of the resource record'
defaultto 43200
munge do |value|
Integer(value)
end
end
newproperty(:data, :array_matching => :all) do
desc 'The resource record\'s data'
isrequired
def insync?(is)
Array(is).sort == Array(@should).sort
end
end
end