Class: ChefDK::Command::Provision
Constant Summary
collapse
- OPT_SEPARATOR =
/[=\s]+/.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#chef_config, #chefdk_config, #config_loader
Methods inherited from Base
#needs_help?, #needs_version?, #run_with_default_options
Methods included from Helpers
#chefdk_home, #err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command
Constructor Details
#initialize(*args) ⇒ Provision
Returns a new instance of Provision.
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/chef-dk/command/provision.rb', line 221
def initialize(*args)
super
@ui = UI.new
@policyfile_relative_path = nil
@policy_group = nil
@provisioning_cookbook_path = nil
@provisioning_cookbook_name = nil
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
215
216
217
|
# File 'lib/chef-dk/command/provision.rb', line 215
def params
@params
end
|
#policy_group ⇒ Object
Returns the value of attribute policy_group.
217
218
219
|
# File 'lib/chef-dk/command/provision.rb', line 217
def policy_group
@policy_group
end
|
#policyfile_relative_path ⇒ Object
Returns the value of attribute policyfile_relative_path.
216
217
218
|
# File 'lib/chef-dk/command/provision.rb', line 216
def policyfile_relative_path
@policyfile_relative_path
end
|
#ui ⇒ Object
Returns the value of attribute ui.
219
220
221
|
# File 'lib/chef-dk/command/provision.rb', line 219
def ui
@ui
end
|
Class Method Details
.split_opt(key_value) ⇒ Object
194
195
196
197
|
# File 'lib/chef-dk/command/provision.rb', line 194
def self.split_opt(key_value)
key, _separator, value = key_value.partition(OPT_SEPARATOR)
[key, value]
end
|
Instance Method Details
#apply_params!(params) ⇒ Object
340
341
342
343
344
345
346
347
|
# File 'lib/chef-dk/command/provision.rb', line 340
def apply_params!(params)
remaining_args = parse_options(params)
if enable_policyfile?
handle_policy_argv(remaining_args)
else
handle_no_policy_argv(remaining_args)
end
end
|
#chef_runner ⇒ Object
An instance of ChefRunner. Calling ChefRunner#converge will trigger convergence and generate the desired code.
256
257
258
|
# File 'lib/chef-dk/command/provision.rb', line 256
def chef_runner
@chef_runner ||= ChefRunner.new(provisioning_cookbook_path, ["recipe[#{provisioning_cookbook_name}::#{recipe}]"])
end
|
#cookbook_path ⇒ Object
332
333
334
|
# File 'lib/chef-dk/command/provision.rb', line 332
def cookbook_path
config[:cookbook]
end
|
#debug? ⇒ Boolean
349
350
351
|
# File 'lib/chef-dk/command/provision.rb', line 349
def debug?
!!config[:debug]
end
|
#default_action ⇒ Object
295
296
297
298
299
300
301
|
# File 'lib/chef-dk/command/provision.rb', line 295
def default_action
if config[:destroy]
:destroy
else
:converge
end
end
|
#enable_policyfile? ⇒ Boolean
336
337
338
|
# File 'lib/chef-dk/command/provision.rb', line 336
def enable_policyfile?
config[:enable_policyfile]
end
|
#node_name ⇒ Object
303
304
305
|
# File 'lib/chef-dk/command/provision.rb', line 303
def node_name
config[:node_name]
end
|
#policy_name ⇒ Object
287
288
289
290
291
292
293
|
# File 'lib/chef-dk/command/provision.rb', line 287
def policy_name
if sync_policy?
push.policy_data["name"]
else
config[:policy_name]
end
end
|
#provisioning_cookbook_name ⇒ Object
The name of the provisioning cookbook
327
328
329
330
|
# File 'lib/chef-dk/command/provision.rb', line 327
def provisioning_cookbook_name
detect_provisioning_cookbook_name_and_path! unless @provisioning_cookbook_name
@provisioning_cookbook_name
end
|
#provisioning_cookbook_path ⇒ Object
Gives the ‘cookbook_path` in the chef-client sense, which is the directory that contains the provisioning cookbook.
321
322
323
324
|
# File 'lib/chef-dk/command/provision.rb', line 321
def provisioning_cookbook_path
detect_provisioning_cookbook_name_and_path! unless @provisioning_cookbook_path
@provisioning_cookbook_path
end
|
#push ⇒ Object
260
261
262
263
264
265
266
|
# File 'lib/chef-dk/command/provision.rb', line 260
def push
@push ||= PolicyfileServices::Push.new(policyfile: policyfile_relative_path,
ui: ui,
policy_group: policy_group,
config: chef_config,
root_dir: Dir.pwd)
end
|
#recipe ⇒ Object
315
316
317
|
# File 'lib/chef-dk/command/provision.rb', line 315
def recipe
config[:machine_recipe]
end
|
#run(params = []) ⇒ Object
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/chef-dk/command/provision.rb', line 233
def run(params = [])
return 1 unless apply_params!(params)
chef_config return 1 unless check_cookbook_and_recipe_path
push.run if sync_policy?
setup_context
chef_runner.converge
0
rescue ChefRunnerError, PolicyfileServiceError => e
handle_error(e)
1
rescue StandardError, LoadError => error
ui.err("Error: #{error.message}")
1
end
|
#setup_context ⇒ Object
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/chef-dk/command/provision.rb', line 268
def setup_context
ProvisioningData.context.tap do |c|
c.action = default_action
c.node_name = node_name
c.target = target
c.set_user_opts(user_opts)
c.enable_policyfile = enable_policyfile?
if enable_policyfile?
c.policy_group = policy_group
c.policy_name = policy_name
end
end
end
|
#sync_policy? ⇒ Boolean
353
354
355
|
# File 'lib/chef-dk/command/provision.rb', line 353
def sync_policy?
config.key?(:sync)
end
|
#target ⇒ Object
307
308
309
|
# File 'lib/chef-dk/command/provision.rb', line 307
def target
config[:target]
end
|
#user_opts ⇒ Object
311
312
313
|
# File 'lib/chef-dk/command/provision.rb', line 311
def user_opts
config[:opts]
end
|