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, #generator_config, #knife_config
Methods inherited from Base
#needs_help?, #needs_version?, #run_with_default_options
Methods included from Helpers
#chefdk_home, #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix
Constructor Details
#initialize(*args) ⇒ Provision
Returns a new instance of Provision.
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/chef-dk/command/provision.rb', line 217
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.
211
212
213
|
# File 'lib/chef-dk/command/provision.rb', line 211
def params
@params
end
|
#policy_group ⇒ Object
Returns the value of attribute policy_group.
213
214
215
|
# File 'lib/chef-dk/command/provision.rb', line 213
def policy_group
@policy_group
end
|
#policyfile_relative_path ⇒ Object
Returns the value of attribute policyfile_relative_path.
212
213
214
|
# File 'lib/chef-dk/command/provision.rb', line 212
def policyfile_relative_path
@policyfile_relative_path
end
|
#ui ⇒ Object
Returns the value of attribute ui.
215
216
217
|
# File 'lib/chef-dk/command/provision.rb', line 215
def ui
@ui
end
|
Class Method Details
.split_opt(key_value) ⇒ Object
190
191
192
193
|
# File 'lib/chef-dk/command/provision.rb', line 190
def self.split_opt(key_value)
key, _separator, value = key_value.partition(OPT_SEPARATOR)
[key, value]
end
|
Instance Method Details
#apply_params!(params) ⇒ Object
336
337
338
339
340
341
342
343
|
# File 'lib/chef-dk/command/provision.rb', line 336
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.
252
253
254
|
# File 'lib/chef-dk/command/provision.rb', line 252
def chef_runner
@chef_runner ||= ChefRunner.new(provisioning_cookbook_path, ["recipe[#{provisioning_cookbook_name}::#{recipe}]"])
end
|
#cookbook_path ⇒ Object
328
329
330
|
# File 'lib/chef-dk/command/provision.rb', line 328
def cookbook_path
config[:cookbook]
end
|
#debug? ⇒ Boolean
345
346
347
|
# File 'lib/chef-dk/command/provision.rb', line 345
def debug?
!!config[:debug]
end
|
#default_action ⇒ Object
291
292
293
294
295
296
297
|
# File 'lib/chef-dk/command/provision.rb', line 291
def default_action
if config[:destroy]
:destroy
else
:converge
end
end
|
#enable_policyfile? ⇒ Boolean
332
333
334
|
# File 'lib/chef-dk/command/provision.rb', line 332
def enable_policyfile?
config[:enable_policyfile]
end
|
#node_name ⇒ Object
299
300
301
|
# File 'lib/chef-dk/command/provision.rb', line 299
def node_name
config[:node_name]
end
|
#policy_name ⇒ Object
283
284
285
286
287
288
289
|
# File 'lib/chef-dk/command/provision.rb', line 283
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
323
324
325
326
|
# File 'lib/chef-dk/command/provision.rb', line 323
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.
317
318
319
320
|
# File 'lib/chef-dk/command/provision.rb', line 317
def provisioning_cookbook_path
detect_provisioning_cookbook_name_and_path! unless @provisioning_cookbook_path
@provisioning_cookbook_path
end
|
#push ⇒ Object
256
257
258
259
260
261
262
|
# File 'lib/chef-dk/command/provision.rb', line 256
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
311
312
313
|
# File 'lib/chef-dk/command/provision.rb', line 311
def recipe
config[:machine_recipe]
end
|
#run(params = []) ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
# File 'lib/chef-dk/command/provision.rb', line 229
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# File 'lib/chef-dk/command/provision.rb', line 264
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
349
350
351
|
# File 'lib/chef-dk/command/provision.rb', line 349
def sync_policy?
config.key?(:sync)
end
|
#target ⇒ Object
303
304
305
|
# File 'lib/chef-dk/command/provision.rb', line 303
def target
config[:target]
end
|
#user_opts ⇒ Object
307
308
309
|
# File 'lib/chef-dk/command/provision.rb', line 307
def user_opts
config[:opts]
end
|