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 given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
24 interfaces = lookupvar('interfaces')
26 # If we do not have any interfaces, then there are no requested attributes
27 return false if (interfaces == :undefined || interfaces.nil?)
29 interfaces = interfaces.split(',')
32 return interfaces.member?(args[0])
37 # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
38 # https://tickets.puppetlabs.com/browse/PUP-3597
41 catch :undefined_variable do
42 factval = lookupvar(kind)
44 rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
51 interfaces.each do |iface|
55 # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
56 # https://tickets.puppetlabs.com/browse/PUP-3597
57 catch :undefined_variable do
58 factval = lookupvar("#{kind}_#{iface}")
60 rescue Puppet::ParseError # Eat the exception if strict_variables = true is set