4 module Puppet::Parser::Functions
5 newfunction(:has_interface_with, :type => :rvalue, :doc => <<-DOC
6 Returns boolean based on kind and value:
12 has_interface_with("macaddress", "x:x:x:x:x:x")
13 has_interface_with("ipaddress", "127.0.0.1") => true
16 If no "kind" is given, then the presence of the interface is checked:
17 has_interface_with("lo") => true
21 raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments given (#{args.size} for 1 or 2)") if args.empty? || args.size > 2
23 interfaces = lookupvar('interfaces')
25 # If we do not have any interfaces, then there are no requested attributes
26 return false if interfaces == :undefined || interfaces.nil?
28 interfaces = interfaces.split(',')
31 return interfaces.member?(args[0])
36 # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
37 # https://tickets.puppetlabs.com/browse/PUP-3597
40 catch :undefined_variable do
41 factval = lookupvar(kind)
43 rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set
50 interfaces.each do |iface|
54 # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
55 # https://tickets.puppetlabs.com/browse/PUP-3597
56 catch :undefined_variable do
57 factval = lookupvar("#{kind}_#{iface}")
59 rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set