]> git.donarmstrong.com Git - dsa-puppet.git/blob - modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb
first stab at plugins-in-modules style
[dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / whohosts.rb
1 module Puppet::Parser::Functions
2   newfunction(:whohosts, :type => :rvalue) do |args|
3     require 'ipaddr'
4     require 'yaml'
5
6     nodeinfo = args[0]
7     yamlfile = args[1]
8     parser.watch_file(yamlfile)
9
10     $KCODE = 'utf-8'
11
12     ans = "unknown"
13     yaml = YAML.load_file(yamlfile)
14
15     if (nodeinfo['ldap'].has_key?('ipHostNumber'))
16       nodeinfo['ldap']['ipHostNumber'].each do |addr|
17         yaml.keys.each do |hoster|
18           yaml[hoster].each do |net|
19             if IPAddr.new(net).include?(addr)
20               ans = hoster
21             end
22           end
23         end
24       end
25     end
26     return ans
27   end
28 end