puppet-tripleo/lib/puppet/functions/is_ip_addresses.rb
Alex Schultz 8d889af7d4 Update functions to fix unit tests
With the release of 5.5.7, some of the legacy function definitions no
longer pass in unit tests. This change updates the functions that are
failing in the tests to the modern style (4.x) for function
declarations.  Additionally we're removing teh lookup_hiera_hash
function which is failing but not actually consumed by our code base.

There will be a followup patch to migrate the rest of the parser
functions to the new format, but this patch should unblock the gates.

NOTE: git thinks some of these files have been added/deleted rather than
git move due to the large amount of changes between the two versions of
the file.

Change-Id: Ie7316fd422bd4a5eb91f94016977e5d8d76c27bc
Closes-Bug: #1799786
2018-10-29 12:16:38 +01:00

30 lines
682 B
Ruby

require 'ipaddr'
# Custom function to verify if the parameter is a string representing an ip address
# or an array of strings representing an ip address
# Returns true if all elements are proper ip addresses and false otherwise
Puppet::Functions.create_function(:is_ip_addresses) do
dispatch :is_ip_addresses do
param 'Variant[Array, String, Undef]', :ip_addr
end
def is_ip_addresses(ip_addr)
if not ip_addr
return false
end
if ip_addr.class == String
ips = [ip_addr]
else
ips = ip_addr
end
ips.each do |ip|
begin
tmpip = IPAddr.new ip
rescue
return false
end
end
return true
end
end