X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fpuppetmaster%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fwhohosts.rb;h=20f83d367851f75ad07ad9ba6f957eaaff82038b;hb=7fbd1fb63f9a8e87683b183e8b39bce18af59a4a;hp=73f4212b6f2513cc1c58c2b1fde95cb1f5967fc2;hpb=bf59f9fdc671bd9dc855f0ab9e25dde9613a07f8;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 73f4212b6..20f83d367 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb @@ -3,32 +3,31 @@ module Puppet::Parser::Functions require 'ipaddr' require 'yaml' - nodeinfo = args[0] + ipAddrs = args[0] yamlfile = args[1] 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?(Array) and yaml[hoster].has_key?['netrange'] - netrange = yaml[hoster]['netrange'] - else - next - end - netrange.each do |net| + ipAddrs.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 + + netrange.each do |net| begin if IPAddr.new(net).include?(addr) - return hoster + ans = yaml[hoster] + ans['name'] = hoster end - rescue - raise "Could not match addr #{addr} for net #{net}" + rescue => e + raise Puppet::ParseError, "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}" end end end