X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fpuppetmaster%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fwhohosts.rb;h=3192bb731c82c2f9890e0981d4b686067c41c2a8;hb=c4c9a52df83e66cd9ed5039f66756529e06c6416;hp=780afa1d0c947c7e698be9399fecc910e14af23e;hpb=11a422dfc9e2ee37f0bd5d6ead76ea2de7b76d57;p=mirror%2Fdsa-puppet.git diff --git a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb index 780afa1d0..3192bb731 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb @@ -1,38 +1,36 @@ +require 'puppet/file_system' + module Puppet::Parser::Functions newfunction(:whohosts, :type => :rvalue) do |args| require 'ipaddr' require 'yaml' - nodeinfo = args[0] - yamlfile = args[1] - parser.watch_file(yamlfile) - - $KCODE = 'utf-8' + ipAddrs = args[0] - ans = "unknown" + ans = {"name" => "unknown"} + yamlfile = Puppet::Parser::Files.find_file('debian_org/misc/hoster.yaml', compiler.environment) 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?(Hash) and yaml[hoster].has_key?('netrange') - netrange = yaml[hoster]['netrange'] - else - next - end + 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 - end - rescue Exception => e - raise "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}" + 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