X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=modules%2Fpuppetmaster%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fwhohosts.rb;h=b55204ac8fdd17712ae920f509c864288301d088;hb=a97bb246b7122f4bb7686b9b48ee379e00bf4914;hp=84b618c3e6f93c05afe172e6bd800a58c2751f7a;hpb=377748bbc8dc5824bb518905c0f618b27d5e9ea5;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 84b618c3..b55204ac 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb @@ -3,37 +3,36 @@ 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| - if yaml[hoster].kind_of?(Array) - netrange = yaml[hoster] - elsif yaml[hoster].kind_of?(Hash) and yaml[hoster].has_key?('netrange') - netrange = yaml[hoster]['netrange'] - else - next - end - netrange.each do |net| - begin - if IPAddr.new(net).include?(addr) - ans = hoster - end - rescue Exception => e - raise "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}" + 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 = 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