X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=modules%2Fpuppetmaster%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fwhohosts.rb;h=ca0d2957c7ec51e0f52ffbce4ca8473cc499184b;hb=d32b5ca2040af0e861851c5519aa5ff5b7887768;hp=c2bda8c4aa05db1fdf7052d5ef4dbb0e427515cd;hpb=48143e4a3da865ec35a02407723ee995f59f3413;p=dsa-puppet.git diff --git a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb index c2bda8c4..ca0d2957 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb @@ -3,26 +3,37 @@ module Puppet::Parser::Functions require 'ipaddr' require 'yaml' - nodeinfo = args[0] + ipAddrs = args[0] yamlfile = args[1] + parser = Puppet::Parser::Parser.new(environment) parser.watch_file(yamlfile) - $KCODE = 'utf-8' - - ans = "unknown" + ans = {"name" => "unknown"} yaml = YAML.load_file(yamlfile) - if (nodeinfo['ldap'].has_key?('ipHostNumber')) - nodeinfo['ldap']['ipHostNumber'].each do |addr| - yaml.keys.each do |hoster| - yaml[hoster].each do |net| + ipAddrs.each do |addr| + yaml.keys.each do |hoster| + next unless yaml[hoster].kind_of?(Hash) and yaml[hoster].has_key?('netrange') + netrange = yaml[hoster]['netrange'] + + netrange.each do |net| + begin if IPAddr.new(net).include?(addr) - ans = hoster + ans = yaml[hoster] + ans['name'] = hoster end + rescue => e + raise Puppet::ParseError, "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}" end end end end + if not ans['longname'] + ans['longname'] = ans['name'] + end return ans end end +# vim:set ts=2: +# vim:set et: +# vim:set shiftwidth=2: