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|
- yaml[hoster].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)
- ans = hoster
+ ans = yaml[hoster]
+ ans['name'] = hoster
end
+ rescue => e
+ raise Puppet::ParseError, "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}"
end
end
end
return ans
end
end
+# vim:set ts=2:
+# vim:set et:
+# vim:set shiftwidth=2: