1 require 'puppet/file_system'
3 module Puppet::Parser::Functions
4 newfunction(:whohosts, :type => :rvalue) do |args|
10 ans = {"name" => "unknown"}
11 yamlfile = Puppet::Parser::Files.find_file('debian_org/misc/hoster.yaml', compiler.environment)
12 yaml = YAML.load_file(yamlfile)
14 ipAddrs.each do |addr|
15 yaml.keys.each do |hoster|
16 next unless yaml[hoster].kind_of?(Hash) and yaml[hoster].has_key?('netrange')
17 netrange = yaml[hoster]['netrange']
19 netrange.each do |net|
21 if IPAddr.new(net).include?(addr)
26 raise Puppet::ParseError, "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}"
31 if not ans['longname']
32 ans['longname'] = ans['name']
39 # vim:set shiftwidth=2: