Class: ChefDK::Command::Provision
Constant Summary
collapse
- OPT_SEPARATOR =
/[=\s]+/
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.
216
217
218
219
220
221
222
223
224
225
226
|
# File 'lib/chef-dk/command/provision.rb', line 216
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.
210
211
212
|
# File 'lib/chef-dk/command/provision.rb', line 210
def params
@params
end
|
#policy_group ⇒ Object
Returns the value of attribute policy_group.
212
213
214
|
# File 'lib/chef-dk/command/provision.rb', line 212
def policy_group
@policy_group
end
|
#policyfile_relative_path ⇒ Object
Returns the value of attribute policyfile_relative_path.
211
212
213
|
# File 'lib/chef-dk/command/provision.rb', line 211
def policyfile_relative_path
@policyfile_relative_path
end
|
#ui ⇒ Object
Returns the value of attribute ui.
214
215
216
|
# File 'lib/chef-dk/command/provision.rb', line 214
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
335
336
337
338
339
340
341
342
|
# File 'lib/chef-dk/command/provision.rb', line 335
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.
251
252
253
|
# File 'lib/chef-dk/command/provision.rb', line 251
def chef_runner
@chef_runner ||= ChefRunner.new(provisioning_cookbook_path, ["recipe[#{provisioning_cookbook_name}::#{recipe}]"])
end
|
#cookbook_path ⇒ Object
327
328
329
|
# File 'lib/chef-dk/command/provision.rb', line 327
def cookbook_path
config[:cookbook]
end
|
#debug? ⇒ Boolean
344
345
346
|
# File 'lib/chef-dk/command/provision.rb', line 344
def debug?
!!config[:debug]
end
|
#default_action ⇒ Object
290
291
292
293
294
295
296
|
# File 'lib/chef-dk/command/provision.rb', line 290
def default_action
if config[:destroy]
:destroy
else
:converge
end
end
|
#enable_policyfile? ⇒ Boolean
331
332
333
|
# File 'lib/chef-dk/command/provision.rb', line 331
def enable_policyfile?
config[:enable_policyfile]
end
|
#node_name ⇒ Object
298
299
300
|
# File 'lib/chef-dk/command/provision.rb', line 298
def node_name
config[:node_name]
end
|
#policy_name ⇒ Object
282
283
284
285
286
287
288
|
# File 'lib/chef-dk/command/provision.rb', line 282
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
322
323
324
325
|
# File 'lib/chef-dk/command/provision.rb', line 322
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.
316
317
318
319
|
# File 'lib/chef-dk/command/provision.rb', line 316
def provisioning_cookbook_path
detect_provisioning_cookbook_name_and_path! unless @provisioning_cookbook_path
@provisioning_cookbook_path
end
|
#push ⇒ Object
255
256
257
258
259
260
261
|
# File 'lib/chef-dk/command/provision.rb', line 255
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
310
311
312
|
# File 'lib/chef-dk/command/provision.rb', line 310
def recipe
config[:machine_recipe]
end
|
#run(params = []) ⇒ Object
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/chef-dk/command/provision.rb', line 228
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/chef-dk/command/provision.rb', line 263
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
348
349
350
|
# File 'lib/chef-dk/command/provision.rb', line 348
def sync_policy?
config.key?(:sync)
end
|
#target ⇒ Object
302
303
304
|
# File 'lib/chef-dk/command/provision.rb', line 302
def target
config[:target]
end
|
#user_opts ⇒ Object
306
307
308
|
# File 'lib/chef-dk/command/provision.rb', line 306
def user_opts
config[:opts]
end
|