diff options
Diffstat (limited to '')
-rw-r--r-- | lib/puppet/functions/dns/rev_record.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/puppet/functions/dns/rev_record.rb b/lib/puppet/functions/dns/rev_record.rb new file mode 100644 index 0000000..efbedc6 --- /dev/null +++ b/lib/puppet/functions/dns/rev_record.rb @@ -0,0 +1,18 @@ +require 'ipaddr' + +Puppet::Functions.create_function(:'dns::rev_record') do + dispatch :rev_record do + param 'Stdlib::IP::Address::V6::Nosubnet', :ip + param 'Stdlib::IP::Address::V6::Nosubnet', :netmask + return_type 'Tuple[String,2]' + end + + def rev_record(ip, netmask) + cidr = IPAddr.new("::/#{netmask}").prefix + addr = IPAddr.new ip + parts = addr.ip6_arpa.split('.') + + [ parts.take(cidr/4).join('.'), + parts.drop(cidr/4).join('.') ] + end +end |