-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This function calculate the reverse for an IPv4 or IPv6 address Fixes: #228
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'ipaddr' | ||
|
||
# @summary Returns the reverse of an IP address | ||
# | ||
# Not actual query is done to the DNS server, it only calculate the record | ||
# that could be added to a DNS zone file. | ||
Puppet::Functions.create_function(:'extlib::ip_to_reverse') do | ||
# @param ip | ||
# IPv4 or IPv6 address | ||
# | ||
# @example Calling the function | ||
# extlib::ip_to_reverse('192.0.2.0') | ||
dispatch :ip_to_reverse? do | ||
param 'Stdlib::IP::Address::Nosubnet', :ip | ||
return_type 'String' | ||
end | ||
|
||
def ip_to_reverse?(ip) | ||
IPAddr(ip).reverse | ||
end | ||
end |