Skip to content

Instantly share code, notes, and snippets.

@LadyNamedLaura
Last active December 23, 2015 04:16
Show Gist options
  • Save LadyNamedLaura/587fe891f4b7c0183c8b to your computer and use it in GitHub Desktop.
Save LadyNamedLaura/587fe891f4b7c0183c8b to your computer and use it in GitHub Desktop.
puppet get_interface_with.rb
Puppet::Functions.create_function(:get_interface_with) do
def get_interface_with(tests)
interfaces = closure_scope.lookupvar('networking')['interfaces']
interfaces.each do |ifname, info|
(info.fetch('bindings',[]) + info.fetch('bindings6',[])).each do | binding |
good = true
tests.each do |kind, value|
unless lookupval(info, binding, kind) == value
good = false
break
end
end
if good
info = info.dup
info['name'] = ifname
return info
end
end
end
return nil
end
def lookupval(info, binding, kind)
if kind == "macaddress" || kind == "mac"
return info["mac"]
end
return binding[kind]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment