source: other-projects/hathitrust/vagrant-hadoop-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/is_ipv4_address.rb@ 30903

Last change on this file since 30903 was 30903, checked in by davidb, 7 years ago

Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details

File size: 797 bytes
Line 
1#
2# is_ipv4_address.rb
3#
4
5module Puppet::Parser::Functions
6 newfunction(:is_ipv4_address, :type => :rvalue, :doc => <<-EOS
7Returns true if the string passed to this function is a valid IPv4 address.
8 EOS
9 ) do |arguments|
10
11 require 'ipaddr'
12
13 function_deprecation([:is_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
14
15 if (arguments.size != 1) then
16 raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments "+
17 "given #{arguments.size} for 1")
18 end
19
20 begin
21 ip = IPAddr.new(arguments[0])
22 rescue ArgumentError
23 return false
24 end
25
26 return ip.ipv4?
27 end
28end
29
30# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.