]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb
Try returning an info hash for a hoster - this will fail
[dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / whohosts.rb
index c2bda8c4aa05db1fdf7052d5ef4dbb0e427515cd..022ca895af991943211fefb06c4dc166f31b8ee1 100644 (file)
@@ -9,15 +9,26 @@ module Puppet::Parser::Functions
 
     $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|
-            if IPAddr.new(net).include?(addr)
-              ans = 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)
+                ans = yaml[hoster]
+                ans['name'] = hoster
+              end
+            rescue Exception => e
+              raise "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}"
             end
           end
         end
@@ -26,3 +37,6 @@ module Puppet::Parser::Functions
     return ans
   end
 end
+# vim:set ts=2:
+# vim:set et:
+# vim:set shiftwidth=2: