]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb
variable assignment does not clone string...
[dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / whohosts.rb
index 73f4212b6f2513cc1c58c2b1fde95cb1f5967fc2..ca0d2957c7ec51e0f52ffbce4ca8473cc499184b 100644 (file)
@@ -3,36 +3,34 @@ 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?(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|
+        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)
-              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
     end
+    if not ans['longname']
+      ans['longname'] = ans['name']
+    end
     return ans
   end
 end