Module: Chef::DSL::Recipe
- Defined in:
- lib/chef_metal/recipe_dsl.rb
Constant Summary collapse
- NOT_PASSED =
Object.new
Instance Method Summary collapse
- #add_machine_options(options, &block) ⇒ Object
- #auto_batch_machines(value = NOT_PASSED) ⇒ Object
- #current_machine_options ⇒ Object
-
#machine(name, &block) ⇒ Object
When the machine resource is first declared, create a machine_batch (if there isn’t one already).
- #machine_batch(name = nil, &block) ⇒ Object
- #machine_batch_default_name ⇒ Object
- #with_driver(driver, options = nil, &block) ⇒ Object
- #with_machine_options(machine_options, &block) ⇒ Object
Instance Method Details
#add_machine_options(options, &block) ⇒ Object
28 29 30 |
# File 'lib/chef_metal/recipe_dsl.rb', line 28 def (, &block) run_context..(, &block) end |
#auto_batch_machines(value = NOT_PASSED) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/chef_metal/recipe_dsl.rb', line 34 def auto_batch_machines(value = NOT_PASSED) if value == NOT_PASSED run_context..auto_batch_machines else run_context..auto_batch_machines = value end end |
#current_machine_options ⇒ Object
24 25 26 |
# File 'lib/chef_metal/recipe_dsl.rb', line 24 def run_context.. end |
#machine(name, &block) ⇒ Object
When the machine resource is first declared, create a machine_batch (if there isn’t one already)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/chef_metal/recipe_dsl.rb', line 63 def machine(name, &block) resource = build_resource(:machine, name, caller[0], &block) # Grab the previous resource so we can decide whether to batch this or make it its own resource. previous_index = run_context.resource_collection.previous_index previous = previous_index >= 0 ? run_context.resource_collection[previous_index] : nil if run_context..auto_batch_machines && previous && Array(resource.action).size == 1 && Array(previous.action) == Array(resource.action) # Handle batching similar machines (with similar actions) if previous.is_a?(Chef::Resource::MachineBatch) # If we see a machine declared after a previous machine_batch with the same action, add it to the batch. previous.machines << resource elsif previous.is_a?(Chef::Resource::Machine) # If we see two machines in a row with the same action, batch them. _self = self batch = build_resource(:machine_batch, machine_batch_default_name) do action resource.action machines [ previous, resource ] end batch.from_recipe self run_context.resource_collection[previous_index] = batch else run_context.resource_collection.insert(resource) end else run_context.resource_collection.insert(resource) end resource end |
#machine_batch(name = nil, &block) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/chef_metal/recipe_dsl.rb', line 52 def machine_batch(name = nil, &block) name ||= machine_batch_default_name recipe = self declare_resource(:machine_batch, name, caller[0]) do from_recipe recipe instance_eval(&block) end end |
#machine_batch_default_name ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/chef_metal/recipe_dsl.rb', line 42 def machine_batch_default_name if @machine_batch_index @machine_batch_index += 1 "default#{@machine_batch_index}" else @machine_batch_index = 0 "default" end end |
#with_driver(driver, options = nil, &block) ⇒ Object
16 17 18 |
# File 'lib/chef_metal/recipe_dsl.rb', line 16 def with_driver(driver, = nil, &block) run_context..with_driver(driver, , &block) end |
#with_machine_options(machine_options, &block) ⇒ Object
20 21 22 |
# File 'lib/chef_metal/recipe_dsl.rb', line 20 def (, &block) run_context..(, &block) end |