Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created March 1, 2016 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7e9f6a255db644bd54e3 to your computer and use it in GitHub Desktop.
Save anonymous/7e9f6a255db644bd54e3 to your computer and use it in GitHub Desktop.
require 'ipaddr'
module Puppet::Parser::Functions
# args -> ['ip address', [['name', 'CIDR network', vlanid],...]]
newfunction(:find_vlan_id, :type => :rvalue) do |args|
subnet = args[1].select do |name, net, vlan|
raise Puppet::ParseError, "2: " + name.to_s + "-" + net.to_s + "-" + vlan.to_s
IPAddr.new(net) === args[0]
end
return subnet ? subnet[2] : nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment