chef-provisioning 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +899 -885
- 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 -35
- 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 -156
- 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 -29
- 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 +5 -5
@@ -1,224 +1,224 @@
|
|
1
|
-
require 'chef/chef_fs/parallelizer'
|
2
|
-
require 'chef/provider/lwrp_base'
|
3
|
-
require 'chef/provider/machine'
|
4
|
-
require 'chef/provisioning/chef_provider_action_handler'
|
5
|
-
require 'chef/provisioning/add_prefix_action_handler'
|
6
|
-
require 'chef/provisioning/machine_spec'
|
7
|
-
|
8
|
-
class Chef
|
9
|
-
class Provider
|
10
|
-
class MachineBatch < Chef::Provider::LWRPBase
|
11
|
-
provides :machine_batch
|
12
|
-
|
13
|
-
def action_handler
|
14
|
-
@action_handler ||= Provisioning::ChefProviderActionHandler.new(self)
|
15
|
-
end
|
16
|
-
|
17
|
-
use_inline_resources
|
18
|
-
|
19
|
-
def whyrun_supported?
|
20
|
-
true
|
21
|
-
end
|
22
|
-
|
23
|
-
def parallelizer
|
24
|
-
@parallelizer ||= Chef::ChefFS::Parallelizer.new(new_resource.max_simultaneous || 100)
|
25
|
-
end
|
26
|
-
|
27
|
-
action :allocate do
|
28
|
-
by_new_driver.each do |driver, specs_and_options|
|
29
|
-
driver.allocate_machines(action_handler, specs_and_options, parallelizer) do |machine_spec|
|
30
|
-
m = by_id[machine_spec.id]
|
31
|
-
machine_spec.from_image ||= m[:resource].from_image if m[:resource] && m[:resource].from_image
|
32
|
-
machine_spec.driver_url ||= driver.driver_url
|
33
|
-
machine_spec.save(m[:action_handler])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
action :ready do
|
39
|
-
with_ready_machines
|
40
|
-
end
|
41
|
-
|
42
|
-
action :setup do
|
43
|
-
with_ready_machines do |m|
|
44
|
-
m[:machine].setup_convergence(m[:action_handler])
|
45
|
-
m[:spec].save(m[:action_handler])
|
46
|
-
Chef::Provider::Machine.upload_files(m[:action_handler], m[:machine], m[:files])
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
action :converge do
|
51
|
-
with_ready_machines do |m|
|
52
|
-
m[:machine].setup_convergence(m[:action_handler])
|
53
|
-
m[:spec].save(m[:action_handler])
|
54
|
-
Chef::Provider::Machine.upload_files(m[:action_handler], m[:machine], m[:files])
|
55
|
-
|
56
|
-
if m[:resource] && m[:resource].converge
|
57
|
-
Chef::Log.info("Converging #{m[:spec].name} because 'converge true' is set ...")
|
58
|
-
m[:machine].converge(m[:action_handler])
|
59
|
-
elsif (!m[:resource] || m[:resource].converge.nil?) && m[:action_handler].locally_updated
|
60
|
-
Chef::Log.info("Converging #{m[:spec].name} because the resource was updated ...")
|
61
|
-
m[:machine].converge(m[:action_handler])
|
62
|
-
elsif !m[:spec].node['automatic'] || m[:spec].node['automatic'].size == 0
|
63
|
-
Chef::Log.info("Converging #{m[:spec].name} because it has never been converged (automatic attributes are empty) ...")
|
64
|
-
m[:machine].converge(m[:action_handler])
|
65
|
-
elsif m[:resource] && m[:resource].converge == false
|
66
|
-
Chef::Log.debug("Not converging #{m[:spec].name} because 'converge false' is set.")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
action :converge_only do
|
72
|
-
parallel_do(@machines) do |m|
|
73
|
-
machine = run_context.chef_provisioning.connect_to_machine(m[:spec])
|
74
|
-
machine.converge(m[:action_handler])
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
action :destroy do
|
79
|
-
parallel_do(by_current_driver) do |driver, specs_and_options|
|
80
|
-
driver.destroy_machines(action_handler, specs_and_options, parallelizer)
|
81
|
-
specs_and_options.keys.each do |machine_spec|
|
82
|
-
machine_spec.delete(action_handler)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
action :stop do
|
88
|
-
parallel_do(by_current_driver) do |driver, specs_and_options|
|
89
|
-
driver.stop_machines(action_handler, specs_and_options, parallelizer)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
class MachineBatchError < StandardError
|
94
|
-
attr_reader :machine
|
95
|
-
def initialize(machine, msg)
|
96
|
-
@machine = machine
|
97
|
-
super(msg)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def with_ready_machines
|
102
|
-
action_allocate
|
103
|
-
parallel_do(by_new_driver) do |driver, specs_and_options|
|
104
|
-
driver.ready_machines(action_handler, specs_and_options, parallelizer) do |machine|
|
105
|
-
machine.machine_spec.save(action_handler)
|
106
|
-
|
107
|
-
m = by_id[machine.machine_spec.id]
|
108
|
-
|
109
|
-
m[:machine] = machine
|
110
|
-
begin
|
111
|
-
yield m if block_given?
|
112
|
-
rescue StandardError => error
|
113
|
-
Chef::Log.debug("Chef provisioning failed on machine #{machine.name}")
|
114
|
-
raise MachineBatchError.new(machine, error.message)
|
115
|
-
ensure
|
116
|
-
machine.disconnect
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def by_id
|
123
|
-
@by_id ||= @machines.inject({}) { |hash,m| hash[m[:spec].id] = m; hash }
|
124
|
-
end
|
125
|
-
|
126
|
-
# TODO in many of these cases, the order of the results only matters because you
|
127
|
-
# want to match it up with the input. Make a parallelize method that doesn't
|
128
|
-
# care about order and spits back results as quickly as possible.
|
129
|
-
def parallel_do(enum, options = {}, &block)
|
130
|
-
parallelizer.parallelize(enum, options, &block).to_a
|
131
|
-
end
|
132
|
-
|
133
|
-
def by_new_driver
|
134
|
-
result = {}
|
135
|
-
drivers = {}
|
136
|
-
@machines.each do |m|
|
137
|
-
if m[:desired_driver]
|
138
|
-
drivers[m[:desired_driver]] ||= run_context.chef_provisioning.driver_for(m[:desired_driver])
|
139
|
-
driver = drivers[m[:desired_driver]]
|
140
|
-
# Check whether the current driver is same or different; we disallow
|
141
|
-
# moving a machine from one place to another.
|
142
|
-
if m[:spec].driver_url
|
143
|
-
drivers[m[:spec].driver_url] ||= run_context.chef_provisioning.driver_for(m[:spec].driver_url)
|
144
|
-
current_driver = drivers[m[:spec].driver_url]
|
145
|
-
if driver.driver_url != current_driver.driver_url
|
146
|
-
raise "Cannot move '#{m[:spec].name}' from #{current_driver.driver_url} to #{driver.driver_url}: machine moving is not supported. Destroy and recreate."
|
147
|
-
end
|
148
|
-
end
|
149
|
-
result[driver] ||= {}
|
150
|
-
result[driver][m[:spec]] = m[:machine_options].call(driver)
|
151
|
-
else
|
152
|
-
raise "No driver specified for #{m[:spec].name}"
|
153
|
-
end
|
154
|
-
end
|
155
|
-
result
|
156
|
-
end
|
157
|
-
|
158
|
-
def by_current_driver
|
159
|
-
result = {}
|
160
|
-
drivers = {}
|
161
|
-
@machines.each do |m|
|
162
|
-
if m[:spec].driver_url
|
163
|
-
drivers[m[:spec].driver_url] ||= run_context.chef_provisioning.driver_for(m[:spec].driver_url)
|
164
|
-
driver = drivers[m[:spec].driver_url]
|
165
|
-
result[driver] ||= {}
|
166
|
-
result[driver][m[:spec]] = m[:machine_options].call(driver)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
result
|
170
|
-
end
|
171
|
-
|
172
|
-
def load_current_resource
|
173
|
-
# Load nodes in parallel
|
174
|
-
@machines = parallel_do(new_resource.machines) do |machine|
|
175
|
-
if machine.is_a?(Chef::Resource::Machine)
|
176
|
-
machine_resource = machine
|
177
|
-
provider = Chef::Provider::Machine.new(machine_resource, machine_resource.run_context)
|
178
|
-
provider.load_current_resource
|
179
|
-
{
|
180
|
-
:resource => machine_resource,
|
181
|
-
:spec => provider.machine_spec,
|
182
|
-
:desired_driver => machine_resource.driver,
|
183
|
-
:files => machine_resource.files,
|
184
|
-
:machine_options => proc { |driver| provider.machine_options(driver) },
|
185
|
-
:action_handler => Provisioning::AddPrefixActionHandler.new(action_handler, "[#{machine_resource.name}] ")
|
186
|
-
}
|
187
|
-
elsif machine.is_a?(Provisioning::ManagedEntry)
|
188
|
-
machine_spec = machine
|
189
|
-
{
|
190
|
-
:spec => machine_spec,
|
191
|
-
:desired_driver => new_resource.driver,
|
192
|
-
:files => new_resource.files,
|
193
|
-
:machine_options => proc { |driver| machine_options(driver) },
|
194
|
-
:action_handler => Provisioning::AddPrefixActionHandler.new(action_handler, "[#{machine_spec.name}] ")
|
195
|
-
}
|
196
|
-
else
|
197
|
-
name = machine
|
198
|
-
machine_spec = chef_managed_entry_store.get_or_new(:machine, name)
|
199
|
-
{
|
200
|
-
:spec => machine_spec,
|
201
|
-
:desired_driver => new_resource.driver,
|
202
|
-
:files => new_resource.files,
|
203
|
-
:machine_options => proc { |driver| machine_options(driver) },
|
204
|
-
:action_handler => Provisioning::AddPrefixActionHandler.new(action_handler, "[#{name}] ")
|
205
|
-
}
|
206
|
-
end
|
207
|
-
end.to_a
|
208
|
-
end
|
209
|
-
|
210
|
-
def chef_managed_entry_store
|
211
|
-
@chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
|
212
|
-
end
|
213
|
-
|
214
|
-
def machine_options(driver)
|
215
|
-
result = { :convergence_options => { :chef_server => new_resource.chef_server } }
|
216
|
-
result = Chef::Mixin::DeepMerge.hash_only_merge(result, run_context.chef_provisioning.config[:machine_options]) if run_context.chef_provisioning.config[:machine_options]
|
217
|
-
result = Chef::Mixin::DeepMerge.hash_only_merge(result, driver.config[:machine_options]) if driver.config && driver.config[:machine_options]
|
218
|
-
result = Chef::Mixin::DeepMerge.hash_only_merge(result, new_resource.machine_options)
|
219
|
-
result
|
220
|
-
end
|
221
|
-
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
1
|
+
require 'chef/chef_fs/parallelizer'
|
2
|
+
require 'chef/provider/lwrp_base'
|
3
|
+
require 'chef/provider/machine'
|
4
|
+
require 'chef/provisioning/chef_provider_action_handler'
|
5
|
+
require 'chef/provisioning/add_prefix_action_handler'
|
6
|
+
require 'chef/provisioning/machine_spec'
|
7
|
+
|
8
|
+
class Chef
|
9
|
+
class Provider
|
10
|
+
class MachineBatch < Chef::Provider::LWRPBase
|
11
|
+
provides :machine_batch
|
12
|
+
|
13
|
+
def action_handler
|
14
|
+
@action_handler ||= Provisioning::ChefProviderActionHandler.new(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
use_inline_resources
|
18
|
+
|
19
|
+
def whyrun_supported?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def parallelizer
|
24
|
+
@parallelizer ||= Chef::ChefFS::Parallelizer.new(new_resource.max_simultaneous || 100)
|
25
|
+
end
|
26
|
+
|
27
|
+
action :allocate do
|
28
|
+
by_new_driver.each do |driver, specs_and_options|
|
29
|
+
driver.allocate_machines(action_handler, specs_and_options, parallelizer) do |machine_spec|
|
30
|
+
m = by_id[machine_spec.id]
|
31
|
+
machine_spec.from_image ||= m[:resource].from_image if m[:resource] && m[:resource].from_image
|
32
|
+
machine_spec.driver_url ||= driver.driver_url
|
33
|
+
machine_spec.save(m[:action_handler])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
action :ready do
|
39
|
+
with_ready_machines
|
40
|
+
end
|
41
|
+
|
42
|
+
action :setup do
|
43
|
+
with_ready_machines do |m|
|
44
|
+
m[:machine].setup_convergence(m[:action_handler])
|
45
|
+
m[:spec].save(m[:action_handler])
|
46
|
+
Chef::Provider::Machine.upload_files(m[:action_handler], m[:machine], m[:files])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
action :converge do
|
51
|
+
with_ready_machines do |m|
|
52
|
+
m[:machine].setup_convergence(m[:action_handler])
|
53
|
+
m[:spec].save(m[:action_handler])
|
54
|
+
Chef::Provider::Machine.upload_files(m[:action_handler], m[:machine], m[:files])
|
55
|
+
|
56
|
+
if m[:resource] && m[:resource].converge
|
57
|
+
Chef::Log.info("Converging #{m[:spec].name} because 'converge true' is set ...")
|
58
|
+
m[:machine].converge(m[:action_handler])
|
59
|
+
elsif (!m[:resource] || m[:resource].converge.nil?) && m[:action_handler].locally_updated
|
60
|
+
Chef::Log.info("Converging #{m[:spec].name} because the resource was updated ...")
|
61
|
+
m[:machine].converge(m[:action_handler])
|
62
|
+
elsif !m[:spec].node['automatic'] || m[:spec].node['automatic'].size == 0
|
63
|
+
Chef::Log.info("Converging #{m[:spec].name} because it has never been converged (automatic attributes are empty) ...")
|
64
|
+
m[:machine].converge(m[:action_handler])
|
65
|
+
elsif m[:resource] && m[:resource].converge == false
|
66
|
+
Chef::Log.debug("Not converging #{m[:spec].name} because 'converge false' is set.")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
action :converge_only do
|
72
|
+
parallel_do(@machines) do |m|
|
73
|
+
machine = run_context.chef_provisioning.connect_to_machine(m[:spec])
|
74
|
+
machine.converge(m[:action_handler])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
action :destroy do
|
79
|
+
parallel_do(by_current_driver) do |driver, specs_and_options|
|
80
|
+
driver.destroy_machines(action_handler, specs_and_options, parallelizer)
|
81
|
+
specs_and_options.keys.each do |machine_spec|
|
82
|
+
machine_spec.delete(action_handler)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
action :stop do
|
88
|
+
parallel_do(by_current_driver) do |driver, specs_and_options|
|
89
|
+
driver.stop_machines(action_handler, specs_and_options, parallelizer)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class MachineBatchError < StandardError
|
94
|
+
attr_reader :machine
|
95
|
+
def initialize(machine, msg)
|
96
|
+
@machine = machine
|
97
|
+
super(msg)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def with_ready_machines
|
102
|
+
action_allocate
|
103
|
+
parallel_do(by_new_driver) do |driver, specs_and_options|
|
104
|
+
driver.ready_machines(action_handler, specs_and_options, parallelizer) do |machine|
|
105
|
+
machine.machine_spec.save(action_handler)
|
106
|
+
|
107
|
+
m = by_id[machine.machine_spec.id]
|
108
|
+
|
109
|
+
m[:machine] = machine
|
110
|
+
begin
|
111
|
+
yield m if block_given?
|
112
|
+
rescue StandardError => error
|
113
|
+
Chef::Log.debug("Chef provisioning failed on machine #{machine.name}")
|
114
|
+
raise MachineBatchError.new(machine, error.message)
|
115
|
+
ensure
|
116
|
+
machine.disconnect
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def by_id
|
123
|
+
@by_id ||= @machines.inject({}) { |hash,m| hash[m[:spec].id] = m; hash }
|
124
|
+
end
|
125
|
+
|
126
|
+
# TODO in many of these cases, the order of the results only matters because you
|
127
|
+
# want to match it up with the input. Make a parallelize method that doesn't
|
128
|
+
# care about order and spits back results as quickly as possible.
|
129
|
+
def parallel_do(enum, options = {}, &block)
|
130
|
+
parallelizer.parallelize(enum, options, &block).to_a
|
131
|
+
end
|
132
|
+
|
133
|
+
def by_new_driver
|
134
|
+
result = {}
|
135
|
+
drivers = {}
|
136
|
+
@machines.each do |m|
|
137
|
+
if m[:desired_driver]
|
138
|
+
drivers[m[:desired_driver]] ||= run_context.chef_provisioning.driver_for(m[:desired_driver])
|
139
|
+
driver = drivers[m[:desired_driver]]
|
140
|
+
# Check whether the current driver is same or different; we disallow
|
141
|
+
# moving a machine from one place to another.
|
142
|
+
if m[:spec].driver_url
|
143
|
+
drivers[m[:spec].driver_url] ||= run_context.chef_provisioning.driver_for(m[:spec].driver_url)
|
144
|
+
current_driver = drivers[m[:spec].driver_url]
|
145
|
+
if driver.driver_url != current_driver.driver_url
|
146
|
+
raise "Cannot move '#{m[:spec].name}' from #{current_driver.driver_url} to #{driver.driver_url}: machine moving is not supported. Destroy and recreate."
|
147
|
+
end
|
148
|
+
end
|
149
|
+
result[driver] ||= {}
|
150
|
+
result[driver][m[:spec]] = m[:machine_options].call(driver)
|
151
|
+
else
|
152
|
+
raise "No driver specified for #{m[:spec].name}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
result
|
156
|
+
end
|
157
|
+
|
158
|
+
def by_current_driver
|
159
|
+
result = {}
|
160
|
+
drivers = {}
|
161
|
+
@machines.each do |m|
|
162
|
+
if m[:spec].driver_url
|
163
|
+
drivers[m[:spec].driver_url] ||= run_context.chef_provisioning.driver_for(m[:spec].driver_url)
|
164
|
+
driver = drivers[m[:spec].driver_url]
|
165
|
+
result[driver] ||= {}
|
166
|
+
result[driver][m[:spec]] = m[:machine_options].call(driver)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
result
|
170
|
+
end
|
171
|
+
|
172
|
+
def load_current_resource
|
173
|
+
# Load nodes in parallel
|
174
|
+
@machines = parallel_do(new_resource.machines) do |machine|
|
175
|
+
if machine.is_a?(Chef::Resource::Machine)
|
176
|
+
machine_resource = machine
|
177
|
+
provider = Chef::Provider::Machine.new(machine_resource, machine_resource.run_context)
|
178
|
+
provider.load_current_resource
|
179
|
+
{
|
180
|
+
:resource => machine_resource,
|
181
|
+
:spec => provider.machine_spec,
|
182
|
+
:desired_driver => machine_resource.driver,
|
183
|
+
:files => machine_resource.files,
|
184
|
+
:machine_options => proc { |driver| provider.machine_options(driver) },
|
185
|
+
:action_handler => Provisioning::AddPrefixActionHandler.new(action_handler, "[#{machine_resource.name}] ")
|
186
|
+
}
|
187
|
+
elsif machine.is_a?(Provisioning::ManagedEntry)
|
188
|
+
machine_spec = machine
|
189
|
+
{
|
190
|
+
:spec => machine_spec,
|
191
|
+
:desired_driver => new_resource.driver,
|
192
|
+
:files => new_resource.files,
|
193
|
+
:machine_options => proc { |driver| machine_options(driver) },
|
194
|
+
:action_handler => Provisioning::AddPrefixActionHandler.new(action_handler, "[#{machine_spec.name}] ")
|
195
|
+
}
|
196
|
+
else
|
197
|
+
name = machine
|
198
|
+
machine_spec = chef_managed_entry_store.get_or_new(:machine, name)
|
199
|
+
{
|
200
|
+
:spec => machine_spec,
|
201
|
+
:desired_driver => new_resource.driver,
|
202
|
+
:files => new_resource.files,
|
203
|
+
:machine_options => proc { |driver| machine_options(driver) },
|
204
|
+
:action_handler => Provisioning::AddPrefixActionHandler.new(action_handler, "[#{name}] ")
|
205
|
+
}
|
206
|
+
end
|
207
|
+
end.to_a
|
208
|
+
end
|
209
|
+
|
210
|
+
def chef_managed_entry_store
|
211
|
+
@chef_managed_entry_store ||= Provisioning.chef_managed_entry_store(new_resource.chef_server)
|
212
|
+
end
|
213
|
+
|
214
|
+
def machine_options(driver)
|
215
|
+
result = { :convergence_options => { :chef_server => new_resource.chef_server } }
|
216
|
+
result = Chef::Mixin::DeepMerge.hash_only_merge(result, run_context.chef_provisioning.config[:machine_options]) if run_context.chef_provisioning.config[:machine_options]
|
217
|
+
result = Chef::Mixin::DeepMerge.hash_only_merge(result, driver.config[:machine_options]) if driver.config && driver.config[:machine_options]
|
218
|
+
result = Chef::Mixin::DeepMerge.hash_only_merge(result, new_resource.machine_options)
|
219
|
+
result
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -1,35 +1,36 @@
|
|
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 MachineExecute < Chef::Provider::LWRPBase
|
8
|
-
|
9
|
-
def action_handler
|
10
|
-
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
|
11
|
-
end
|
12
|
-
|
13
|
-
use_inline_resources
|
14
|
-
|
15
|
-
def whyrun_supported?
|
16
|
-
true
|
17
|
-
end
|
18
|
-
|
19
|
-
def machine
|
20
|
-
@machine ||= begin
|
21
|
-
if new_resource.machine.kind_of?(Chef::Provisioning::Machine)
|
22
|
-
new_resource.machine
|
23
|
-
else
|
24
|
-
run_context.chef_provisioning.connect_to_machine(new_resource.machine, new_resource.chef_server)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
action :run do
|
30
|
-
machine.execute(action_handler, new_resource.command, :stream => new_resource.live_stream
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
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 MachineExecute < Chef::Provider::LWRPBase
|
8
|
+
|
9
|
+
def action_handler
|
10
|
+
@action_handler ||= Chef::Provisioning::ChefProviderActionHandler.new(self)
|
11
|
+
end
|
12
|
+
|
13
|
+
use_inline_resources
|
14
|
+
|
15
|
+
def whyrun_supported?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def machine
|
20
|
+
@machine ||= begin
|
21
|
+
if new_resource.machine.kind_of?(Chef::Provisioning::Machine)
|
22
|
+
new_resource.machine
|
23
|
+
else
|
24
|
+
run_context.chef_provisioning.connect_to_machine(new_resource.machine, new_resource.chef_server)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
action :run do
|
30
|
+
machine.execute(action_handler, new_resource.command, :stream => new_resource.live_stream,
|
31
|
+
:timeout => new_resource.timeout)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|