Last change
on this file since 30960 was 30960, checked in by davidb, 8 years ago |
Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster
|
File size:
860 bytes
|
Rev | Line | |
---|
[30960] | 1 | #
|
---|
| 2 | # is_ip_address.rb
|
---|
| 3 | #
|
---|
| 4 |
|
---|
| 5 | module Puppet::Parser::Functions
|
---|
| 6 | newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS
|
---|
| 7 | Returns true if the string passed to this function is a valid IP address.
|
---|
| 8 | EOS
|
---|
| 9 | ) do |arguments|
|
---|
| 10 |
|
---|
| 11 | require 'ipaddr'
|
---|
| 12 |
|
---|
| 13 | function_deprecation([:is_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
|
---|
| 14 |
|
---|
| 15 | if (arguments.size != 1) then
|
---|
| 16 | raise(Puppet::ParseError, "is_ip_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 | if ip.ipv4? or ip.ipv6? then
|
---|
| 27 | return true
|
---|
| 28 | else
|
---|
| 29 | return false
|
---|
| 30 | end
|
---|
| 31 | end
|
---|
| 32 | end
|
---|
| 33 |
|
---|
| 34 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.