Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / is_mac_address.rb
1 #
2 # is_mac_address.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:is_mac_address, :type => :rvalue, :doc => <<-DOC
6     @summary
7       **Deprecated:** Returns true if the string passed to this function is a valid mac 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     if arguments.size != 1
18       raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments given #{arguments.size} for 1")
19     end
20
21     mac = arguments[0]
22
23     return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){5}$}i =~ mac
24     return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){19}$}i =~ mac
25     return false
26   end
27 end
28
29 # vim: set ts=2 sw=2 et :