chef 0.8.10 → 0.8.14
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/bin/chef-client +2 -2
- data/bin/chef-solo +1 -2
- data/bin/knife +1 -2
- data/bin/shef +2 -5
- data/lib/chef.rb +11 -7
- data/lib/chef/application.rb +25 -20
- data/lib/chef/application/client.rb +12 -7
- data/lib/chef/application/knife.rb +7 -1
- data/lib/chef/application/solo.rb +1 -1
- data/lib/chef/applications.rb +4 -0
- data/lib/chef/cache/checksum.rb +7 -6
- data/lib/chef/certificate.rb +2 -2
- data/lib/chef/client.rb +28 -4
- data/lib/chef/config.rb +4 -3
- data/lib/chef/cookbook_loader.rb +6 -1
- data/lib/chef/daemon.rb +2 -0
- data/lib/chef/data_bag_item.rb +2 -1
- data/lib/chef/exceptions.rb +5 -0
- data/lib/chef/file_cache.rb +18 -18
- data/lib/chef/index_queue/indexable.rb +5 -3
- data/lib/chef/knife.rb +45 -13
- data/lib/chef/knife/client_list.rb +1 -1
- data/lib/chef/knife/client_show.rb +1 -1
- data/lib/chef/knife/configure.rb +47 -36
- data/lib/chef/knife/cookbook_list.rb +1 -1
- data/lib/chef/knife/cookbook_metadata.rb +22 -27
- data/lib/chef/knife/cookbook_metadata_from_file.rb +40 -0
- data/lib/chef/knife/cookbook_show.rb +2 -2
- data/lib/chef/knife/cookbook_site_download.rb +57 -0
- data/lib/chef/knife/cookbook_site_list.rb +55 -0
- data/lib/chef/knife/cookbook_site_search.rb +50 -0
- data/lib/chef/knife/cookbook_site_show.rb +56 -0
- data/lib/chef/knife/cookbook_site_vendor.rb +114 -0
- data/lib/chef/knife/cookbook_test.rb +103 -0
- data/lib/chef/knife/cookbook_upload.rb +29 -38
- data/lib/chef/knife/data_bag_edit.rb +1 -1
- data/lib/chef/knife/data_bag_list.rb +2 -2
- data/lib/chef/knife/data_bag_show.rb +1 -1
- data/lib/chef/knife/ec2_instance_data.rb +1 -1
- data/lib/chef/knife/index_rebuild.rb +2 -2
- data/lib/chef/knife/node_from_file.rb +1 -1
- data/lib/chef/knife/node_list.rb +2 -2
- data/lib/chef/knife/node_run_list_add.rb +1 -1
- data/lib/chef/knife/node_run_list_remove.rb +1 -1
- data/lib/chef/knife/node_show.rb +1 -1
- data/lib/chef/knife/rackspace_server_create.rb +156 -0
- data/lib/chef/knife/rackspace_server_delete.rb +57 -0
- data/lib/chef/knife/rackspace_server_list.rb +59 -0
- data/lib/chef/knife/role_from_file.rb +1 -1
- data/lib/chef/knife/role_list.rb +1 -1
- data/lib/chef/knife/role_show.rb +1 -1
- data/lib/chef/knife/search.rb +1 -1
- data/lib/chef/knife/ssh.rb +21 -4
- data/lib/chef/knife/terremark_server_create.rb +152 -0
- data/lib/chef/knife/terremark_server_delete.rb +87 -0
- data/lib/chef/knife/terremark_server_list.rb +77 -0
- data/lib/chef/mixin/command.rb +11 -9
- data/lib/chef/mixin/params_validate.rb +1 -1
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +4 -1
- data/lib/chef/mixin/template.rb +6 -5
- data/lib/chef/mixin/xml_escape.rb +3 -3
- data/lib/chef/mixins.rb +16 -0
- data/lib/chef/node.rb +53 -52
- data/lib/chef/openid_registration.rb +0 -1
- data/lib/chef/platform.rb +171 -137
- data/lib/chef/provider.rb +2 -2
- data/lib/chef/provider/cron.rb +22 -22
- data/lib/chef/provider/deploy/revision.rb +5 -1
- data/lib/chef/provider/erl_call.rb +2 -2
- data/lib/chef/provider/file.rb +44 -23
- data/lib/chef/provider/group/dscl.rb +6 -4
- data/lib/chef/provider/mdadm.rb +0 -4
- data/lib/chef/provider/mount/mount.rb +20 -8
- data/lib/chef/provider/package.rb +1 -1
- data/lib/chef/provider/package/freebsd.rb +22 -18
- data/lib/chef/provider/package/rubygems.rb +7 -10
- data/lib/chef/provider/remote_directory.rb +15 -0
- data/lib/chef/provider/remote_file.rb +73 -50
- data/lib/chef/provider/script.rb +10 -8
- data/lib/chef/provider/service/windows.rb +129 -0
- data/lib/chef/provider/subversion.rb +1 -1
- data/lib/chef/provider/template.rb +51 -50
- data/lib/chef/providers.rb +80 -0
- data/lib/chef/recipe.rb +2 -4
- data/lib/chef/resource.rb +21 -7
- data/lib/chef/resource/cron.rb +14 -5
- data/lib/chef/resource/deploy.rb +52 -45
- data/lib/chef/resource/execute.rb +1 -1
- data/lib/chef/resource/file.rb +16 -8
- data/lib/chef/resource/mount.rb +1 -1
- data/lib/chef/resource/remote_directory.rb +19 -10
- data/lib/chef/resource/scm.rb +23 -16
- data/lib/chef/resource/service.rb +10 -1
- data/lib/chef/resources.rb +60 -0
- data/lib/chef/rest.rb +234 -189
- data/lib/chef/rest/auth_credentials.rb +78 -0
- data/lib/chef/{application/server.rb → rest/cookie_jar.rb} +18 -6
- data/lib/chef/rest/rest_request.rb +151 -0
- data/lib/chef/role.rb +38 -46
- data/lib/chef/streaming_cookbook_uploader.rb +8 -2
- data/lib/chef/tasks/chef_repo.rake +14 -4
- data/lib/chef/util/file_edit.rb +0 -1
- data/lib/chef/webui_user.rb +0 -1
- metadata +46 -9
- data/distro/suse/etc/init.d/chef-client +0 -121
data/lib/chef/node.rb
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
# you may not use this file except in compliance with the License.
|
9
9
|
# You may obtain a copy of the License at
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# Unless required by applicable law or agreed to in writing, software
|
14
14
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
15
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -22,6 +22,7 @@ require 'chef/mixin/check_helper'
|
|
22
22
|
require 'chef/mixin/params_validate'
|
23
23
|
require 'chef/mixin/from_file'
|
24
24
|
require 'chef/mixin/language_include_attribute'
|
25
|
+
require 'chef/mixin/deep_merge'
|
25
26
|
require 'chef/couchdb'
|
26
27
|
require 'chef/rest'
|
27
28
|
require 'chef/run_list'
|
@@ -32,24 +33,24 @@ require 'json'
|
|
32
33
|
|
33
34
|
class Chef
|
34
35
|
class Node
|
35
|
-
|
36
|
+
|
36
37
|
attr_accessor :attribute, :recipe_list, :couchdb, :couchdb_rev, :run_state, :run_list, :override_attrs, :default_attrs, :cookbook_loader
|
37
38
|
attr_reader :node
|
38
39
|
attr_reader :couchdb_id
|
39
|
-
|
40
|
+
|
40
41
|
include Chef::Mixin::CheckHelper
|
41
42
|
include Chef::Mixin::FromFile
|
42
43
|
include Chef::Mixin::ParamsValidate
|
43
44
|
include Chef::Mixin::LanguageIncludeAttribute
|
44
45
|
include Chef::IndexQueue::Indexable
|
45
|
-
|
46
|
+
|
46
47
|
DESIGN_DOCUMENT = {
|
47
48
|
"version" => 9,
|
48
49
|
"language" => "javascript",
|
49
50
|
"views" => {
|
50
51
|
"all" => {
|
51
52
|
"map" => <<-EOJS
|
52
|
-
function(doc) {
|
53
|
+
function(doc) {
|
53
54
|
if (doc.chef_type == "node") {
|
54
55
|
emit(doc.name, doc);
|
55
56
|
}
|
@@ -58,7 +59,7 @@ class Chef
|
|
58
59
|
},
|
59
60
|
"all_id" => {
|
60
61
|
"map" => <<-EOJS
|
61
|
-
function(doc) {
|
62
|
+
function(doc) {
|
62
63
|
if (doc.chef_type == "node") {
|
63
64
|
emit(doc.name, doc.name);
|
64
65
|
}
|
@@ -84,7 +85,7 @@ class Chef
|
|
84
85
|
to_emit["ohai_time"] = doc["attributes"]["ohai_time"];
|
85
86
|
} else {
|
86
87
|
to_emit["ohai_time"] = "Undefined";
|
87
|
-
}
|
88
|
+
}
|
88
89
|
if (doc["attributes"]["uptime"]) {
|
89
90
|
to_emit["uptime"] = doc["attributes"]["uptime"];
|
90
91
|
} else {
|
@@ -125,7 +126,7 @@ class Chef
|
|
125
126
|
}
|
126
127
|
},
|
127
128
|
}
|
128
|
-
|
129
|
+
|
129
130
|
# Create a new Chef::Node object.
|
130
131
|
def initialize(couchdb=nil)
|
131
132
|
@name = nil
|
@@ -153,36 +154,36 @@ class Chef
|
|
153
154
|
end
|
154
155
|
|
155
156
|
def chef_server_rest
|
156
|
-
Chef::REST.new(Chef::Config[:chef_server_url])
|
157
|
+
Chef::REST.new(Chef::Config[:chef_server_url])
|
157
158
|
end
|
158
159
|
|
159
160
|
def self.chef_server_rest
|
160
|
-
Chef::REST.new(Chef::Config[:chef_server_url])
|
161
|
+
Chef::REST.new(Chef::Config[:chef_server_url])
|
161
162
|
end
|
162
163
|
|
163
|
-
# Find a recipe for this Chef::Node by fqdn. Will search first for
|
164
|
+
# Find a recipe for this Chef::Node by fqdn. Will search first for
|
164
165
|
# Chef::Config["node_path"]/fqdn.rb, then hostname.rb, then default.rb.
|
165
|
-
#
|
166
|
+
#
|
166
167
|
# Returns a new Chef::Node object.
|
167
168
|
#
|
168
|
-
# Raises an ArgumentError if it cannot find the node.
|
169
|
+
# Raises an ArgumentError if it cannot find the node.
|
169
170
|
def find_file(fqdn)
|
170
171
|
host_parts = fqdn.split(".")
|
171
172
|
hostname = host_parts[0]
|
172
|
-
|
173
|
+
|
173
174
|
[fqdn, hostname, "default"].each { |fname|
|
174
|
-
node_file = File.join(Chef::Config[:node_path], "#{fname.to_s}.rb")
|
175
|
+
node_file = File.join(Chef::Config[:node_path], "#{fname.to_s}.rb")
|
175
176
|
return self.from_file(node_file) if File.exists?(node_file)
|
176
177
|
}
|
177
|
-
|
178
|
-
raise ArgumentError, "Cannot find a node matching #{fqdn}, not even with default.rb!"
|
178
|
+
|
179
|
+
raise ArgumentError, "Cannot find a node matching #{fqdn}, not even with default.rb!"
|
179
180
|
end
|
180
|
-
|
181
|
+
|
181
182
|
# Set the name of this Node, or return the current name.
|
182
183
|
def name(arg=nil)
|
183
184
|
if arg != nil
|
184
185
|
validate(
|
185
|
-
{:name => arg },
|
186
|
+
{:name => arg },
|
186
187
|
{:name => { :kind_of => String,
|
187
188
|
:cannot_be => :blank}
|
188
189
|
})
|
@@ -191,17 +192,17 @@ class Chef
|
|
191
192
|
@name
|
192
193
|
end
|
193
194
|
end
|
194
|
-
|
195
|
+
|
195
196
|
# Return an attribute of this node. Returns nil if the attribute is not found.
|
196
197
|
def [](attrib)
|
197
198
|
Chef::Node::Attribute.new(@attribute, @default_attrs, @override_attrs)[attrib]
|
198
199
|
end
|
199
|
-
|
200
|
+
|
200
201
|
# Set an attribute of this node
|
201
202
|
def []=(attrib, value)
|
202
203
|
Chef::Node::Attribute.new(@attribute, @default_attrs, @override_attrs)[attrib] = value
|
203
204
|
end
|
204
|
-
|
205
|
+
|
205
206
|
def store(attrib, value)
|
206
207
|
self[attrib] = value
|
207
208
|
end
|
@@ -233,12 +234,12 @@ class Chef
|
|
233
234
|
def attribute?(attrib)
|
234
235
|
Chef::Node::Attribute.new(@attribute, @default_attrs, @override_attrs).attribute?(attrib)
|
235
236
|
end
|
236
|
-
|
237
|
-
# Yield each key of the top level to the block.
|
237
|
+
|
238
|
+
# Yield each key of the top level to the block.
|
238
239
|
def each(&block)
|
239
240
|
Chef::Node::Attribute.new(@attribute, @default_attrs, @override_attrs).each(&block)
|
240
241
|
end
|
241
|
-
|
242
|
+
|
242
243
|
# Iterates over each attribute, passing the attribute and value to the block.
|
243
244
|
def each_attribute(&block)
|
244
245
|
Chef::Node::Attribute.new(@attribute, @default_attrs, @override_attrs).each_attribute(&block)
|
@@ -250,23 +251,23 @@ class Chef
|
|
250
251
|
def method_missing(symbol, *args)
|
251
252
|
Chef::Node::Attribute.new(@attribute, @default_attrs, @override_attrs).send(symbol, *args)
|
252
253
|
end
|
253
|
-
|
254
|
+
|
254
255
|
# Returns true if this Node expects a given recipe, false if not.
|
255
256
|
def recipe?(recipe_name)
|
256
257
|
@run_list.include?(recipe_name) || @run_state[:seen_recipes].include?(recipe_name)
|
257
258
|
end
|
258
|
-
|
259
|
+
|
259
260
|
# Returns true if this Node expects a given role, false if not.
|
260
261
|
def role?(role_name)
|
261
262
|
@run_list.include?("role[#{role_name}]")
|
262
263
|
end
|
263
264
|
|
264
265
|
# Returns an Array of roles and recipes, in the order they will be applied.
|
265
|
-
# If you call it with arguments, they will become the new list of roles and recipes.
|
266
|
+
# If you call it with arguments, they will become the new list of roles and recipes.
|
266
267
|
def run_list(*args)
|
267
268
|
args.length > 0 ? @run_list.reset!(args) : @run_list
|
268
269
|
end
|
269
|
-
|
270
|
+
|
270
271
|
def recipes(*args)
|
271
272
|
Chef::Log.warn "Chef::Node#recipes method is deprecated. Please use Chef::Node#run_list"
|
272
273
|
run_list(*args)
|
@@ -276,22 +277,22 @@ class Chef
|
|
276
277
|
def run_list?(item)
|
277
278
|
@run_list.detect { |r| r == item } ? true : false
|
278
279
|
end
|
279
|
-
|
280
|
+
|
280
281
|
def consume_attributes(attrs)
|
281
282
|
attrs ||= {}
|
282
283
|
Chef::Log.debug("Adding JSON Attributes")
|
283
|
-
attrs.
|
284
|
-
if
|
285
|
-
run_list
|
286
|
-
else
|
287
|
-
Chef::Log.debug("JSON Attribute: #{key} - #{value.inspect}")
|
288
|
-
store(key, value)
|
284
|
+
if new_run_list = attrs.delete("recipes") || attrs.delete("run_list")
|
285
|
+
if attrs.key?("recipes") || attrs.key?("run_list")
|
286
|
+
raise Chef::Exceptions::AmbiguousRunlistSpecification, "please set the node's run list using the 'run_list' attribute only."
|
289
287
|
end
|
288
|
+
Chef::Log.info("Replacing the run_list with #{new_run_list.inspect} from JSON")
|
289
|
+
run_list(new_run_list)
|
290
290
|
end
|
291
|
+
Chef::Mixin::DeepMerge.merge(@attribute, attrs)
|
292
|
+
|
291
293
|
self[:tags] = Array.new unless attribute?(:tags)
|
292
|
-
|
293
294
|
end
|
294
|
-
|
295
|
+
|
295
296
|
# Transform the node to a Hash
|
296
297
|
def to_hash
|
297
298
|
index_hash = Hash.new
|
@@ -305,8 +306,8 @@ class Chef
|
|
305
306
|
index_hash["run_list"] = @run_list.run_list if @run_list.run_list.length > 0
|
306
307
|
index_hash
|
307
308
|
end
|
308
|
-
|
309
|
-
# Serialize this object as a hash
|
309
|
+
|
310
|
+
# Serialize this object as a hash
|
310
311
|
def to_json(*a)
|
311
312
|
result = {
|
312
313
|
"name" => @name,
|
@@ -320,13 +321,13 @@ class Chef
|
|
320
321
|
result["_rev"] = @couchdb_rev if @couchdb_rev
|
321
322
|
result.to_json(*a)
|
322
323
|
end
|
323
|
-
|
324
|
+
|
324
325
|
# Create a Chef::Node from JSON
|
325
326
|
def self.json_create(o)
|
326
327
|
node = new
|
327
328
|
node.name(o["name"])
|
328
329
|
o["attributes"].each { |k,v| node[k] = v }
|
329
|
-
|
330
|
+
|
330
331
|
node.default_attrs = Mash.new(o["defaults"]) if o.has_key?("defaults")
|
331
332
|
node.override_attrs = Mash.new(o["overrides"]) if o.has_key?("overrides")
|
332
333
|
|
@@ -340,7 +341,7 @@ class Chef
|
|
340
341
|
node.index_id = node.couchdb_id
|
341
342
|
node
|
342
343
|
end
|
343
|
-
|
344
|
+
|
344
345
|
# List all the Chef::Node objects in the CouchDB. If inflate is set to true, you will get
|
345
346
|
# the full list of all Nodes, fully inflated.
|
346
347
|
def self.cdb_list(inflate=false, couchdb=nil)
|
@@ -360,10 +361,10 @@ class Chef
|
|
360
361
|
Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes")
|
361
362
|
end
|
362
363
|
end
|
363
|
-
|
364
|
+
|
364
365
|
# Load a node by name from CouchDB
|
365
366
|
def self.cdb_load(name, couchdb=nil)
|
366
|
-
(couchdb || Chef::CouchDB.new).load("node", name)
|
367
|
+
(couchdb || Chef::CouchDB.new).load("node", name)
|
367
368
|
end
|
368
369
|
|
369
370
|
def self.exists?(nodename, couchdb)
|
@@ -373,12 +374,12 @@ class Chef
|
|
373
374
|
nil
|
374
375
|
end
|
375
376
|
end
|
376
|
-
|
377
|
+
|
377
378
|
# Load a node by name
|
378
379
|
def self.load(name)
|
379
380
|
Chef::REST.new(Chef::Config[:chef_server_url]).get_rest("nodes/#{name}")
|
380
381
|
end
|
381
|
-
|
382
|
+
|
382
383
|
# Remove this node from the CouchDB
|
383
384
|
def cdb_destroy
|
384
385
|
@couchdb.delete("node", @name, @couchdb_rev)
|
@@ -388,7 +389,7 @@ class Chef
|
|
388
389
|
def destroy
|
389
390
|
chef_server_rest.delete_rest("nodes/#{@name}")
|
390
391
|
end
|
391
|
-
|
392
|
+
|
392
393
|
# Save this node to the CouchDB
|
393
394
|
def cdb_save
|
394
395
|
@couchdb_rev = @couchdb.store("node", @name, self)["rev"]
|
@@ -404,18 +405,18 @@ class Chef
|
|
404
405
|
end
|
405
406
|
self
|
406
407
|
end
|
407
|
-
|
408
|
+
|
408
409
|
# Create the node via the REST API
|
409
410
|
def create
|
410
411
|
chef_server_rest.post_rest("nodes", self)
|
411
412
|
self
|
412
|
-
end
|
413
|
+
end
|
413
414
|
|
414
415
|
# Set up our CouchDB design document
|
415
416
|
def self.create_design_document(couchdb=nil)
|
416
417
|
(couchdb || Chef::CouchDB.new).create_design_document("nodes", DESIGN_DOCUMENT)
|
417
418
|
end
|
418
|
-
|
419
|
+
|
419
420
|
# As a string
|
420
421
|
def to_s
|
421
422
|
"node[#{@name}]"
|
data/lib/chef/platform.rb
CHANGED
@@ -19,128 +19,162 @@
|
|
19
19
|
require 'chef/config'
|
20
20
|
require 'chef/log'
|
21
21
|
require 'chef/mixin/params_validate'
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
|
23
|
+
# Actually, this file depends on nearly every provider in chef, but actually
|
24
|
+
# requiring them causes circular requires resulting in uninitialized constant
|
25
|
+
# errors.
|
26
|
+
require 'chef/provider'
|
27
|
+
require 'chef/provider/log'
|
28
|
+
require 'chef/provider/user'
|
29
|
+
require 'chef/provider/group'
|
30
|
+
require 'chef/provider/mount'
|
31
|
+
require 'chef/provider/service'
|
32
|
+
require 'chef/provider/package'
|
33
|
+
|
25
34
|
|
26
35
|
class Chef
|
27
36
|
class Platform
|
28
37
|
|
29
|
-
@platforms = {
|
30
|
-
:mac_os_x => {
|
31
|
-
:default => {
|
32
|
-
:package => Chef::Provider::Package::Macports,
|
33
|
-
:user => Chef::Provider::User::Dscl,
|
34
|
-
:group => Chef::Provider::Group::Dscl
|
35
|
-
}
|
36
|
-
},
|
37
|
-
:freebsd => {
|
38
|
-
:default => {
|
39
|
-
:group => Chef::Provider::Group::Pw,
|
40
|
-
:package => Chef::Provider::Package::Freebsd,
|
41
|
-
:service => Chef::Provider::Service::Freebsd,
|
42
|
-
:user => Chef::Provider::User::Pw,
|
43
|
-
:cron => Chef::Provider::Cron
|
44
|
-
}
|
45
|
-
},
|
46
|
-
:ubuntu => {
|
47
|
-
:default => {
|
48
|
-
:package => Chef::Provider::Package::Apt,
|
49
|
-
:service => Chef::Provider::Service::Debian,
|
50
|
-
:cron => Chef::Provider::Cron,
|
51
|
-
:mdadm => Chef::Provider::Mdadm
|
52
|
-
}
|
53
|
-
},
|
54
|
-
:debian => {
|
55
|
-
:default => {
|
56
|
-
:package => Chef::Provider::Package::Apt,
|
57
|
-
:service => Chef::Provider::Service::Debian,
|
58
|
-
:cron => Chef::Provider::Cron,
|
59
|
-
:mdadm => Chef::Provider::Mdadm
|
60
|
-
}
|
61
|
-
},
|
62
|
-
:centos => {
|
63
|
-
:default => {
|
64
|
-
:service => Chef::Provider::Service::Redhat,
|
65
|
-
:cron => Chef::Provider::Cron,
|
66
|
-
:package => Chef::Provider::Package::Yum,
|
67
|
-
:mdadm => Chef::Provider::Mdadm
|
68
|
-
}
|
69
|
-
},
|
70
|
-
:fedora => {
|
71
|
-
:default => {
|
72
|
-
:service => Chef::Provider::Service::Redhat,
|
73
|
-
:cron => Chef::Provider::Cron,
|
74
|
-
:package => Chef::Provider::Package::Yum,
|
75
|
-
:mdadm => Chef::Provider::Mdadm
|
76
|
-
}
|
77
|
-
},
|
78
|
-
:suse => {
|
79
|
-
:default => {
|
80
|
-
:service => Chef::Provider::Service::Redhat,
|
81
|
-
:cron => Chef::Provider::Cron,
|
82
|
-
:package => Chef::Provider::Package::Zypper
|
83
|
-
}
|
84
|
-
},
|
85
|
-
:redhat => {
|
86
|
-
:default => {
|
87
|
-
:service => Chef::Provider::Service::Redhat,
|
88
|
-
:cron => Chef::Provider::Cron,
|
89
|
-
:package => Chef::Provider::Package::Yum,
|
90
|
-
:mdadm => Chef::Provider::Mdadm
|
91
|
-
}
|
92
|
-
},
|
93
|
-
:gentoo => {
|
94
|
-
:default => {
|
95
|
-
:package => Chef::Provider::Package::Portage,
|
96
|
-
:service => Chef::Provider::Service::Gentoo,
|
97
|
-
:cron => Chef::Provider::Cron,
|
98
|
-
:mdadm => Chef::Provider::Mdadm
|
99
|
-
}
|
100
|
-
},
|
101
|
-
:arch => {
|
102
|
-
:default => {
|
103
|
-
:package => Chef::Provider::Package::Pacman,
|
104
|
-
:service => Chef::Provider::Service::Arch,
|
105
|
-
:cron => Chef::Provider::Cron,
|
106
|
-
:mdadm => Chef::Provider::Mdadm
|
107
|
-
}
|
108
|
-
},
|
109
|
-
:solaris => {},
|
110
|
-
:default => {
|
111
|
-
:file => Chef::Provider::File,
|
112
|
-
:directory => Chef::Provider::Directory,
|
113
|
-
:link => Chef::Provider::Link,
|
114
|
-
:template => Chef::Provider::Template,
|
115
|
-
:remote_file => Chef::Provider::RemoteFile,
|
116
|
-
:remote_directory => Chef::Provider::RemoteDirectory,
|
117
|
-
:execute => Chef::Provider::Execute,
|
118
|
-
:mount => Chef::Provider::Mount::Mount,
|
119
|
-
:script => Chef::Provider::Script,
|
120
|
-
:service => Chef::Provider::Service::Init,
|
121
|
-
:perl => Chef::Provider::Script,
|
122
|
-
:python => Chef::Provider::Script,
|
123
|
-
:ruby => Chef::Provider::Script,
|
124
|
-
:bash => Chef::Provider::Script,
|
125
|
-
:csh => Chef::Provider::Script,
|
126
|
-
:user => Chef::Provider::User::Useradd,
|
127
|
-
:group => Chef::Provider::Group::Gpasswd,
|
128
|
-
:http_request => Chef::Provider::HttpRequest,
|
129
|
-
:route => Chef::Provider::Route,
|
130
|
-
:ifconfig => Chef::Provider::Ifconfig,
|
131
|
-
:ruby_block => Chef::Provider::RubyBlock,
|
132
|
-
:erl_call => Chef::Provider::ErlCall,
|
133
|
-
:log => Chef::Provider::Log::ChefLog
|
134
|
-
}
|
135
|
-
}
|
136
|
-
|
137
38
|
class << self
|
138
|
-
|
39
|
+
attr_writer :platforms
|
40
|
+
|
41
|
+
def platforms
|
42
|
+
@platforms ||= {
|
43
|
+
:mac_os_x => {
|
44
|
+
:default => {
|
45
|
+
:package => Chef::Provider::Package::Macports,
|
46
|
+
:user => Chef::Provider::User::Dscl,
|
47
|
+
:group => Chef::Provider::Group::Dscl
|
48
|
+
}
|
49
|
+
},
|
50
|
+
:freebsd => {
|
51
|
+
:default => {
|
52
|
+
:group => Chef::Provider::Group::Pw,
|
53
|
+
:package => Chef::Provider::Package::Freebsd,
|
54
|
+
:service => Chef::Provider::Service::Freebsd,
|
55
|
+
:user => Chef::Provider::User::Pw,
|
56
|
+
:cron => Chef::Provider::Cron
|
57
|
+
}
|
58
|
+
},
|
59
|
+
:ubuntu => {
|
60
|
+
:default => {
|
61
|
+
:package => Chef::Provider::Package::Apt,
|
62
|
+
:service => Chef::Provider::Service::Debian,
|
63
|
+
:cron => Chef::Provider::Cron,
|
64
|
+
:mdadm => Chef::Provider::Mdadm
|
65
|
+
}
|
66
|
+
},
|
67
|
+
:debian => {
|
68
|
+
:default => {
|
69
|
+
:package => Chef::Provider::Package::Apt,
|
70
|
+
:service => Chef::Provider::Service::Debian,
|
71
|
+
:cron => Chef::Provider::Cron,
|
72
|
+
:mdadm => Chef::Provider::Mdadm
|
73
|
+
}
|
74
|
+
},
|
75
|
+
:centos => {
|
76
|
+
:default => {
|
77
|
+
:service => Chef::Provider::Service::Redhat,
|
78
|
+
:cron => Chef::Provider::Cron,
|
79
|
+
:package => Chef::Provider::Package::Yum,
|
80
|
+
:mdadm => Chef::Provider::Mdadm
|
81
|
+
}
|
82
|
+
},
|
83
|
+
:scientific => {
|
84
|
+
:default => {
|
85
|
+
:service => Chef::Provider::Service::Redhat,
|
86
|
+
:cron => Chef::Provider::Cron,
|
87
|
+
:package => Chef::Provider::Package::Yum,
|
88
|
+
:mdadm => Chef::Provider::Mdadm
|
89
|
+
}
|
90
|
+
},
|
91
|
+
:fedora => {
|
92
|
+
:default => {
|
93
|
+
:service => Chef::Provider::Service::Redhat,
|
94
|
+
:cron => Chef::Provider::Cron,
|
95
|
+
:package => Chef::Provider::Package::Yum,
|
96
|
+
:mdadm => Chef::Provider::Mdadm
|
97
|
+
}
|
98
|
+
},
|
99
|
+
:suse => {
|
100
|
+
:default => {
|
101
|
+
:service => Chef::Provider::Service::Redhat,
|
102
|
+
:cron => Chef::Provider::Cron,
|
103
|
+
:package => Chef::Provider::Package::Zypper
|
104
|
+
}
|
105
|
+
},
|
106
|
+
:redhat => {
|
107
|
+
:default => {
|
108
|
+
:service => Chef::Provider::Service::Redhat,
|
109
|
+
:cron => Chef::Provider::Cron,
|
110
|
+
:package => Chef::Provider::Package::Yum,
|
111
|
+
:mdadm => Chef::Provider::Mdadm
|
112
|
+
}
|
113
|
+
},
|
114
|
+
:gentoo => {
|
115
|
+
:default => {
|
116
|
+
:package => Chef::Provider::Package::Portage,
|
117
|
+
:service => Chef::Provider::Service::Gentoo,
|
118
|
+
:cron => Chef::Provider::Cron,
|
119
|
+
:mdadm => Chef::Provider::Mdadm
|
120
|
+
}
|
121
|
+
},
|
122
|
+
:arch => {
|
123
|
+
:default => {
|
124
|
+
:package => Chef::Provider::Package::Pacman,
|
125
|
+
:service => Chef::Provider::Service::Arch,
|
126
|
+
:cron => Chef::Provider::Cron,
|
127
|
+
:mdadm => Chef::Provider::Mdadm
|
128
|
+
}
|
129
|
+
},
|
130
|
+
:mswin => {
|
131
|
+
:default => {
|
132
|
+
:service => Chef::Provider::Service::Windows
|
133
|
+
}
|
134
|
+
},
|
135
|
+
:mingw32 => {
|
136
|
+
:default => {
|
137
|
+
:service => Chef::Provider::Service::Windows
|
138
|
+
}
|
139
|
+
},
|
140
|
+
:windows => {
|
141
|
+
:default => {
|
142
|
+
:service => Chef::Provider::Service::Windows
|
143
|
+
}
|
144
|
+
},
|
145
|
+
:solaris => {},
|
146
|
+
:default => {
|
147
|
+
:file => Chef::Provider::File,
|
148
|
+
:directory => Chef::Provider::Directory,
|
149
|
+
:link => Chef::Provider::Link,
|
150
|
+
:template => Chef::Provider::Template,
|
151
|
+
:remote_file => Chef::Provider::RemoteFile,
|
152
|
+
:remote_directory => Chef::Provider::RemoteDirectory,
|
153
|
+
:execute => Chef::Provider::Execute,
|
154
|
+
:mount => Chef::Provider::Mount::Mount,
|
155
|
+
:script => Chef::Provider::Script,
|
156
|
+
:service => Chef::Provider::Service::Init,
|
157
|
+
:perl => Chef::Provider::Script,
|
158
|
+
:python => Chef::Provider::Script,
|
159
|
+
:ruby => Chef::Provider::Script,
|
160
|
+
:bash => Chef::Provider::Script,
|
161
|
+
:csh => Chef::Provider::Script,
|
162
|
+
:user => Chef::Provider::User::Useradd,
|
163
|
+
:group => Chef::Provider::Group::Gpasswd,
|
164
|
+
:http_request => Chef::Provider::HttpRequest,
|
165
|
+
:route => Chef::Provider::Route,
|
166
|
+
:ifconfig => Chef::Provider::Ifconfig,
|
167
|
+
:ruby_block => Chef::Provider::RubyBlock,
|
168
|
+
:erl_call => Chef::Provider::ErlCall,
|
169
|
+
:log => Chef::Provider::Log::ChefLog
|
170
|
+
}
|
171
|
+
}
|
172
|
+
end
|
139
173
|
|
140
174
|
include Chef::Mixin::ParamsValidate
|
141
175
|
|
142
176
|
def find(name, version)
|
143
|
-
provider_map =
|
177
|
+
provider_map = platforms[:default].clone
|
144
178
|
|
145
179
|
name_sym = name
|
146
180
|
if name.kind_of?(String)
|
@@ -149,15 +183,15 @@ class Chef
|
|
149
183
|
name_sym = name.to_sym
|
150
184
|
end
|
151
185
|
|
152
|
-
if
|
153
|
-
if
|
186
|
+
if platforms.has_key?(name_sym)
|
187
|
+
if platforms[name_sym].has_key?(version)
|
154
188
|
Chef::Log.debug("Platform #{name.to_s} version #{version} found")
|
155
|
-
if
|
156
|
-
provider_map.merge!(
|
189
|
+
if platforms[name_sym].has_key?(:default)
|
190
|
+
provider_map.merge!(platforms[name_sym][:default])
|
157
191
|
end
|
158
|
-
provider_map.merge!(
|
159
|
-
elsif
|
160
|
-
provider_map.merge!(
|
192
|
+
provider_map.merge!(platforms[name_sym][version])
|
193
|
+
elsif platforms[name_sym].has_key?(:default)
|
194
|
+
provider_map.merge!(platforms[name_sym][:default])
|
161
195
|
end
|
162
196
|
else
|
163
197
|
Chef::Log.debug("Platform #{name} not found, using all defaults. (Unsupported platform?)")
|
@@ -221,30 +255,30 @@ class Chef
|
|
221
255
|
)
|
222
256
|
if args.has_key?(:platform)
|
223
257
|
if args.has_key?(:version)
|
224
|
-
if
|
225
|
-
if
|
226
|
-
|
258
|
+
if platforms.has_key?(args[:platform])
|
259
|
+
if platforms[args[:platform]].has_key?(args[:version])
|
260
|
+
platforms[args[:platform]][args[:version]][args[:resource].to_sym] = args[:provider]
|
227
261
|
else
|
228
|
-
|
262
|
+
platforms[args[:platform]][args[:version]] = {
|
229
263
|
args[:resource].to_sym => args[:provider]
|
230
264
|
}
|
231
265
|
end
|
232
266
|
else
|
233
|
-
|
267
|
+
platforms[args[:platform]] = {
|
234
268
|
args[:version] => {
|
235
269
|
args[:resource].to_sym => args[:provider]
|
236
270
|
}
|
237
271
|
}
|
238
272
|
end
|
239
273
|
else
|
240
|
-
if
|
241
|
-
if
|
242
|
-
|
274
|
+
if platforms.has_key?(args[:platform])
|
275
|
+
if platforms[args[:platform]].has_key?(:default)
|
276
|
+
platforms[args[:platform]][:default][args[:resource].to_sym] = args[:provider]
|
243
277
|
else
|
244
|
-
|
278
|
+
platforms[args[:platform]] = { :default => { args[:resource].to_sym => args[:provider] } }
|
245
279
|
end
|
246
280
|
else
|
247
|
-
|
281
|
+
platforms[args[:platform]] = {
|
248
282
|
:default => {
|
249
283
|
args[:resource].to_sym => args[:provider]
|
250
284
|
}
|
@@ -252,10 +286,10 @@ class Chef
|
|
252
286
|
end
|
253
287
|
end
|
254
288
|
else
|
255
|
-
if
|
256
|
-
|
289
|
+
if platforms.has_key?(:default)
|
290
|
+
platforms[:default][args[:resource].to_sym] = args[:provider]
|
257
291
|
else
|
258
|
-
|
292
|
+
platforms[:default] = {
|
259
293
|
args[:resource].to_sym => args[:provider]
|
260
294
|
}
|
261
295
|
end
|
@@ -264,8 +298,8 @@ class Chef
|
|
264
298
|
|
265
299
|
def find_provider(platform, version, resource_type)
|
266
300
|
pmap = Chef::Platform.find(platform, version)
|
267
|
-
provider_klass = explicit_provider(platform, version, resource_type) ||
|
268
|
-
platform_provider(platform, version, resource_type) ||
|
301
|
+
provider_klass = explicit_provider(platform, version, resource_type) ||
|
302
|
+
platform_provider(platform, version, resource_type) ||
|
269
303
|
resource_matching_provider(platform, version, resource_type)
|
270
304
|
|
271
305
|
raise ArgumentError, "Cannot find a provider for #{resource_type} on #{platform} version #{version}" if provider_klass.nil?
|
@@ -288,8 +322,8 @@ class Chef
|
|
288
322
|
def resource_matching_provider(platform, version, resource_type)
|
289
323
|
if resource_type.kind_of?(Chef::Resource)
|
290
324
|
begin
|
291
|
-
Chef::Provider.const_get(resource_type.class.to_s.split('::').last)
|
292
|
-
rescue NameError
|
325
|
+
Chef::Provider.const_get(resource_type.class.to_s.split('::').last)
|
326
|
+
rescue NameError
|
293
327
|
nil
|
294
328
|
end
|
295
329
|
else
|