Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / is_ip_address.rb
1 #
2 # is_ip_address.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:is_ip_address, :type => :rvalue, :doc => <<-DOC
6     @summary
7       **Deprecated:** Returns true if the string passed to this function is a valid IP address.
8
9     @return [Boolean]
10       Returns `true` or `false`
11
12     > **Note:* **Deprecated** Will be removed in a future version of stdlib. See
13     [`validate_legacy`](#validate_legacy).
14     DOC
15              ) do |arguments|
16
17     require 'ipaddr'
18
19     function_deprecation([:is_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function,
20                            with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
21
22     if arguments.size != 1
23       raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments given #{arguments.size} for 1")
24     end
25
26     begin
27       ip = IPAddr.new(arguments[0])
28     rescue ArgumentError
29       return false
30     end
31
32     return true if ip.ipv4? || ip.ipv6?
33     return false
34   end
35 end
36
37 # vim: set ts=2 sw=2 et :