puppet 0.16.0 → 0.18.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (185) hide show
  1. data/CHANGELOG +98 -0
  2. data/Rakefile +5 -1
  3. data/bin/puppet +1 -1
  4. data/bin/puppetca +25 -11
  5. data/bin/puppetd +189 -66
  6. data/bin/puppetdoc +79 -62
  7. data/bin/puppetmasterd +93 -49
  8. data/bin/puppetrun +385 -0
  9. data/conf/redhat/client.init +5 -2
  10. data/conf/redhat/fileserver.conf +1 -1
  11. data/conf/redhat/lsb-config.patch +51 -0
  12. data/conf/redhat/puppet.spec +45 -18
  13. data/conf/redhat/puppetd.conf +32 -4
  14. data/conf/redhat/server.init +5 -2
  15. data/conf/solaris/pkginfo +7 -0
  16. data/conf/solaris/smf/puppetd.xml +77 -0
  17. data/conf/solaris/smf/puppetmasterd.xml +77 -0
  18. data/conf/solaris/smf/svc-puppetd +66 -0
  19. data/conf/solaris/smf/svc-puppetmasterd +62 -0
  20. data/examples/code/failers/noobjectrvalue +1 -0
  21. data/examples/code/snippets/deepclassheirarchy.pp +23 -0
  22. data/examples/code/snippets/defineoverrides.pp +17 -0
  23. data/examples/code/snippets/emptyexec.pp +3 -0
  24. data/examples/code/snippets/selectorvalues.pp +6 -1
  25. data/examples/code/snippets/tagged.pp +35 -0
  26. data/ext/ldap/puppet.schema +2 -2
  27. data/install.rb +4 -2
  28. data/lib/puppet.rb +206 -15
  29. data/lib/puppet/client.rb +30 -20
  30. data/lib/puppet/client/ca.rb +2 -2
  31. data/lib/puppet/client/dipper.rb +5 -9
  32. data/lib/puppet/client/master.rb +224 -44
  33. data/lib/puppet/client/pelement.rb +54 -9
  34. data/lib/puppet/client/proxy.rb +3 -2
  35. data/lib/puppet/client/reporter.rb +34 -0
  36. data/lib/puppet/client/runner.rb +17 -0
  37. data/lib/puppet/config.rb +136 -55
  38. data/lib/puppet/daemon.rb +59 -37
  39. data/lib/puppet/element.rb +2 -1
  40. data/lib/puppet/event.rb +14 -3
  41. data/lib/puppet/filetype.rb +28 -19
  42. data/lib/puppet/log.rb +297 -132
  43. data/lib/puppet/metric.rb +31 -131
  44. data/lib/puppet/networkclient.rb +73 -46
  45. data/lib/puppet/parameter.rb +49 -1
  46. data/lib/puppet/parsedfile.rb +32 -12
  47. data/lib/puppet/parser/ast.rb +6 -1
  48. data/lib/puppet/parser/ast/astarray.rb +32 -6
  49. data/lib/puppet/parser/ast/collection.rb +91 -0
  50. data/lib/puppet/parser/ast/compdef.rb +2 -2
  51. data/lib/puppet/parser/ast/component.rb +24 -11
  52. data/lib/puppet/parser/ast/function.rb +50 -0
  53. data/lib/puppet/parser/ast/hostclass.rb +70 -22
  54. data/lib/puppet/parser/ast/node.rb +17 -8
  55. data/lib/puppet/parser/ast/nodedef.rb +1 -1
  56. data/lib/puppet/parser/ast/objectdef.rb +28 -10
  57. data/lib/puppet/parser/ast/selector.rb +4 -1
  58. data/lib/puppet/parser/functions.rb +145 -0
  59. data/lib/puppet/parser/interpreter.rb +243 -86
  60. data/lib/puppet/parser/lexer.rb +5 -4
  61. data/lib/puppet/parser/parser.rb +586 -505
  62. data/lib/puppet/parser/scope.rb +337 -187
  63. data/lib/puppet/rails.rb +115 -0
  64. data/lib/puppet/rails/database.rb +40 -0
  65. data/lib/puppet/rails/host.rb +83 -0
  66. data/lib/puppet/rails/rails_object.rb +42 -0
  67. data/lib/puppet/rails/rails_parameter.rb +5 -0
  68. data/lib/puppet/reports/rrdgraph.rb +20 -0
  69. data/lib/puppet/reports/tagmail.rb +94 -0
  70. data/lib/puppet/server.rb +20 -4
  71. data/lib/puppet/server/authconfig.rb +14 -3
  72. data/lib/puppet/server/authstore.rb +2 -2
  73. data/lib/puppet/server/ca.rb +23 -11
  74. data/lib/puppet/server/filebucket.rb +10 -10
  75. data/lib/puppet/server/fileserver.rb +4 -8
  76. data/lib/puppet/server/master.rb +19 -22
  77. data/lib/puppet/server/pelement.rb +28 -16
  78. data/lib/puppet/server/report.rb +184 -0
  79. data/lib/puppet/server/runner.rb +62 -0
  80. data/lib/puppet/server/servlet.rb +23 -9
  81. data/lib/puppet/sslcertificates/ca.rb +25 -1
  82. data/lib/puppet/statechange.rb +34 -53
  83. data/lib/puppet/storage.rb +1 -2
  84. data/lib/puppet/transaction.rb +305 -133
  85. data/lib/puppet/transaction/report.rb +42 -0
  86. data/lib/puppet/transportable.rb +57 -33
  87. data/lib/puppet/type.rb +260 -127
  88. data/lib/puppet/type/component.rb +9 -21
  89. data/lib/puppet/type/cron.rb +367 -116
  90. data/lib/puppet/type/exec.rb +15 -16
  91. data/lib/puppet/type/group.rb +9 -1
  92. data/lib/puppet/type/nameservice.rb +2 -5
  93. data/lib/puppet/type/nameservice/netinfo.rb +3 -0
  94. data/lib/puppet/type/nameservice/objectadd.rb +23 -10
  95. data/lib/puppet/type/nameservice/pw.rb +16 -3
  96. data/lib/puppet/type/package.rb +25 -75
  97. data/lib/puppet/type/package/apple.rb +15 -1
  98. data/lib/puppet/type/package/apt.rb +37 -2
  99. data/lib/puppet/type/package/blastwave.rb +136 -0
  100. data/lib/puppet/type/package/dpkg.rb +4 -4
  101. data/lib/puppet/type/package/gem.rb +119 -0
  102. data/lib/puppet/type/package/openbsd.rb +7 -6
  103. data/lib/puppet/type/package/ports.rb +7 -2
  104. data/lib/puppet/type/package/rpm.rb +1 -1
  105. data/lib/puppet/type/package/sun.rb +23 -9
  106. data/lib/puppet/type/package/sunfreeware.rb +7 -0
  107. data/lib/puppet/type/package/yum.rb +16 -9
  108. data/lib/puppet/type/parsedtype.rb +7 -5
  109. data/lib/puppet/type/parsedtype/mount.rb +55 -34
  110. data/lib/puppet/type/parsedtype/port.rb +7 -1
  111. data/lib/puppet/type/parsedtype/sshkey.rb +6 -16
  112. data/lib/puppet/type/pfile.rb +115 -23
  113. data/lib/puppet/type/pfile/checksum.rb +18 -5
  114. data/lib/puppet/type/pfile/content.rb +2 -2
  115. data/lib/puppet/type/pfile/ensure.rb +3 -3
  116. data/lib/puppet/type/pfile/group.rb +2 -2
  117. data/lib/puppet/type/pfile/source.rb +28 -17
  118. data/lib/puppet/type/pfile/target.rb +25 -17
  119. data/lib/puppet/type/pfilebucket.rb +25 -6
  120. data/lib/puppet/type/schedule.rb +6 -6
  121. data/lib/puppet/type/service.rb +24 -14
  122. data/lib/puppet/type/service/debian.rb +1 -1
  123. data/lib/puppet/type/service/redhat.rb +13 -10
  124. data/lib/puppet/type/service/smf.rb +3 -3
  125. data/lib/puppet/type/state.rb +1 -2
  126. data/lib/puppet/type/symlink.rb +3 -4
  127. data/lib/puppet/type/user.rb +22 -10
  128. data/lib/puppet/type/yumrepo.rb +6 -1
  129. data/lib/puppet/type/zone.rb +595 -0
  130. data/lib/puppet/util.rb +58 -12
  131. data/test/client/client.rb +2 -2
  132. data/test/client/master.rb +92 -3
  133. data/test/client/pelement.rb +99 -0
  134. data/test/executables/puppetbin.rb +3 -4
  135. data/test/executables/puppetca.rb +3 -3
  136. data/test/executables/puppetd.rb +3 -3
  137. data/test/executables/puppetmasterd.rb +1 -5
  138. data/test/executables/puppetmodule.rb +2 -2
  139. data/test/language/ast.rb +200 -11
  140. data/test/language/functions.rb +245 -0
  141. data/test/language/interpreter.rb +155 -6
  142. data/test/language/lexer.rb +35 -2
  143. data/test/language/node.rb +48 -1
  144. data/test/language/parser.rb +250 -1
  145. data/test/language/rails.rb +105 -0
  146. data/test/language/scope.rb +304 -10
  147. data/test/language/snippets.rb +54 -5
  148. data/test/language/transportable.rb +60 -28
  149. data/test/other/config.rb +214 -1
  150. data/test/other/events.rb +67 -9
  151. data/test/other/log.rb +31 -5
  152. data/test/other/metrics.rb +23 -21
  153. data/test/other/parsedfile.rb +29 -2
  154. data/test/other/puppet.rb +79 -0
  155. data/test/other/report.rb +106 -0
  156. data/test/other/storage.rb +2 -2
  157. data/test/other/transactions.rb +128 -2
  158. data/test/puppet/utiltest.rb +10 -5
  159. data/test/puppettest.rb +193 -21
  160. data/test/server/authstore.rb +13 -4
  161. data/test/server/bucket.rb +33 -8
  162. data/test/server/ca.rb +44 -6
  163. data/test/server/master.rb +6 -7
  164. data/test/server/pelement.rb +15 -5
  165. data/test/server/report.rb +93 -0
  166. data/test/server/runner.rb +107 -0
  167. data/test/server/server.rb +28 -1
  168. data/test/types/cron.rb +339 -31
  169. data/test/types/file.rb +256 -24
  170. data/test/types/filebucket.rb +6 -2
  171. data/test/types/filesources.rb +41 -92
  172. data/test/types/group.rb +31 -1
  173. data/test/types/host.rb +2 -1
  174. data/test/types/mount.rb +18 -1
  175. data/test/types/package.rb +200 -18
  176. data/test/types/service.rb +5 -1
  177. data/test/types/sshkey.rb +2 -1
  178. data/test/types/symlink.rb +3 -2
  179. data/test/types/type.rb +180 -1
  180. data/test/types/user.rb +65 -27
  181. data/test/types/yumrepo.rb +15 -0
  182. data/test/types/zone.rb +437 -0
  183. metadata +43 -4
  184. data/bin/cf2puppet +0 -186
  185. data/conf/redhat/puppetmasterd.conf +0 -5
@@ -34,6 +34,8 @@ class AuthConfig < Puppet::ParsedFile
34
34
  namespace = namespace.intern
35
35
  method = method.intern
36
36
 
37
+ read()
38
+
37
39
  if @rights.include?(name)
38
40
  return @rights[name].allowed?(host, ip)
39
41
  elsif @rights.include?(namespace)
@@ -51,10 +53,15 @@ class AuthConfig < Puppet::ParsedFile
51
53
 
52
54
  def initialize(file = nil, parsenow = true)
53
55
  @file ||= Puppet[:authconfig]
56
+
57
+ unless @file
58
+ raise Puppet::DevError, "No authconfig file defined"
59
+ end
54
60
  return unless self.exists?
55
- super(file)
61
+ super(@file)
56
62
  @rights = Rights.new
57
- @configstamp = @configtimeout = @configstatted = nil
63
+ @configstamp = @configstatted = nil
64
+ @configtimeout = 60
58
65
 
59
66
  if parsenow
60
67
  read()
@@ -73,10 +80,14 @@ class AuthConfig < Puppet::ParsedFile
73
80
 
74
81
  if tmp == @configstamp
75
82
  return
83
+ else
84
+ Puppet.notice "%s vs %s" % [tmp, @configstamp]
76
85
  end
77
86
  else
78
87
  return
79
88
  end
89
+ else
90
+ Puppet.notice "%s and %s" % [@configtimeout, @configstatted]
80
91
  end
81
92
  end
82
93
 
@@ -163,4 +174,4 @@ end
163
174
  end
164
175
  end
165
176
 
166
- # $Id: authconfig.rb 1129 2006-04-21 19:14:59Z luke $
177
+ # $Id: authconfig.rb 1148 2006-04-28 19:46:04Z luke $
@@ -210,7 +210,7 @@ class Server
210
210
  when /^([a-zA-Z][-\w]*\.)+[-\w]+$/: # a full hostname
211
211
  type = :hostname
212
212
  value = pattern.split(".").reverse
213
- when /^\*\.([a-zA-Z][-\w]*\.)+[-\w]+$/: # this doesn't match TLDs
213
+ when /^\*(\.([a-zA-Z][-\w]*)){1,}$/:
214
214
  type = :domain
215
215
  value = pattern.split(".").reverse
216
216
  else
@@ -223,4 +223,4 @@ class Server
223
223
  end
224
224
  end
225
225
  #
226
- # $Id: authstore.rb 1129 2006-04-21 19:14:59Z luke $
226
+ # $Id: authstore.rb 1248 2006-06-08 21:46:07Z luke $
@@ -16,28 +16,36 @@ class Server
16
16
  iface.add_method("array getcert(csr)")
17
17
  }
18
18
 
19
+ def autosign
20
+ if defined? @autosign
21
+ @autosign
22
+ else
23
+ Puppet[:autosign]
24
+ end
25
+ end
26
+
19
27
  # FIXME autosign? should probably accept both hostnames and IP addresses
20
28
  def autosign?(hostname)
21
29
  # simple values are easy
22
- if @autosign == true or @autosign == false
23
- return @autosign
30
+ if autosign == true or autosign == false
31
+ return autosign
24
32
  end
25
33
 
26
34
  # we only otherwise know how to handle files
27
- unless @autosign =~ /^\//
35
+ unless autosign =~ /^\//
28
36
  raise Puppet::Error, "Invalid autosign value %s" %
29
- @autosign.inspect
37
+ autosign.inspect
30
38
  end
31
39
 
32
- unless FileTest.exists?(@autosign)
40
+ unless FileTest.exists?(autosign)
33
41
  unless defined? @@warnedonautosign
34
42
  @@warnedonautosign = true
35
- Puppet.info "Autosign is enabled but %s is missing" % @autosign
43
+ Puppet.info "Autosign is enabled but %s is missing" % autosign
36
44
  end
37
45
  return false
38
46
  end
39
47
  auth = Puppet::Server::AuthStore.new
40
- File.open(@autosign) { |f|
48
+ File.open(autosign) { |f|
41
49
  f.each { |line|
42
50
  auth.allow(line.chomp)
43
51
  }
@@ -49,7 +57,10 @@ class Server
49
57
 
50
58
  def initialize(hash = {})
51
59
  Puppet.config.use(:puppet, :certificates, :ca)
52
- @autosign = hash[:autosign] || Puppet[:autosign]
60
+ if hash.include? :autosign
61
+ @autosign = hash[:autosign]
62
+ end
63
+
53
64
  @ca = Puppet::SSLCertificates::CA.new(hash)
54
65
  end
55
66
 
@@ -101,13 +112,14 @@ class Server
101
112
  # the csr and return the results
102
113
  Puppet.info "Signing certificate for %s" % hostname
103
114
  cert, cacert = @ca.sign(csr)
104
- Puppet.info "Cert: %s; Cacert: %s" % [cert.class, cacert.class]
115
+ #Puppet.info "Cert: %s; Cacert: %s" % [cert.class, cacert.class]
105
116
  return [cert.to_pem, cacert.to_pem]
106
117
  else # just write out the csr for later signing
107
118
  if @ca.getclientcsr(hostname)
108
119
  Puppet.info "Not replacing existing request from %s" % hostname
109
120
  else
110
- Puppet.info "Storing certificate request for %s" % hostname
121
+ Puppet.notice "Host %s has a waiting certificate request" %
122
+ hostname
111
123
  @ca.storeclientcsr(csr)
112
124
  end
113
125
  return ["", ""]
@@ -138,4 +150,4 @@ class Server
138
150
  end
139
151
  end
140
152
 
141
- # $Id: ca.rb 1053 2006-04-02 23:39:02Z luke $
153
+ # $Id: ca.rb 1414 2006-07-21 15:20:44Z luke $
@@ -16,7 +16,7 @@ class Server
16
16
  Puppet.config.setdefaults("filebucket",
17
17
  :bucketdir => {
18
18
  :default => "$vardir/bucket",
19
- :mode => 0770,
19
+ :mode => 0750,
20
20
  :owner => "$user",
21
21
  :group => "$group",
22
22
  :desc => "Where FileBucket files are stored."
@@ -28,7 +28,7 @@ class Server
28
28
  }
29
29
 
30
30
  Puppet::Util.logmethods(self, true)
31
- attr_reader :name
31
+ attr_reader :name, :path
32
32
 
33
33
  # this doesn't work for relative paths
34
34
  def FileBucket.paths(base,md5)
@@ -48,19 +48,19 @@ class Server
48
48
  end
49
49
 
50
50
  if hash.include?(:Path)
51
- @bucket = hash[:Path]
51
+ @path = hash[:Path]
52
52
  hash.delete(:Path)
53
53
  else
54
54
  if defined? Puppet
55
- @bucket = Puppet[:bucketdir]
55
+ @path = Puppet[:bucketdir]
56
56
  else
57
- @bucket = File.expand_path("~/.filebucket")
57
+ @path = File.expand_path("~/.filebucket")
58
58
  end
59
59
  end
60
60
 
61
61
  Puppet.config.use(:filebucket)
62
62
 
63
- @name = "filebucket[#{Puppet[:bucketdir]}]"
63
+ @name = "filebucket[#{@path}]"
64
64
  end
65
65
 
66
66
  # accept a file from a client
@@ -68,7 +68,7 @@ class Server
68
68
  contents = Base64.decode64(string)
69
69
  md5 = Digest::MD5.hexdigest(contents)
70
70
 
71
- bpath, bfile, pathpath = FileBucket.paths(@bucket,md5)
71
+ bpath, bfile, pathpath = FileBucket.paths(@path,md5)
72
72
 
73
73
  # if it's a new directory...
74
74
  if Puppet.recmkdir(bpath)
@@ -109,7 +109,7 @@ class Server
109
109
  addpath = false
110
110
  if FileTest.exists?(pathpath)
111
111
  File.open(pathpath) { |of|
112
- paths = of.readlines
112
+ paths = of.readlines.collect { |l| l.chomp }
113
113
  }
114
114
 
115
115
  # unless our path is already there...
@@ -131,7 +131,7 @@ class Server
131
131
  end
132
132
 
133
133
  def getfile(md5, client = nil, clientip = nil)
134
- bpath, bfile, bpaths = FileBucket.paths(@bucket,md5)
134
+ bpath, bfile, bpaths = FileBucket.paths(@path,md5)
135
135
 
136
136
  unless FileTest.exists?(bfile)
137
137
  return false
@@ -152,4 +152,4 @@ class Server
152
152
  end
153
153
  end
154
154
  #
155
- # $Id: filebucket.rb 1113 2006-04-17 16:15:33Z luke $
155
+ # $Id: filebucket.rb 1392 2006-07-11 20:58:25Z luke $
@@ -60,11 +60,6 @@ class Server
60
60
  return ""
61
61
  end
62
62
 
63
- #if links == :ignore and obj[:type] == "link"
64
- # mount.info "Ignoring link %s" % obj.name
65
- # return ""
66
- #end
67
-
68
63
  desc = []
69
64
  CHECKPARAMS.each { |check|
70
65
  if state = obj.state(check)
@@ -278,7 +273,7 @@ class Server
278
273
  Puppet.err "FileServer error: Cannot read %s; cannot serve" % @config
279
274
  #raise Puppet::Error, "Cannot read %s" % @config
280
275
  rescue Errno::ENOENT => detail
281
- Puppet.err "FileServer error: '%s' does not exit; cannot serve" %
276
+ Puppet.err "FileServer error: '%s' does not exist; cannot serve" %
282
277
  @config
283
278
  #raise Puppet::Error, "%s does not exit" % @config
284
279
  #rescue FileServerError => detail
@@ -423,8 +418,9 @@ class Server
423
418
  path = nil
424
419
  else
425
420
  # Remove any double slashes that might have occurred
426
- path.gsub!(/\/\//, "/")
421
+ path = URI.unescape(path.gsub(/\/\//, "/"))
427
422
  end
423
+
428
424
  return mount, path
429
425
  end
430
426
 
@@ -562,4 +558,4 @@ class Server
562
558
  end
563
559
  end
564
560
 
565
- # $Id: fileserver.rb 989 2006-03-06 21:19:34Z luke $
561
+ # $Id: fileserver.rb 1315 2006-06-27 05:15:51Z luke $
@@ -25,16 +25,15 @@ class Server
25
25
  facts["serverversion"] = Puppet.version.to_s
26
26
 
27
27
  # And then add the server name and IP
28
- facts["servername"] = Facter["hostname"].value
29
- facts["serverip"] = Facter["ipaddress"].value
30
- end
31
-
32
- def filetimeout
33
- @interpreter.filetimeout
34
- end
35
-
36
- def filetimeout=(int)
37
- @interpreter.filetimeout = int
28
+ {"servername" => "hostname",
29
+ "serverip" => "ipaddress"
30
+ }.each do |var, fact|
31
+ if obj = Facter[fact]
32
+ facts[var] = obj.value
33
+ else
34
+ Puppet.warning "Could not retrieve fact %s" % fact
35
+ end
36
+ end
38
37
  end
39
38
 
40
39
  # Tell a client whether there's a fresh config for it
@@ -70,8 +69,6 @@ class Server
70
69
  @ca = nil
71
70
  end
72
71
 
73
- args[:ParseCheck] = hash[:FileTimeout] || 15
74
-
75
72
  Puppet.debug("Creating interpreter")
76
73
 
77
74
  if hash.include?(:UseNodes)
@@ -135,17 +132,17 @@ class Server
135
132
  # This is hackish, but there's no "silence" option for benchmarks
136
133
  # right now
137
134
  if @local
138
- begin
135
+ #begin
139
136
  retobjects = @interpreter.run(client, facts)
140
- rescue Puppet::Error => detail
141
- Puppet.err detail
142
- raise XMLRPC::FaultException.new(
143
- 1, detail.to_s
144
- )
145
- rescue => detail
146
- Puppet.err detail.to_s
147
- return ""
148
- end
137
+ #rescue Puppet::Error => detail
138
+ # Puppet.err detail
139
+ # raise XMLRPC::FaultException.new(
140
+ # 1, detail.to_s
141
+ # )
142
+ #rescue => detail
143
+ # Puppet.err detail.to_s
144
+ # return ""
145
+ #end
149
146
  else
150
147
  benchmark(:notice, "Compiled configuration for %s" % client) do
151
148
  begin
@@ -19,8 +19,7 @@ class Server::PElement < Server::Handler
19
19
  begin
20
20
  case format
21
21
  when "yaml":
22
- tmp = YAML::load(CGI.unescape(bucket))
23
- bucket = tmp
22
+ bucket = YAML::load(Base64.decode64(bucket))
24
23
  else
25
24
  raise Puppet::Error, "Unsupported format '%s'" % format
26
25
  end
@@ -50,6 +49,7 @@ class Server::PElement < Server::Handler
50
49
  # Describe a given object. This returns the 'is' values for every state
51
50
  # available on the object type.
52
51
  def describe(type, name, retrieve = nil, ignore = [], format = "yaml", client = nil, clientip = nil)
52
+ Puppet.info "Describing %s[%s]" % [type, name]
53
53
  @local = true unless client
54
54
  typeklass = nil
55
55
  unless typeklass = Puppet.type(type)
@@ -59,6 +59,7 @@ class Server::PElement < Server::Handler
59
59
  obj = nil
60
60
 
61
61
  retrieve ||= :all
62
+ ignore ||= []
62
63
 
63
64
  if obj = typeklass[name]
64
65
  obj[:check] = retrieve
@@ -71,6 +72,12 @@ class Server::PElement < Server::Handler
71
72
  end
72
73
  end
73
74
 
75
+ unless obj
76
+ raise XMLRPC::FaultException.new(
77
+ 1, "Could not create %s[%s]" % [type, name]
78
+ )
79
+ end
80
+
74
81
  trans = obj.to_trans
75
82
 
76
83
  # Now get rid of any attributes they specifically don't want
@@ -87,20 +94,18 @@ class Server::PElement < Server::Handler
87
94
  end
88
95
  end
89
96
 
90
- if @local
91
- return trans
92
- else
93
- str = nil
97
+ unless @local
94
98
  case format
95
99
  when "yaml":
96
- str = CGI.escape(YAML::dump(trans))
100
+ trans = Base64.encode64(YAML::dump(trans))
97
101
  else
98
102
  raise XMLRPC::FaultException.new(
99
103
  1, "Unavailable config format %s" % format
100
104
  )
101
105
  end
102
- return CGI.escape(str)
103
106
  end
107
+
108
+ return trans
104
109
  end
105
110
 
106
111
  # Create a new fileserving module.
@@ -113,13 +118,15 @@ class Server::PElement < Server::Handler
113
118
  end
114
119
 
115
120
  # List all of the elements of a given type.
116
- def list(type, ignore = [], base = nil, client = nil, clientip = nil)
121
+ def list(type, ignore = [], base = nil, format = "yaml", client = nil, clientip = nil)
117
122
  @local = true unless client
118
123
  typeklass = nil
119
124
  unless typeklass = Puppet.type(type)
120
125
  raise Puppet::Error, "Puppet type %s is unsupported" % type
121
126
  end
122
127
 
128
+ # They can pass in false
129
+ ignore ||= []
123
130
  ignore = [ignore] unless ignore.is_a? Array
124
131
  bucket = TransBucket.new
125
132
  bucket.type = typeklass.name
@@ -131,20 +138,25 @@ class Server::PElement < Server::Handler
131
138
  bucket << object
132
139
  end
133
140
 
134
- if @local
135
- return bucket
136
- else
137
- str = nil
141
+ unless @local
138
142
  case format
139
143
  when "yaml":
140
- str = YAML.dump(bucket)
144
+ begin
145
+ bucket = Base64.encode64(YAML::dump(bucket))
146
+ rescue => detail
147
+ Puppet.err detail
148
+ raise XMLRPC::FaultException.new(
149
+ 1, detail.to_s
150
+ )
151
+ end
141
152
  else
142
153
  raise XMLRPC::FaultException.new(
143
154
  1, "Unavailable config format %s" % format
144
155
  )
145
156
  end
146
- return CGI.escape(str)
147
157
  end
158
+
159
+ return bucket
148
160
  end
149
161
 
150
162
  private
@@ -173,4 +185,4 @@ class Server::PElement < Server::Handler
173
185
  end
174
186
  end
175
187
 
176
- # $Id: pelement.rb 1129 2006-04-21 19:14:59Z luke $
188
+ # $Id: pelement.rb 1145 2006-04-28 04:08:38Z luke $
@@ -0,0 +1,184 @@
1
+ module Puppet
2
+ class Server
3
+ # A simple server for triggering a new run on a Puppet client.
4
+ class Report < Handler
5
+ @interface = XMLRPC::Service::Interface.new("puppetreports") { |iface|
6
+ iface.add_method("string report(array)")
7
+ }
8
+
9
+ Puppet.setdefaults(:reporting,
10
+ :reportdirectory => {:default => "$vardir/reports",
11
+ :mode => 0750,
12
+ :owner => "$user",
13
+ :group => "$group",
14
+ :desc => "The directory in which to store reports received from the
15
+ client. Each client gets a separate subdirectory."},
16
+ :reports => ["none",
17
+ "The list of reports to generate. All reports are looked for
18
+ in puppet/reports/<name>.rb, and multiple report names should be
19
+ comma-separated (whitespace is okay)."
20
+ ]
21
+ )
22
+
23
+ @reports = {}
24
+
25
+ class << self
26
+ attr_reader :hooks
27
+ end
28
+
29
+ def self.reportmethod(report)
30
+ "report_" + report.to_s
31
+ end
32
+
33
+ # Add a hook for processing reports.
34
+ def self.newreport(name, &block)
35
+ name = name.intern if name.is_a? String
36
+ method = reportmethod(name)
37
+
38
+ # We want to define a method so that reports can use 'return'.
39
+ define_method(method, &block)
40
+
41
+ @reports[name] = method
42
+ end
43
+
44
+ # Load a report.
45
+ def self.report(name)
46
+ name = name.intern if name.is_a? String
47
+ unless @reports.include? reportmethod(name)
48
+ begin
49
+ require "puppet/reports/#{name.to_s}"
50
+ unless @reports.include? name
51
+ Puppet.warning(
52
+ "Loaded report file for %s but report was not defined" %
53
+ name
54
+ )
55
+ return nil
56
+ end
57
+ rescue LoadError => detail
58
+ if Puppet[:debug]
59
+ puts detail.backtrace
60
+ end
61
+ Puppet.warning "Could not load report %s: %s" %
62
+ [name, detail]
63
+ return nil
64
+ end
65
+ end
66
+
67
+ @reports[name]
68
+ end
69
+
70
+ def initialize(*args)
71
+ super
72
+ Puppet.config.use(:reporting)
73
+ Puppet.config.use(:metrics)
74
+ end
75
+
76
+ # Dynamically create the report methods as necessary.
77
+ def method_missing(name, *args)
78
+ if name.to_s =~ /^report_(.+)$/
79
+ if self.class.report($1)
80
+ send(name, *args)
81
+ else
82
+ super
83
+ end
84
+ else
85
+ super
86
+ end
87
+ end
88
+
89
+ # Accept a report from a client.
90
+ def report(report, client = nil, clientip = nil)
91
+ # We need the client name for storing files.
92
+ client ||= Facter["hostname"].value
93
+
94
+ # Unescape the report
95
+ unless @local
96
+ report = CGI.unescape(report)
97
+ end
98
+
99
+ process(report)
100
+
101
+ # We don't want any tracking back in the fs. Unlikely, but there
102
+ # you go.
103
+ client.gsub("..",".")
104
+
105
+ dir = File.join(Puppet[:reportdirectory], client)
106
+
107
+ unless FileTest.exists?(dir)
108
+ mkclientdir(client, dir)
109
+ end
110
+
111
+ # Now store the report.
112
+ now = Time.now.gmtime
113
+ name = %w{year month day hour min}.collect do |method|
114
+ # Make sure we're at least two digits everywhere
115
+ "%02d" % now.send(method).to_s
116
+ end.join("") + ".yaml"
117
+
118
+ file = File.join(dir, name)
119
+
120
+ begin
121
+ File.open(file, "w", 0640) do |f|
122
+ f.puts report
123
+ end
124
+ rescue => detail
125
+ if Puppet[:debug]
126
+ puts detail.backtrace
127
+ end
128
+ Puppet.warning "Could not write report for %s at %s: %s" %
129
+ [client, file, detail]
130
+ end
131
+
132
+
133
+ # Our report is in YAML
134
+ return file
135
+ end
136
+
137
+ private
138
+
139
+ def mkclientdir(client, dir)
140
+ Puppet.config.setdefaults("reportclient-#{client}",
141
+ "clientdir-#{client}" => { :default => dir,
142
+ :mode => 0750,
143
+ :owner => "$user",
144
+ :group => "$group"
145
+ }
146
+ )
147
+
148
+ Puppet.config.use("reportclient-#{client}")
149
+ end
150
+
151
+ # Process the report using all of the existing hooks.
152
+ def process(report)
153
+ return if Puppet[:reports] == "none"
154
+
155
+ # First convert the report to real objects
156
+ begin
157
+ report = YAML.load(report)
158
+ rescue => detail
159
+ Puppet.warning "Could not load report: %s" % detail
160
+ return
161
+ end
162
+
163
+ Puppet[:reports].split(/\s*,\s*/).each do |name|
164
+ method = self.class.reportmethod(name)
165
+
166
+ Puppet.info "Processing report %s" % name
167
+ begin
168
+ send(method, report)
169
+ rescue NoMethodError => detail
170
+ Puppet.warning "No report named '%s'" % name
171
+ rescue => detail
172
+ if Puppet[:debug]
173
+ puts detail.backtrace
174
+ end
175
+ Puppet.err "Report %s failed: %s" %
176
+ [name, detail]
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+ # $Id: report.rb 1390 2006-07-11 20:22:27Z luke $