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
@@ -0,0 +1,7 @@
1
+ module Puppet
2
+ # At this point, it's an exact copy of the Blastwave stuff.
3
+ Puppet.type(:package).newpkgtype(:sunfreeware, :blastwave) do
4
+ end
5
+ end
6
+
7
+ # $Id: sunfreeware.rb 1357 2006-07-04 06:06:09Z luke $
@@ -1,25 +1,32 @@
1
1
  module Puppet
2
2
  Puppet.type(:package).newpkgtype(:yum, :rpm) do
3
+ include Puppet::Util
3
4
  # Install a package using 'yum'.
4
5
  def install
5
6
  cmd = "yum -y install %s" % self[:name]
6
7
 
7
- self.info "Executing %s" % cmd.inspect
8
- output = %x{#{cmd} 2>&1}
8
+ begin
9
+ output = execute(cmd)
10
+ rescue Puppet::ExecutionFailure => detail
11
+ raise Puppet::PackageError.new(detail)
12
+ end
9
13
 
10
- unless $? == 0
11
- raise Puppet::PackageError.new(output)
14
+ @states[:ensure].retrieve
15
+ if @states[:ensure].is == :absent
16
+ raise Puppet::PackageError.new(
17
+ "Could not find package %s" % self.name
18
+ )
12
19
  end
13
20
  end
14
21
 
15
22
  # What's the latest package version available?
16
23
  def latest
17
24
  cmd = "yum list available %s" % self[:name]
18
- self.info "Executing %s" % cmd.inspect
19
- output = %x{#{cmd} 2>&1}
20
25
 
21
- unless $? == 0
22
- raise Puppet::PackageError.new(output)
26
+ begin
27
+ output = execute(cmd)
28
+ rescue Puppet::ExecutionFailure => detail
29
+ raise Puppet::PackageError.new(detail)
23
30
  end
24
31
 
25
32
  if output =~ /#{self[:name]}\S+\s+(\S+)\s/
@@ -42,4 +49,4 @@ module Puppet
42
49
  end
43
50
  end
44
51
 
45
- # $Id: yum.rb 1128 2006-04-21 03:06:54Z luke $
52
+ # $Id: yum.rb 1421 2006-07-21 23:12:51Z luke $
@@ -221,7 +221,7 @@ module Puppet
221
221
  @fileobj ||= @filetype.new(@path)
222
222
  text = @fileobj.read
223
223
  if text.nil? or text == ""
224
- # there is no host file
224
+ # there is no file
225
225
  return nil
226
226
  else
227
227
  # First we mark all of our objects absent; any objects
@@ -278,7 +278,7 @@ module Puppet
278
278
  end
279
279
  end
280
280
 
281
- # Return the last time the hosts file was loaded. Could
281
+ # Return the last time the file was loaded. Could
282
282
  # be used for reducing writes, but currently is not.
283
283
  def self.loaded?(user)
284
284
  @fileobj ||= @filetype.new(@path)
@@ -305,10 +305,12 @@ module Puppet
305
305
  def retrieve
306
306
  self.class.retrieve()
307
307
 
308
- self.eachstate { |st| st.retrieve }
308
+ self.eachstate { |st|
309
+ st.retrieve
310
+ }
309
311
  end
310
312
 
311
- # Write the entire host file out.
313
+ # Write the entire file out.
312
314
  def store
313
315
  self.class.store()
314
316
  end
@@ -339,4 +341,4 @@ require 'puppet/type/parsedtype/port'
339
341
  require 'puppet/type/parsedtype/mount'
340
342
  require 'puppet/type/parsedtype/sshkey'
341
343
 
342
- # $Id: parsedtype.rb 1125 2006-04-20 19:38:48Z luke $
344
+ # $Id: parsedtype.rb 1223 2006-05-25 06:08:11Z luke $
@@ -6,7 +6,12 @@ require 'puppet/type/state'
6
6
  module Puppet
7
7
  newtype(:mount, Puppet::Type::ParsedType) do
8
8
  ensurable do
9
- desc "Create, remove, or mount a filesystem mount."
9
+ desc "Control what to do with this mount. If the value is
10
+ ``present``, the mount is entered into the mount table,
11
+ but not mounted, if it is ``absent``, the entry is removed
12
+ from the mount table and the filesystem is unmounted if
13
+ currently mounted, if it is ``mounted``, the filesystem
14
+ is entered into the mount table and mounted."
10
15
 
11
16
  newvalue(:present) do
12
17
  @parent.create()
@@ -101,39 +106,50 @@ module Puppet
101
106
  end
102
107
 
103
108
  @doc = "Manages mounted mounts, including putting mount
104
- information into the mount table."
105
-
106
- @instances = []
107
-
108
- @platform = Facter["operatingsystem"].value
109
- case @platform
110
- when "Solaris":
111
- @path = "/etc/vfstab"
112
- @fields = [:device, :blockdevice, :path, :fstype, :pass, :atboot,
113
- :options]
114
- when "Darwin":
115
- @filetype = Puppet::FileType.filetype(:netinfo)
116
- @filetype.format = "fstab"
117
- @path = "mounts"
118
- @fields = [:device, :path, :fstype, :options, :dump, :pass]
119
-
120
- # How to map the dumped table to what we want
121
- @fieldnames = {
122
- "name" => :device,
123
- "dir" => :path,
124
- "dump_freq" => :dump,
125
- "passno" => :pass,
126
- "vfstype" => :fstype,
127
- "opts" => :options
128
- }
129
- else
130
- @path = "/etc/fstab"
131
- @fields = [:device, :path, :fstype, :options, :dump, :pass]
109
+ information into the mount table. The actual behavior depends
110
+ on the value of the 'ensure' parameter."
111
+
112
+ def self.init
113
+ @platform = Facter["operatingsystem"].value
114
+ case @platform
115
+ when "Solaris":
116
+ @path = "/etc/vfstab"
117
+ @fields = [:device, :blockdevice, :path, :fstype, :pass, :atboot,
118
+ :options]
119
+ @defaults = [ nil ] * @fields.size
120
+ when "Darwin":
121
+ @filetype = Puppet::FileType.filetype(:netinfo)
122
+ @filetype.format = "fstab"
123
+ @path = "mounts"
124
+ @fields = [:device, :path, :fstype, :options, :dump, :pass]
125
+ @defaults = [ nil ] * @fields.size
126
+
127
+ # How to map the dumped table to what we want
128
+ @fieldnames = {
129
+ "name" => :device,
130
+ "dir" => :path,
131
+ "dump_freq" => :dump,
132
+ "passno" => :pass,
133
+ "vfstype" => :fstype,
134
+ "opts" => :options
135
+ }
136
+ else
137
+ @path = "/etc/fstab"
138
+ @fields = [:device, :path, :fstype, :options, :dump, :pass]
139
+ @defaults = [ nil ] * 4 + [ "0", "2" ]
140
+ end
141
+
142
+ # Allow Darwin to override the default filetype
143
+ unless defined? @filetype
144
+ @filetype = Puppet::FileType.filetype(:flat)
145
+ end
132
146
  end
133
147
 
134
- # Allow Darwin to override the default filetype
135
- unless defined? @filetype
136
- @filetype = Puppet::FileType.filetype(:flat)
148
+ init
149
+
150
+ def self.clear
151
+ init
152
+ super
137
153
  end
138
154
 
139
155
  # Parse a mount tab.
@@ -156,10 +172,15 @@ module Puppet
156
172
  comment(line)
157
173
  else
158
174
  values = line.split(/\s+/)
159
- unless @fields.length == values.length
175
+ if @fields.length < values.length
160
176
  raise Puppet::Error, "Could not parse line %s" % line
161
177
  end
162
178
 
179
+ values = @defaults.zip(values).collect { |d, v| v || d }
180
+ unless @fields.length == values.length
181
+ raise Puppet::Error, "Could not parse line %s" % line
182
+ end
183
+
163
184
  @fields.zip(values).each do |field, value|
164
185
  hash[field] = value
165
186
  end
@@ -247,4 +268,4 @@ module Puppet
247
268
  end
248
269
  end
249
270
 
250
- # $Id: mount.rb 1113 2006-04-17 16:15:33Z luke $
271
+ # $Id: mount.rb 1380 2006-07-10 23:13:06Z lutter $
@@ -172,6 +172,12 @@ module Puppet
172
172
  end
173
173
  end
174
174
  else
175
+ if line =~ /^\s+\d+/ and
176
+ Facter["operatingsystem"].value == "Darwin"
177
+ #Puppet.notice "Skipping wonky OS X port entry %s" %
178
+ # line.inspect
179
+ next
180
+ end
175
181
  raise Puppet::Error, "Could not match '%s'" % line
176
182
  end
177
183
 
@@ -252,4 +258,4 @@ module Puppet
252
258
  end
253
259
  end
254
260
 
255
- # $Id: port.rb 1129 2006-04-21 19:14:59Z luke $
261
+ # $Id: port.rb 1156 2006-05-01 01:07:47Z luke $
@@ -5,8 +5,6 @@ require 'puppet/type/state'
5
5
 
6
6
  module Puppet
7
7
  newtype(:sshkey, Puppet::Type::ParsedType) do
8
- isaggregatable
9
-
10
8
  newstate(:type) do
11
9
  desc "The encryption type used. Probably ssh-dss or ssh-rsa."
12
10
  end
@@ -21,8 +19,7 @@ module Puppet
21
19
  desc "Any alias the host might have. Multiple values must be
22
20
  specified as an array. Note that this state has the same name
23
21
  as one of the metaparams; using this state to set aliases will
24
- make those aliases available in your Puppet scripts and also on
25
- disk."
22
+ make those aliases available in your Puppet scripts."
26
23
 
27
24
  # We actually want to return the whole array here, not just the first
28
25
  # value.
@@ -57,12 +54,13 @@ module Puppet
57
54
  isnamevar
58
55
  end
59
56
 
60
- @doc = "Installs and manages host entries. For most systems, these
61
- entries will just be in /etc/hosts, but some systems (notably OS X)
62
- will have different solutions."
57
+ @doc = "Installs and manages ssh host keys. At this point, this type
58
+ only knows how to install keys into /etc/ssh/ssh_known_hosts, and
59
+ it cannot manage user authorized keys yet."
63
60
 
64
61
  @instances = []
65
62
 
63
+ # FIXME This should be configurable.
66
64
  @path = "/etc/ssh/ssh_known_hosts"
67
65
  @fields = [:name, :type, :key]
68
66
 
@@ -99,14 +97,6 @@ module Puppet
99
97
  hash[:alias] = names
100
98
  end
101
99
 
102
- #if match = /^(\S+)\s+(\S+)\s*(\S*)$/.match(line)
103
- # fields().zip(match.captures).each { |param, value|
104
- # hash[param] = value
105
- # }
106
- #else
107
- # raise Puppet::Error, "Could not match '%s'" % line
108
- #end
109
-
110
100
  if hash[:alias] == ""
111
101
  hash.delete(:alias)
112
102
  end
@@ -130,4 +120,4 @@ module Puppet
130
120
  end
131
121
  end
132
122
 
133
- # $Id: sshkey.rb 910 2006-02-15 07:20:36Z luke $
123
+ # $Id: sshkey.rb 1279 2006-06-14 15:30:25Z luke $
@@ -32,21 +32,22 @@ module Puppet
32
32
 
33
33
  newparam(:backup) do
34
34
  desc "Whether files should be backed up before
35
- being replaced. If a filebucket_ is specified, files will be
35
+ being replaced. If a filebucket is specified, files will be
36
36
  backed up there; else, they will be backed up in the same directory
37
- with a ``.puppet-bak`` extension.
37
+ with a ``.puppet-bak`` extension,, and no backups
38
+ will be made if backup is ``false``.
38
39
 
39
40
  To use filebuckets, you must first create a filebucket in your
40
- configuration::
41
+ configuration:
41
42
 
42
43
  filebucket { main:
43
44
  server => puppet
44
45
  }
45
46
 
46
- ``puppetmasterd`` creates a filebucket by default, so you can
47
- usually back up to your main server with this configuration. Once
48
- you've described the bucket in your configuration, you can use
49
- it in any file::
47
+ The ``puppetmasterd`` daemon creates a filebucket by default,
48
+ so you can usually back up to your main server with this
49
+ configuration. Once you've described the bucket in your
50
+ configuration, you can use it in any file:
50
51
 
51
52
  file { \"/my/file\":
52
53
  source => \"/path/in/nfs/or/something\",
@@ -64,19 +65,20 @@ module Puppet
64
65
  "
65
66
 
66
67
  attr_reader :bucket
67
- defaultto true
68
+ defaultto ".puppet-bak"
68
69
 
69
70
  munge do |value|
70
71
  case value
71
- when false, "false":
72
+ when false, "false", :false:
72
73
  false
73
- when true, "true", ".puppet-bak":
74
+ when true, "true", ".puppet-bak", :true:
74
75
  ".puppet-bak"
75
76
  when String:
76
77
  # We can't depend on looking this up right now,
77
78
  # we have to do it after all of the objects
78
79
  # have been instantiated.
79
80
  @bucket = value
81
+ value
80
82
  else
81
83
  self.fail "Invalid backup type %s" %
82
84
  value.inspect
@@ -97,10 +99,17 @@ module Puppet
97
99
 
98
100
  newparam(:recurse) do
99
101
  desc "Whether and how deeply to do recursive
100
- management. **false**/*true*/*inf*/*number*"
102
+ management."
101
103
 
104
+ newvalues(:true, :false, :inf, /^[0-9]+$/)
102
105
  munge do |value|
103
- value
106
+ newval = super(value)
107
+ case newval
108
+ when :true, :inf: true
109
+ when :false: false
110
+ else
111
+ newval
112
+ end
104
113
  end
105
114
  end
106
115
 
@@ -216,7 +225,8 @@ module Puppet
216
225
  if @parameters.include?(:backup) and bucket = @parameters[:backup].bucket
217
226
  case bucket
218
227
  when String:
219
- if obj = @@filebuckets.include?(bucket)
228
+ if obj = @@filebuckets[bucket]
229
+ # This sets the @value on :backup, too
220
230
  @parameters[:backup].bucket = obj
221
231
  elsif obj = Puppet.type(:filebucket).bucket(bucket)
222
232
  @@filebuckets[bucket] = obj
@@ -248,9 +258,57 @@ module Puppet
248
258
 
249
259
  case File.stat(file).ftype
250
260
  when "directory":
251
- self.info :bc
252
- # we don't need to backup directories
253
- return true
261
+ if self[:recurse]
262
+ # we don't need to backup directories when recurse is on
263
+ return true
264
+ else
265
+ backup = self[:backup]
266
+ case backup
267
+ when Puppet::Client::Dipper:
268
+ notice "Recursively backing up to filebucket"
269
+ require 'find'
270
+ Find.find(self[:path]) do |f|
271
+ if File.file?(f)
272
+ sum = backup.backup(f)
273
+ self.info "Filebucketed %s to %s with sum %s" %
274
+ [f, backup.name, sum]
275
+ end
276
+ end
277
+
278
+ require 'fileutils'
279
+ FileUtils.rmtree(self[:path])
280
+ return true
281
+ when String:
282
+ newfile = file + backup
283
+ # Just move it, since it's a directory.
284
+ if FileTest.exists?(newfile)
285
+ begin
286
+ File.unlink(newfile)
287
+ rescue => detail
288
+ puts detail.backtrace
289
+ self.err "Could not remove old backup: %s" %
290
+ detail
291
+ return false
292
+ end
293
+ end
294
+ begin
295
+ bfile = file + backup
296
+
297
+ # Ruby 1.8.1 requires the 'preserve' addition, but
298
+ # later versions do not appear to require it.
299
+ FileUtils.cp_r(file, bfile, :preserve => true)
300
+ return true
301
+ rescue => detail
302
+ # since they said they want a backup, let's error out
303
+ # if we couldn't make one
304
+ self.fail "Could not back %s up: %s" %
305
+ [file, detail.message]
306
+ end
307
+ else
308
+ self.err "Invalid backup type %s" % backup.inspect
309
+ return false
310
+ end
311
+ end
254
312
  when "file":
255
313
  backup = self[:backup]
256
314
  case backup
@@ -271,8 +329,13 @@ module Puppet
271
329
  end
272
330
  end
273
331
  begin
274
- FileUtils.cp(file,
275
- file + backup)
332
+ # FIXME Shouldn't this just use a Puppet object with
333
+ # 'source' specified?
334
+ bfile = file + backup
335
+
336
+ # Ruby 1.8.1 requires the 'preserve' addition, but
337
+ # later versions do not appear to require it.
338
+ FileUtils.cp(file, bfile, :preserve => true)
276
339
  return true
277
340
  rescue => detail
278
341
  # since they said they want a backup, let's error out
@@ -281,7 +344,7 @@ module Puppet
281
344
  [file, detail.message]
282
345
  end
283
346
  else
284
- self.err "Invalid backup type %s" % backup
347
+ self.err "Invalid backup type %s" % backup.inspect
285
348
  return false
286
349
  end
287
350
  else
@@ -662,6 +725,9 @@ module Puppet
662
725
  unless @states.include?(:checksum)
663
726
  self[:checksum] = "md5"
664
727
  end
728
+
729
+ # We have to retrieve the source info before the recursion happens,
730
+ # although I'm not exactly clear on why.
665
731
  @states[:source].retrieve
666
732
  end
667
733
 
@@ -678,10 +744,19 @@ module Puppet
678
744
  next if name == :source
679
745
  state.is = :absent
680
746
  }
747
+
681
748
  return
682
749
  end
683
750
 
684
- super
751
+ states().each { |state|
752
+ # We don't want to call 'describe()' twice, so only do a local
753
+ # retrieve on the source.
754
+ if state.name == :source
755
+ state.retrieve(false)
756
+ else
757
+ state.retrieve
758
+ end
759
+ }
685
760
  end
686
761
 
687
762
  # Set the checksum, from another state. There are multiple states that
@@ -710,6 +785,12 @@ module Puppet
710
785
  if self.class.name == :file and self[:links] != :follow
711
786
  method = :lstat
712
787
  end
788
+ path = self[:path]
789
+ # Just skip them when they don't exist at all.
790
+ unless FileTest.exists?(path) or FileTest.symlink?(path)
791
+ @stat = nil
792
+ return @stat
793
+ end
713
794
  if @stat.nil? or refresh == true
714
795
  begin
715
796
  @stat = File.send(method, self[:path])
@@ -727,8 +808,11 @@ module Puppet
727
808
  def uri2obj(source)
728
809
  sourceobj = FileSource.new
729
810
  path = nil
811
+ unless source
812
+ devfail "Got a nil source"
813
+ end
730
814
  if source =~ /^\//
731
- source = "file://localhost/%s" % source
815
+ source = "file://localhost/%s" % URI.escape(source)
732
816
  sourceobj.mount = "localhost"
733
817
  sourceobj.local = true
734
818
  end
@@ -785,9 +869,15 @@ module Puppet
785
869
  def write(usetmp = true)
786
870
  mode = self.should(:mode)
787
871
 
788
- if FileTest.exists?(self[:path])
872
+ #if FileTest.exists?(self[:path])
873
+ if s = stat(false)
789
874
  # this makes sure we have a copy for posterity
790
875
  @backed = self.handlebackup
876
+
877
+ if s.ftype == "link" and self[:links] != :follow
878
+ # Remove existing links, since we're writing out a file
879
+ File.unlink(self[:path])
880
+ end
791
881
  end
792
882
 
793
883
  # The temporary file
@@ -834,6 +924,8 @@ module Puppet
834
924
  end
835
925
 
836
926
  # And then update our checksum, so the next run doesn't find it.
927
+ # FIXME This is extra work, because it's going to read the whole
928
+ # file back in again.
837
929
  self.setchecksum
838
930
  end
839
931
  end # Puppet.type(:pfile)
@@ -857,4 +949,4 @@ module Puppet
857
949
  require 'puppet/type/pfile/mode'
858
950
  require 'puppet/type/pfile/type'
859
951
  end
860
- # $Id: pfile.rb 1125 2006-04-20 19:38:48Z luke $
952
+ # $Id: pfile.rb 1355 2006-07-03 23:15:15Z luke $