1 module Puppet::Parser::Functions
3 newfunction(:validate_ipv6_address, :doc => <<-ENDHEREDOC
4 Validate that all values passed are valid IPv6 addresses.
5 Fail compilation if any value fails this check.
7 The following values will pass:
10 validate_ipv6_address(1)
11 validate_ipv6_address($my_ip)
12 validate_bool("fe80::baf6:b1ff:fe19:7507", $my_ip)
14 The following values will fail, causing compilation to abort:
16 $some_array = [ true, false, "garbage string", "1.2.3.4" ]
17 validate_ipv6_address($some_array)
23 rescuable_exceptions = [ ArgumentError ]
25 if defined?(IPAddr::InvalidAddressError)
26 rescuable_exceptions << IPAddr::InvalidAddressError
29 unless args.length > 0 then
30 raise Puppet::ParseError, ("validate_ipv6_address(): wrong number of arguments (#{args.length}; must be > 0)")
34 unless arg.is_a?(String)
35 raise Puppet::ParseError, "#{arg.inspect} is not a string."
39 unless IPAddr.new(arg).ipv6?
40 raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv6 address."
42 rescue *rescuable_exceptions
43 raise Puppet::ParseError, "#{arg.inspect} is not a valid IPv6 address."