From 635ed82e5cae38b0ba82098c340cbeed70d483c3 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 18:10:16 +0100 Subject: (#2) - unstubbed is_valid_ip_address --- lib/puppet/parser/functions/is_valid_ip_address.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/puppet/parser/functions') diff --git a/lib/puppet/parser/functions/is_valid_ip_address.rb b/lib/puppet/parser/functions/is_valid_ip_address.rb index e91dda8..4f45890 100644 --- a/lib/puppet/parser/functions/is_valid_ip_address.rb +++ b/lib/puppet/parser/functions/is_valid_ip_address.rb @@ -7,11 +7,24 @@ module Puppet::Parser::Functions EOS ) do |arguments| + require 'ipaddr' + if (arguments.size != 1) then raise(Puppet::ParseError, "is_valid_ip_address(): Wrong number of arguments "+ "given #{arguments.size} for 1") end + begin + ip = IPAddr.new(arguments[0]) + rescue ArgumentError + return false + end + + if ip.ipv4? or ip.ipv6? then + return true + else + return false + end end end -- cgit v1.2.3