chef-provisioning 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +906 -899
- data/Gemfile +17 -17
- data/LICENSE +201 -201
- data/README.md +312 -312
- data/Rakefile +55 -55
- data/chef-provisioning.gemspec +38 -38
- data/lib/chef/provider/load_balancer.rb +75 -75
- data/lib/chef/provider/machine.rb +219 -219
- data/lib/chef/provider/machine_batch.rb +224 -224
- data/lib/chef/provider/machine_execute.rb +36 -36
- data/lib/chef/provider/machine_file.rb +55 -55
- data/lib/chef/provider/machine_image.rb +105 -105
- data/lib/chef/provisioning.rb +110 -110
- data/lib/chef/provisioning/action_handler.rb +68 -68
- data/lib/chef/provisioning/add_prefix_action_handler.rb +35 -35
- data/lib/chef/provisioning/chef_managed_entry_store.rb +128 -128
- data/lib/chef/provisioning/chef_provider_action_handler.rb +74 -74
- data/lib/chef/provisioning/chef_run_data.rb +132 -132
- data/lib/chef/provisioning/convergence_strategy.rb +28 -28
- data/lib/chef/provisioning/convergence_strategy/ignore_convergence_failure.rb +54 -54
- data/lib/chef/provisioning/convergence_strategy/install_cached.rb +188 -188
- data/lib/chef/provisioning/convergence_strategy/install_msi.rb +71 -71
- data/lib/chef/provisioning/convergence_strategy/install_sh.rb +71 -71
- data/lib/chef/provisioning/convergence_strategy/no_converge.rb +35 -35
- data/lib/chef/provisioning/convergence_strategy/precreate_chef_objects.rb +255 -255
- data/lib/chef/provisioning/driver.rb +323 -323
- data/lib/chef/provisioning/load_balancer_spec.rb +14 -14
- data/lib/chef/provisioning/machine.rb +112 -112
- data/lib/chef/provisioning/machine/basic_machine.rb +84 -84
- data/lib/chef/provisioning/machine/unix_machine.rb +288 -288
- data/lib/chef/provisioning/machine/windows_machine.rb +108 -108
- data/lib/chef/provisioning/machine_image_spec.rb +34 -34
- data/lib/chef/provisioning/machine_spec.rb +58 -58
- data/lib/chef/provisioning/managed_entry.rb +121 -121
- data/lib/chef/provisioning/managed_entry_store.rb +136 -136
- data/lib/chef/provisioning/recipe_dsl.rb +99 -99
- data/lib/chef/provisioning/rspec.rb +27 -27
- data/lib/chef/provisioning/transport.rb +100 -100
- data/lib/chef/provisioning/transport/ssh.rb +403 -403
- data/lib/chef/provisioning/transport/winrm.rb +144 -144
- data/lib/chef/provisioning/version.rb +5 -5
- data/lib/chef/resource/chef_data_bag_resource.rb +146 -146
- data/lib/chef/resource/load_balancer.rb +57 -57
- data/lib/chef/resource/machine.rb +128 -128
- data/lib/chef/resource/machine_batch.rb +78 -78
- data/lib/chef/resource/machine_execute.rb +30 -30
- data/lib/chef/resource/machine_file.rb +34 -34
- data/lib/chef/resource/machine_image.rb +35 -35
- data/lib/chef_metal.rb +1 -1
- data/spec/chef/provisioning/convergence_strategy/ignore_convergence_failure_spec.rb +86 -86
- data/spec/spec_helper.rb +27 -27
- metadata +10 -4
@@ -1,55 +1,55 @@
|
|
1
|
-
require 'chef/provider/lwrp_base'
|
2
|
-
require 'chef/provisioning/chef_provider_action_handler'
|
3
|
-
require 'chef/provisioning/machine'
|
4
|
-
|
5
|
-
class Chef
|
6
|
-
class Provider
|
7
|
-
class MachineFile < Chef::Provider::LWRPBase
|
8
|
-
provides :machine_file
|
9
|
-
|
10
|
-
def action_handler
|
11
|
-
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
|
12
|
-
end
|
13
|
-
|
14
|
-
use_inline_resources
|
15
|
-
|
16
|
-
def whyrun_supported?
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
def machine
|
21
|
-
@machine ||= begin
|
22
|
-
if new_resource.machine.kind_of?(Chef::Provisioning::Machine)
|
23
|
-
new_resource.machine
|
24
|
-
else
|
25
|
-
run_context.chef_provisioning.connect_to_machine(new_resource.machine, new_resource.chef_server)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
action :upload do
|
31
|
-
if new_resource.content
|
32
|
-
machine.write_file(action_handler, new_resource.path, new_resource.content)
|
33
|
-
else
|
34
|
-
machine.upload_file(action_handler, new_resource.local_path, new_resource.path)
|
35
|
-
end
|
36
|
-
|
37
|
-
attributes = {}
|
38
|
-
attributes[:group] = new_resource.group if new_resource.group
|
39
|
-
attributes[:owner] = new_resource.owner if new_resource.owner
|
40
|
-
attributes[:mode] = new_resource.mode if new_resource.mode
|
41
|
-
|
42
|
-
machine.set_attributes(action_handler, new_resource.path, attributes)
|
43
|
-
end
|
44
|
-
|
45
|
-
action :download do
|
46
|
-
machine.download_file(action_handler, new_resource.path, new_resource.local_path)
|
47
|
-
end
|
48
|
-
|
49
|
-
action :delete do
|
50
|
-
machine.delete_file(action_handler, new_resource.path)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
require 'chef/provider/lwrp_base'
|
2
|
+
require 'chef/provisioning/chef_provider_action_handler'
|
3
|
+
require 'chef/provisioning/machine'
|
4
|
+
|
5
|
+
class Chef
|
6
|
+
class Provider
|
7
|
+
class MachineFile < Chef::Provider::LWRPBase
|
8
|
+
provides :machine_file
|
9
|
+
|
10
|
+
def action_handler
|
11
|
+
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
use_inline_resources
|
15
|
+
|
16
|
+
def whyrun_supported?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def machine
|
21
|
+
@machine ||= begin
|
22
|
+
if new_resource.machine.kind_of?(Chef::Provisioning::Machine)
|
23
|
+
new_resource.machine
|
24
|
+
else
|
25
|
+
run_context.chef_provisioning.connect_to_machine(new_resource.machine, new_resource.chef_server)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
action :upload do
|
31
|
+
if new_resource.content
|
32
|
+
machine.write_file(action_handler, new_resource.path, new_resource.content)
|
33
|
+
else
|
34
|
+
machine.upload_file(action_handler, new_resource.local_path, new_resource.path)
|
35
|
+
end
|
36
|
+
|
37
|
+
attributes = {}
|
38
|
+
attributes[:group] = new_resource.group if new_resource.group
|
39
|
+
attributes[:owner] = new_resource.owner if new_resource.owner
|
40
|
+
attributes[:mode] = new_resource.mode if new_resource.mode
|
41
|
+
|
42
|
+
machine.set_attributes(action_handler, new_resource.path, attributes)
|
43
|
+
end
|
44
|
+
|
45
|
+
action :download do
|
46
|
+
machine.download_file(action_handler, new_resource.path, new_resource.local_path)
|
47
|
+
end
|
48
|
+
|
49
|
+
action :delete do
|
50
|
+
machine.delete_file(action_handler, new_resource.path)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,105 +1,105 @@
|
|
1
|
-
require 'chef/provider/lwrp_base'
|
2
|
-
require 'openssl'
|
3
|
-
require 'chef/provisioning/chef_provider_action_handler'
|
4
|
-
|
5
|
-
class Chef
|
6
|
-
class Provider
|
7
|
-
class MachineImage < Chef::Provider::LWRPBase
|
8
|
-
provides :machine_image
|
9
|
-
|
10
|
-
def action_handler
|
11
|
-
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
|
12
|
-
end
|
13
|
-
|
14
|
-
def load_current_resource
|
15
|
-
end
|
16
|
-
|
17
|
-
# Get the driver specified in the resource
|
18
|
-
def new_driver
|
19
|
-
@new_driver ||= run_context.chef_provisioning.driver_for(new_resource.driver)
|
20
|
-
end
|
21
|
-
|
22
|
-
def chef_managed_entry_store
|
23
|
-
@chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
|
24
|
-
end
|
25
|
-
|
26
|
-
action :create do
|
27
|
-
# Get the image mapping on the server (from name to image-id)
|
28
|
-
image_spec = chef_managed_entry_store.get_or_new(:machine_image, new_resource.name)
|
29
|
-
if image_spec.reference
|
30
|
-
# TODO check for real existence and maybe update
|
31
|
-
new_driver.ready_image(action_handler, image_spec, new_image_options)
|
32
|
-
else
|
33
|
-
#
|
34
|
-
# Create a new image
|
35
|
-
#
|
36
|
-
create_image(image_spec, new_resource.machine_options || {})
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
action :destroy do
|
41
|
-
# Destroy the exemplar machine if it exists
|
42
|
-
machine_provider = Chef::Provider::Machine.new(new_resource, run_context)
|
43
|
-
machine_provider.action_handler = action_handler
|
44
|
-
machine_provider.load_current_resource
|
45
|
-
machine_provider.action_destroy
|
46
|
-
|
47
|
-
# Get the image mapping on the server (from name to image-id)
|
48
|
-
image_spec = chef_managed_entry_store.get(:machine_image, new_resource.name)
|
49
|
-
|
50
|
-
if image_spec && image_spec.reference
|
51
|
-
new_driver.destroy_image(action_handler, image_spec, new_resource.image_options)
|
52
|
-
image_spec.delete(action_handler)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def create_image(image_spec, machine_options)
|
57
|
-
# 1. Create the exemplar machine
|
58
|
-
machine_provider = Chef::Provider::Machine.new(new_resource, run_context)
|
59
|
-
machine_provider.action_handler = action_handler
|
60
|
-
machine_provider.load_current_resource
|
61
|
-
machine_provider.action_converge
|
62
|
-
|
63
|
-
# 2. Create the image
|
64
|
-
machine_options = new_machine_options
|
65
|
-
new_driver.allocate_image(action_handler, image_spec, new_image_options,
|
66
|
-
machine_provider.machine_spec, machine_options)
|
67
|
-
image_spec.driver_url ||= new_driver.driver_url
|
68
|
-
image_spec.from_image ||= new_resource.from_image if new_resource.from_image
|
69
|
-
image_spec.run_list ||= machine_provider.machine_spec.node['run_list']
|
70
|
-
|
71
|
-
# 3. Save the linkage from name -> image id
|
72
|
-
image_spec.save(action_handler)
|
73
|
-
|
74
|
-
# 4. Wait for image to be ready
|
75
|
-
new_driver.ready_image(action_handler, image_spec, new_image_options)
|
76
|
-
|
77
|
-
machine_provider.action_destroy
|
78
|
-
end
|
79
|
-
|
80
|
-
def new_image_options
|
81
|
-
@new_image_options ||= begin
|
82
|
-
configs = []
|
83
|
-
configs << new_resource.image_options if new_resource.image_options
|
84
|
-
# See documentation in machine.rb provider
|
85
|
-
(self.class.additional_image_option_keys || []).each do |k|
|
86
|
-
configs << { k => new_resource.send(k)} if new_resource.send(k)
|
87
|
-
end
|
88
|
-
Cheffish::MergedConfig.new(*configs)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def new_machine_options
|
93
|
-
@new_machine_options ||= new_resource.machine_options
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.additional_image_option_keys
|
97
|
-
@@additional_image_option_keys ||= []
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
require 'chef/provisioning/chef_managed_entry_store'
|
105
|
-
Chef::Provisioning::ChefManagedEntryStore.type_names_for_backcompat[:machine_image] = "images"
|
1
|
+
require 'chef/provider/lwrp_base'
|
2
|
+
require 'openssl'
|
3
|
+
require 'chef/provisioning/chef_provider_action_handler'
|
4
|
+
|
5
|
+
class Chef
|
6
|
+
class Provider
|
7
|
+
class MachineImage < Chef::Provider::LWRPBase
|
8
|
+
provides :machine_image
|
9
|
+
|
10
|
+
def action_handler
|
11
|
+
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_current_resource
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get the driver specified in the resource
|
18
|
+
def new_driver
|
19
|
+
@new_driver ||= run_context.chef_provisioning.driver_for(new_resource.driver)
|
20
|
+
end
|
21
|
+
|
22
|
+
def chef_managed_entry_store
|
23
|
+
@chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
|
24
|
+
end
|
25
|
+
|
26
|
+
action :create do
|
27
|
+
# Get the image mapping on the server (from name to image-id)
|
28
|
+
image_spec = chef_managed_entry_store.get_or_new(:machine_image, new_resource.name)
|
29
|
+
if image_spec.reference
|
30
|
+
# TODO check for real existence and maybe update
|
31
|
+
new_driver.ready_image(action_handler, image_spec, new_image_options)
|
32
|
+
else
|
33
|
+
#
|
34
|
+
# Create a new image
|
35
|
+
#
|
36
|
+
create_image(image_spec, new_resource.machine_options || {})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
action :destroy do
|
41
|
+
# Destroy the exemplar machine if it exists
|
42
|
+
machine_provider = Chef::Provider::Machine.new(new_resource, run_context)
|
43
|
+
machine_provider.action_handler = action_handler
|
44
|
+
machine_provider.load_current_resource
|
45
|
+
machine_provider.action_destroy
|
46
|
+
|
47
|
+
# Get the image mapping on the server (from name to image-id)
|
48
|
+
image_spec = chef_managed_entry_store.get(:machine_image, new_resource.name)
|
49
|
+
|
50
|
+
if image_spec && image_spec.reference
|
51
|
+
new_driver.destroy_image(action_handler, image_spec, new_resource.image_options)
|
52
|
+
image_spec.delete(action_handler)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_image(image_spec, machine_options)
|
57
|
+
# 1. Create the exemplar machine
|
58
|
+
machine_provider = Chef::Provider::Machine.new(new_resource, run_context)
|
59
|
+
machine_provider.action_handler = action_handler
|
60
|
+
machine_provider.load_current_resource
|
61
|
+
machine_provider.action_converge
|
62
|
+
|
63
|
+
# 2. Create the image
|
64
|
+
machine_options = new_machine_options
|
65
|
+
new_driver.allocate_image(action_handler, image_spec, new_image_options,
|
66
|
+
machine_provider.machine_spec, machine_options)
|
67
|
+
image_spec.driver_url ||= new_driver.driver_url
|
68
|
+
image_spec.from_image ||= new_resource.from_image if new_resource.from_image
|
69
|
+
image_spec.run_list ||= machine_provider.machine_spec.node['run_list']
|
70
|
+
|
71
|
+
# 3. Save the linkage from name -> image id
|
72
|
+
image_spec.save(action_handler)
|
73
|
+
|
74
|
+
# 4. Wait for image to be ready
|
75
|
+
new_driver.ready_image(action_handler, image_spec, new_image_options)
|
76
|
+
|
77
|
+
machine_provider.action_destroy
|
78
|
+
end
|
79
|
+
|
80
|
+
def new_image_options
|
81
|
+
@new_image_options ||= begin
|
82
|
+
configs = []
|
83
|
+
configs << new_resource.image_options if new_resource.image_options
|
84
|
+
# See documentation in machine.rb provider
|
85
|
+
(self.class.additional_image_option_keys || []).each do |k|
|
86
|
+
configs << { k => new_resource.send(k)} if new_resource.send(k)
|
87
|
+
end
|
88
|
+
Cheffish::MergedConfig.new(*configs)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def new_machine_options
|
93
|
+
@new_machine_options ||= new_resource.machine_options
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.additional_image_option_keys
|
97
|
+
@@additional_image_option_keys ||= []
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
require 'chef/provisioning/chef_managed_entry_store'
|
105
|
+
Chef::Provisioning::ChefManagedEntryStore.type_names_for_backcompat[:machine_image] = "images"
|
data/lib/chef/provisioning.rb
CHANGED
@@ -1,110 +1,110 @@
|
|
1
|
-
# Include recipe basics so require 'chef/provisioning' will load everything
|
2
|
-
require 'chef/provisioning/recipe_dsl'
|
3
|
-
require 'chef/server_api'
|
4
|
-
require 'cheffish/basic_chef_client'
|
5
|
-
require 'cheffish/merged_config'
|
6
|
-
require 'chef/provisioning/chef_managed_entry_store'
|
7
|
-
|
8
|
-
class Chef
|
9
|
-
module Provisioning
|
10
|
-
def self.inline_resource(action_handler, &block)
|
11
|
-
events = ActionHandlerForward.new(action_handler)
|
12
|
-
Cheffish::BasicChefClient.converge_block(nil, events, &block)
|
13
|
-
end
|
14
|
-
|
15
|
-
class ActionHandlerForward < Chef::EventDispatch::Base
|
16
|
-
def initialize(action_handler)
|
17
|
-
@action_handler = action_handler
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :action_handler
|
21
|
-
|
22
|
-
def resource_update_applied(resource, action, update)
|
23
|
-
prefix = action_handler.should_perform_actions ? "" : "Would "
|
24
|
-
update = Array(update).flatten.map { |u| "#{prefix}#{u}"}
|
25
|
-
action_handler.performed_action(update)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Helpers for driver inflation
|
30
|
-
@@registered_driver_classes = {}
|
31
|
-
def self.register_driver_class(name, driver)
|
32
|
-
@@registered_driver_classes[name] = driver
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.default_driver(config = Cheffish.profiled_config)
|
36
|
-
driver_for_url(config[:driver], config)
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.driver_for_url(driver_url, config = Cheffish.profiled_config, allow_different_config = false)
|
40
|
-
#
|
41
|
-
# Create and cache the driver
|
42
|
-
#
|
43
|
-
#
|
44
|
-
# Figure out the driver class
|
45
|
-
#
|
46
|
-
scheme = driver_url.split(':', 2)[0]
|
47
|
-
begin
|
48
|
-
require "chef/provisioning/driver_init/#{scheme}"
|
49
|
-
rescue LoadError
|
50
|
-
begin
|
51
|
-
require "chef_metal/driver_init/#{scheme}"
|
52
|
-
rescue LoadError
|
53
|
-
# try the doomed require again so the stack trace shows the first LoadError and not the second (which
|
54
|
-
# would throw a confusing "chef_metal" into the error output of what is now chef-provisioning). one
|
55
|
-
# could also experiment with saving the first LoadError and re-raising it.
|
56
|
-
require "chef/provisioning/driver_init/#{scheme}"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
driver_class = @@registered_driver_classes[scheme]
|
60
|
-
if !driver_class
|
61
|
-
raise "chef/provisioning/driver_init/#{scheme} did not register a driver class for #{scheme.inspect}! Perhaps you have the case (uppercase or lowercase) wrong?"
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Merge in any driver-specific config
|
66
|
-
#
|
67
|
-
if config[:drivers] && config[:drivers][driver_url]
|
68
|
-
config = Cheffish::MergedConfig.new(config[:drivers][driver_url], config)
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Canonicalize the URL
|
73
|
-
#
|
74
|
-
canonicalized_url, canonicalized_config = driver_class.canonicalize_url(driver_url, config)
|
75
|
-
config = canonicalized_config if canonicalized_config
|
76
|
-
|
77
|
-
#
|
78
|
-
# Merge in config from the canonicalized URL if it is different
|
79
|
-
#
|
80
|
-
if canonicalized_url != driver_url
|
81
|
-
if config[:drivers] && config[:drivers][canonicalized_url]
|
82
|
-
config = Cheffish::MergedConfig.new(config[:drivers][canonicalized_url], config)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
driver_class.from_url(canonicalized_url, config)
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.connect_to_machine(machine_spec, config = Cheffish.profiled_config)
|
90
|
-
chef_server = Cheffish.default_chef_server(config)
|
91
|
-
if machine_spec.is_a?(String)
|
92
|
-
machine_spec = chef_managed_entry_store(chef_server).get(:machine, machine_spec)
|
93
|
-
end
|
94
|
-
driver = driver_for_url(machine_spec.driver_url, config)
|
95
|
-
if driver
|
96
|
-
machine_options = { :convergence_options => { :chef_server => chef_server } }
|
97
|
-
machine_options = Cheffish::MergedConfig.new(config[:machine_options], machine_options) if config[:machine_options]
|
98
|
-
driver.connect_to_machine(machine_spec, machine_options)
|
99
|
-
else
|
100
|
-
nil
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def self.chef_managed_entry_store(chef_server = Cheffish.default_chef_server)
|
105
|
-
Provisioning::ChefManagedEntryStore.new(chef_server)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
ChefMetal = Chef::Provisioning
|
1
|
+
# Include recipe basics so require 'chef/provisioning' will load everything
|
2
|
+
require 'chef/provisioning/recipe_dsl'
|
3
|
+
require 'chef/server_api'
|
4
|
+
require 'cheffish/basic_chef_client'
|
5
|
+
require 'cheffish/merged_config'
|
6
|
+
require 'chef/provisioning/chef_managed_entry_store'
|
7
|
+
|
8
|
+
class Chef
|
9
|
+
module Provisioning
|
10
|
+
def self.inline_resource(action_handler, &block)
|
11
|
+
events = ActionHandlerForward.new(action_handler)
|
12
|
+
Cheffish::BasicChefClient.converge_block(nil, events, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
class ActionHandlerForward < Chef::EventDispatch::Base
|
16
|
+
def initialize(action_handler)
|
17
|
+
@action_handler = action_handler
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :action_handler
|
21
|
+
|
22
|
+
def resource_update_applied(resource, action, update)
|
23
|
+
prefix = action_handler.should_perform_actions ? "" : "Would "
|
24
|
+
update = Array(update).flatten.map { |u| "#{prefix}#{u}"}
|
25
|
+
action_handler.performed_action(update)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Helpers for driver inflation
|
30
|
+
@@registered_driver_classes = {}
|
31
|
+
def self.register_driver_class(name, driver)
|
32
|
+
@@registered_driver_classes[name] = driver
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.default_driver(config = Cheffish.profiled_config)
|
36
|
+
driver_for_url(config[:driver], config)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.driver_for_url(driver_url, config = Cheffish.profiled_config, allow_different_config = false)
|
40
|
+
#
|
41
|
+
# Create and cache the driver
|
42
|
+
#
|
43
|
+
#
|
44
|
+
# Figure out the driver class
|
45
|
+
#
|
46
|
+
scheme = driver_url.split(':', 2)[0]
|
47
|
+
begin
|
48
|
+
require "chef/provisioning/driver_init/#{scheme}"
|
49
|
+
rescue LoadError
|
50
|
+
begin
|
51
|
+
require "chef_metal/driver_init/#{scheme}"
|
52
|
+
rescue LoadError
|
53
|
+
# try the doomed require again so the stack trace shows the first LoadError and not the second (which
|
54
|
+
# would throw a confusing "chef_metal" into the error output of what is now chef-provisioning). one
|
55
|
+
# could also experiment with saving the first LoadError and re-raising it.
|
56
|
+
require "chef/provisioning/driver_init/#{scheme}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
driver_class = @@registered_driver_classes[scheme]
|
60
|
+
if !driver_class
|
61
|
+
raise "chef/provisioning/driver_init/#{scheme} did not register a driver class for #{scheme.inspect}! Perhaps you have the case (uppercase or lowercase) wrong?"
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Merge in any driver-specific config
|
66
|
+
#
|
67
|
+
if config[:drivers] && config[:drivers][driver_url]
|
68
|
+
config = Cheffish::MergedConfig.new(config[:drivers][driver_url], config)
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Canonicalize the URL
|
73
|
+
#
|
74
|
+
canonicalized_url, canonicalized_config = driver_class.canonicalize_url(driver_url, config)
|
75
|
+
config = canonicalized_config if canonicalized_config
|
76
|
+
|
77
|
+
#
|
78
|
+
# Merge in config from the canonicalized URL if it is different
|
79
|
+
#
|
80
|
+
if canonicalized_url != driver_url
|
81
|
+
if config[:drivers] && config[:drivers][canonicalized_url]
|
82
|
+
config = Cheffish::MergedConfig.new(config[:drivers][canonicalized_url], config)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
driver_class.from_url(canonicalized_url, config)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.connect_to_machine(machine_spec, config = Cheffish.profiled_config)
|
90
|
+
chef_server = Cheffish.default_chef_server(config)
|
91
|
+
if machine_spec.is_a?(String)
|
92
|
+
machine_spec = chef_managed_entry_store(chef_server).get(:machine, machine_spec)
|
93
|
+
end
|
94
|
+
driver = driver_for_url(machine_spec.driver_url, config)
|
95
|
+
if driver
|
96
|
+
machine_options = { :convergence_options => { :chef_server => chef_server } }
|
97
|
+
machine_options = Cheffish::MergedConfig.new(config[:machine_options], machine_options) if config[:machine_options]
|
98
|
+
driver.connect_to_machine(machine_spec, machine_options)
|
99
|
+
else
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.chef_managed_entry_store(chef_server = Cheffish.default_chef_server)
|
105
|
+
Provisioning::ChefManagedEntryStore.new(chef_server)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
ChefMetal = Chef::Provisioning
|