4 module Puppet::Parser::Functions
5 newfunction(:has_interface_with, :type => :rvalue, :doc => <<-DOC
7 Returns boolean based on kind and value.
10 boolean values `true` or `false`
12 Valid kinds are `macaddress`, `netmask`, `ipaddress` and `network`.
15 has_interface_with("macaddress", "x:x:x:x:x:x") # Returns `false`
16 has_interface_with("ipaddress", "127.0.0.1") # Returns `true`
18 @example If no "kind" is given, then the presence of the interface is checked:
19 has_interface_with("lo") # Returns `true`
23 raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments given (#{args.size} for 1 or 2)") if args.empty? || 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
42 catch :undefined_variable do
43 factval = lookupvar(kind)
45 rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set
52 interfaces.each do |iface|
56 # Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
57 # https://tickets.puppetlabs.com/browse/PUP-3597
58 catch :undefined_variable do
59 factval = lookupvar("#{kind}_#{iface}")
61 rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set