Remove smarthost_port from nodeinfo
[mirror/dsa-puppet.git] / modules / puppetmaster / lib / puppet / parser / functions / yamlinfo.rb
1 require 'puppet/file_system'
2
3 module Puppet::Parser::Functions
4   newfunction(:yamlinfo, :type => :rvalue) do |args|
5
6     host = args[0]
7
8     read_yaml = lambda { |yaml, host|
9       results = {}
10
11       ['nameinfo', 'footer'].each do |detail|
12         if yaml.has_key?(detail)
13           if yaml[detail].has_key?(host)
14             results[detail] = yaml[detail][host]
15           end
16         end
17       end
18       
19       if yaml.has_key?('services')
20         yaml['services'].each_pair do |service, hostlist|
21           hostlist=[hostlist] unless hostlist.kind_of?(Array)
22           results[service] = hostlist.include?(host)
23         end
24       end
25
26       results['mail_port']      = ''
27       results['smarthost']      = ''
28       results['heavy_exim']     = ''
29
30       if yaml['host_settings'].kind_of?(Hash)
31         yaml['host_settings'].each_pair do |property, values|
32           if values.kind_of?(Hash)
33             results[property] = values[host] if values.has_key?(host)
34           elsif values.kind_of?(Array)
35             results[property] = values.include?(host)
36           end
37         end
38       end
39       return(results)
40     }
41
42     require 'yaml'
43
44     yamlfile = Puppet::Parser::Files.find_file('debian_org/misc/local.yaml', compiler.environment)
45     yaml = YAML.load_file(yamlfile)
46     ret = {}
47
48     if host == '*'
49       Dir.entries('/var/lib/puppet/yaml/node/').each do |fname|
50         next unless fname =~ /(.*)\.yaml$/
51         host_name = $1
52         ret[host_name] = read_yaml.call(yaml, host_name)
53       end
54     else
55       ret = read_yaml.call(yaml, host)
56     end
57
58     return(ret)
59   end
60 end
61