]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / is_mac_address.rb
1 #
2 # is_mac_address.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:is_mac_address, :type => :rvalue, :doc => <<-EOS
7 Returns true if the string passed to this function is a valid mac address.
8     EOS
9   ) do |arguments|
10
11     if (arguments.size != 1) then
12       raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+
13         "given #{arguments.size} for 1")
14     end
15
16     mac = arguments[0]
17
18     if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then
19       return true
20     else
21       return false
22     end
23
24   end
25 end
26
27 # vim: set ts=2 sw=2 et :