Update stdlib
[mirror/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 given #{arguments.size} for 1")
13     end
14
15     mac = arguments[0]
16
17     if /^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){5}$/i.match(mac) then
18       return true
19     else
20       return false
21     end
22
23   end
24 end
25
26 # vim: set ts=2 sw=2 et :