chef 0.9.10 → 0.9.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/chef/cookbook_version.rb +30 -18
- data/lib/chef/file_cache.rb +2 -2
- data/lib/chef/provider/remote_file.rb +1 -1
- data/lib/chef/provider/user/useradd.rb +39 -25
- data/lib/chef/shef/ext.rb +13 -10
- data/lib/chef/shef/shef_session.rb +2 -2
- data/lib/chef/version.rb +1 -1
- metadata +3 -3
@@ -208,6 +208,10 @@ class Chef
|
|
208
208
|
@valid_cache_entries = nil
|
209
209
|
end
|
210
210
|
|
211
|
+
def self.cache
|
212
|
+
Chef::FileCache
|
213
|
+
end
|
214
|
+
|
211
215
|
# Setup a notification to clear the valid_cache_entries when a Chef client
|
212
216
|
# run starts
|
213
217
|
Chef::Client.when_run_starts do |run_status|
|
@@ -221,14 +225,7 @@ class Chef
|
|
221
225
|
def self.sync_cookbooks(cookbook_hash)
|
222
226
|
Chef::Log.debug("Cookbooks to load: #{cookbook_hash.inspect}")
|
223
227
|
|
224
|
-
|
225
|
-
Chef::FileCache.find(File.join(%w{cookbooks ** *})).each do |cache_file|
|
226
|
-
cache_file =~ /^cookbooks\/([^\/]+)\//
|
227
|
-
unless cookbook_hash.has_key?($1)
|
228
|
-
Chef::Log.info("Removing #{cache_file} from the cache; its cookbook is no longer needed on this client.")
|
229
|
-
Chef::FileCache.delete(cache_file)
|
230
|
-
end
|
231
|
-
end
|
228
|
+
clear_obsoleted_cookbooks(cookbook_hash)
|
232
229
|
|
233
230
|
# Synchronize each of the node's cookbooks, and add to the
|
234
231
|
# valid_cache_entries hash.
|
@@ -239,6 +236,19 @@ class Chef
|
|
239
236
|
true
|
240
237
|
end
|
241
238
|
|
239
|
+
# Iterates over cached cookbooks' files, removing files belonging to
|
240
|
+
# cookbooks that don't appear in +cookbook_hash+
|
241
|
+
def self.clear_obsoleted_cookbooks(cookbook_hash)
|
242
|
+
# Remove all cookbooks no longer relevant to this node
|
243
|
+
cache.find(File.join(%w{cookbooks ** *})).each do |cache_file|
|
244
|
+
cache_file =~ /^cookbooks\/([^\/]+)\//
|
245
|
+
unless cookbook_hash.has_key?($1)
|
246
|
+
Chef::Log.info("Removing #{cache_file} from the cache; its cookbook is no longer needed on this client.")
|
247
|
+
cache.delete(cache_file)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
242
252
|
# Update the file caches for a given cache segment. Takes a segment name
|
243
253
|
# and a hash that matches one of the cookbooks/_attribute_files style
|
244
254
|
# remote file listings.
|
@@ -268,8 +278,8 @@ class Chef
|
|
268
278
|
valid_cache_entries[cache_filename] = true
|
269
279
|
|
270
280
|
current_checksum = nil
|
271
|
-
if
|
272
|
-
current_checksum = checksum_cookbook_file(
|
281
|
+
if cache.has_key?(cache_filename)
|
282
|
+
current_checksum = checksum_cookbook_file(cache.load(cache_filename, false))
|
273
283
|
end
|
274
284
|
|
275
285
|
# If the checksums are different between on-disk (current) and on-server
|
@@ -279,13 +289,13 @@ class Chef
|
|
279
289
|
raw_file = chef_server_rest.get_rest(manifest_record[:url], true)
|
280
290
|
|
281
291
|
Chef::Log.info("Storing updated #{cache_filename} in the cache.")
|
282
|
-
|
292
|
+
cache.move_to(raw_file.path, cache_filename)
|
283
293
|
else
|
284
294
|
Chef::Log.debug("Not storing #{cache_filename}, as the cache is up to date.")
|
285
295
|
end
|
286
296
|
|
287
297
|
# make the segment filenames a full path.
|
288
|
-
full_path_cache_filename =
|
298
|
+
full_path_cache_filename = cache.load(cache_filename, false)
|
289
299
|
segment_filenames << full_path_cache_filename
|
290
300
|
end
|
291
301
|
|
@@ -301,12 +311,14 @@ class Chef
|
|
301
311
|
end
|
302
312
|
|
303
313
|
def self.cleanup_file_cache
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
314
|
+
unless Chef::Config[:solo]
|
315
|
+
# Delete each file in the cache that we didn't encounter in the
|
316
|
+
# manifest.
|
317
|
+
cache.find(File.join(%w{cookbooks ** *})).each do |cache_filename|
|
318
|
+
unless valid_cache_entries[cache_filename]
|
319
|
+
Chef::Log.info("Removing #{cache_filename} from the cache; it is no longer on the server.")
|
320
|
+
cache.delete(cache_filename)
|
321
|
+
end
|
310
322
|
end
|
311
323
|
end
|
312
324
|
end
|
data/lib/chef/file_cache.rb
CHANGED
@@ -57,9 +57,9 @@ class Chef
|
|
57
57
|
true
|
58
58
|
end
|
59
59
|
|
60
|
-
# Move a file
|
60
|
+
# Move a file into the cache. Useful with the REST raw file output.
|
61
61
|
#
|
62
|
-
# ===
|
62
|
+
# === Parameters
|
63
63
|
# file<String>:: The path to the file you want in the cache
|
64
64
|
# path<String>:: The relative name you want the new file to use
|
65
65
|
def move_to(file, path)
|
@@ -22,21 +22,24 @@ class Chef
|
|
22
22
|
class Provider
|
23
23
|
class User
|
24
24
|
class Useradd < Chef::Provider::User
|
25
|
+
UNIVERSAL_OPTIONS = [[:comment, "-c"], [:gid, "-g"], [:password, "-p"], [:shell, "-s"], [:uid, "-u"]]
|
26
|
+
|
25
27
|
def create_user
|
26
|
-
command = "useradd"
|
27
|
-
|
28
|
+
command = compile_command("useradd") do |useradd|
|
29
|
+
useradd << universal_options
|
30
|
+
useradd << useradd_options
|
31
|
+
end
|
28
32
|
run_command(:command => command)
|
29
33
|
end
|
30
34
|
|
31
35
|
def manage_user
|
32
|
-
command = "usermod"
|
33
|
-
command << set_options
|
36
|
+
command = compile_command("usermod") { |u| u << universal_options }
|
34
37
|
run_command(:command => command)
|
35
38
|
end
|
36
39
|
|
37
40
|
def remove_user
|
38
41
|
command = "userdel"
|
39
|
-
command << " -r" if
|
42
|
+
command << " -r" if managing_home_dir?
|
40
43
|
command << " #{@new_resource.username}"
|
41
44
|
run_command(:command => command)
|
42
45
|
end
|
@@ -82,41 +85,52 @@ class Chef
|
|
82
85
|
def unlock_user
|
83
86
|
run_command(:command => "usermod -U #{@new_resource.username}")
|
84
87
|
end
|
88
|
+
|
89
|
+
def compile_command(base_command)
|
90
|
+
yield base_command
|
91
|
+
base_command << " #{@new_resource.username}"
|
92
|
+
base_command
|
93
|
+
end
|
85
94
|
|
86
|
-
def
|
95
|
+
def universal_options
|
87
96
|
opts = ''
|
88
97
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
'password' => "-p"
|
95
|
-
}
|
96
|
-
field_list.sort{ |a,b| a[0] <=> b[0] }.each do |field, option|
|
97
|
-
field_symbol = field.to_sym
|
98
|
-
if @current_resource.send(field_symbol) != @new_resource.send(field_symbol)
|
99
|
-
if @new_resource.send(field_symbol)
|
100
|
-
Chef::Log.debug("Setting #{@new_resource} #{field} to #{@new_resource.send(field_symbol)}")
|
101
|
-
opts << " #{option} '#{@new_resource.send(field_symbol)}'"
|
98
|
+
UNIVERSAL_OPTIONS.each do |field, option|
|
99
|
+
if @current_resource.send(field) != @new_resource.send(field)
|
100
|
+
if @new_resource.send(field)
|
101
|
+
Chef::Log.debug("Setting #{@new_resource} #{field} to #{@new_resource.send(field)}")
|
102
|
+
opts << " #{option} '#{@new_resource.send(field)}'"
|
102
103
|
end
|
103
104
|
end
|
104
105
|
end
|
105
|
-
if
|
106
|
-
if
|
106
|
+
if updating_home?
|
107
|
+
if managing_home_dir?
|
107
108
|
Chef::Log.debug("Managing the home directory for #{@new_resource}")
|
108
|
-
opts << " -d '#{@new_resource.home}'
|
109
|
+
opts << " -d '#{@new_resource.home}'"
|
109
110
|
else
|
110
111
|
Chef::Log.debug("Setting #{@new_resource} home to #{@new_resource.home}")
|
111
112
|
opts << " -d '#{@new_resource.home}'"
|
112
113
|
end
|
113
114
|
end
|
114
|
-
opts << " -r" if @new_resource.system
|
115
115
|
opts << " -o" if @new_resource.non_unique || @new_resource.supports[:non_unique]
|
116
|
-
opts << " #{@new_resource.username}"
|
117
116
|
opts
|
118
117
|
end
|
119
|
-
|
118
|
+
|
119
|
+
def useradd_options
|
120
|
+
opts = ''
|
121
|
+
opts << " -m" if updating_home? && managing_home_dir?
|
122
|
+
opts << " -r" if @new_resource.system
|
123
|
+
opts
|
124
|
+
end
|
125
|
+
|
126
|
+
def updating_home?
|
127
|
+
@current_resource.home != @new_resource.home && @new_resource.home
|
128
|
+
end
|
129
|
+
|
130
|
+
def managing_home_dir?
|
131
|
+
@new_resource.manage_home || @new_resource.supports[:manage_home]
|
132
|
+
end
|
133
|
+
|
120
134
|
end
|
121
135
|
end
|
122
136
|
end
|
data/lib/chef/shef/ext.rb
CHANGED
@@ -226,16 +226,6 @@ E
|
|
226
226
|
:attributes
|
227
227
|
end
|
228
228
|
|
229
|
-
desc "returns the current node (i.e., this host)"
|
230
|
-
def node
|
231
|
-
Shef.session.node
|
232
|
-
end
|
233
|
-
|
234
|
-
desc "pretty print the node's attributes"
|
235
|
-
def ohai(key=nil)
|
236
|
-
pp(key ? node.attribute[key] : node.attribute)
|
237
|
-
end
|
238
|
-
|
239
229
|
desc "run chef using the current recipe"
|
240
230
|
def run_chef
|
241
231
|
Chef::Log.level = :debug
|
@@ -295,6 +285,18 @@ E
|
|
295
285
|
end
|
296
286
|
end
|
297
287
|
|
288
|
+
MainContextExtensions = Proc.new do
|
289
|
+
desc "returns the current node (i.e., this host)"
|
290
|
+
def node
|
291
|
+
Shef.session.node
|
292
|
+
end
|
293
|
+
|
294
|
+
desc "pretty print the node's attributes"
|
295
|
+
def ohai(key=nil)
|
296
|
+
pp(key ? node.attribute[key] : node.attribute)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
298
300
|
RESTApiExtensions = Proc.new do
|
299
301
|
desc "edit an object in your EDITOR"
|
300
302
|
explain(<<-E)
|
@@ -530,6 +532,7 @@ E
|
|
530
532
|
|
531
533
|
def self.extend_context_object(obj)
|
532
534
|
obj.instance_eval(&ObjectUIExtensions)
|
535
|
+
obj.instance_eval(&MainContextExtensions)
|
533
536
|
obj.instance_eval(&RESTApiExtensions)
|
534
537
|
obj.extend(FileUtils)
|
535
538
|
obj.extend(Chef::Mixin::Language)
|
@@ -190,7 +190,7 @@ module Shef
|
|
190
190
|
@client.register
|
191
191
|
@client.build_node
|
192
192
|
|
193
|
-
@client.sync_cookbooks
|
193
|
+
@client.sync_cookbooks
|
194
194
|
end
|
195
195
|
|
196
196
|
end
|
@@ -263,7 +263,7 @@ module Shef
|
|
263
263
|
@client.register
|
264
264
|
@client.build_node
|
265
265
|
|
266
|
-
@client.sync_cookbooks
|
266
|
+
@client.sync_cookbooks
|
267
267
|
end
|
268
268
|
|
269
269
|
end
|
data/lib/chef/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 12
|
9
|
+
version: 0.9.12
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Adam Jacob
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-22 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|