Last active
December 14, 2015 08:58
-
-
Save vjanelle/5061070 to your computer and use it in GitHub Desktop.
attempts to find an interface that'll serve the IP address
This file contains 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
# find_ip_by_interface.rb | |
# | |
# Attempts to discover which interface will serve a particular destination | |
# | |
require 'ipaddr' | |
module Puppet::Parser::Functions | |
newfunction(:find_ip_by_interface, :type => :rvalue) do |args| | |
address = IPAddr.new(args[0]) | |
retcon = "" | |
lookupvar('interfaces').split(',').each do |interface| | |
netmask = lookupvar("netmask_#{interface}") | |
int_addr = lookupvar("ipaddress_#{interface}") | |
int = IPAddr.new("#{int_addr}/#{netmask}") | |
if int.include?(address) | |
retcon = interface | |
end | |
end | |
retcon | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment