Last active
December 23, 2015 04:16
-
-
Save LadyNamedLaura/587fe891f4b7c0183c8b to your computer and use it in GitHub Desktop.
puppet get_interface_with.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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