5 module Puppet::Parser::Functions
6 newfunction(:has_interface_with, :type => :rvalue, :doc => <<-EOS
7 Returns boolean based on kind and value:
13 has_interface_with("macaddress", "x:x:x:x:x:x")
14 has_interface_with("ipaddress", "127.0.0.1") => true
17 If no "kind" is given, then the presence of the interface is checked:
18 has_interface_with("lo") => true
22 raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " +
23 "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
25 interfaces = lookupvar('interfaces')
27 # If we do not have any interfaces, then there are no requested attributes
28 return false if (interfaces == :undefined || interfaces.nil?)
30 interfaces = interfaces.split(',')
33 return interfaces.member?(args[0])
38 # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
39 # https://tickets.puppetlabs.com/browse/PUP-3597
41 catch :undefined_variable do
42 factval = lookupvar(kind)
49 interfaces.each do |iface|
53 # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
54 # https://tickets.puppetlabs.com/browse/PUP-3597
55 catch :undefined_variable do
56 factval = lookupvar("#{kind}_#{iface}")
58 rescue Puppet::ParseError # Eat the exception if strict_variables = true is set