Class: Chef::Resource::MachineBatch
- Inherits:
-
LWRPBase
- Object
- LWRPBase
- Chef::Resource::MachineBatch
- Defined in:
- lib/chef/resource/machine_batch.rb
Instance Method Summary collapse
- #add_machine_options(options) ⇒ Object
-
#initialize(*args) ⇒ MachineBatch
constructor
A new instance of MachineBatch.
- #machine(name, &block) ⇒ Object
- #machines(*values) ⇒ Object
-
#to_text ⇒ Object
We override this because we want to hide @from_recipe and shorten @machines in error output.
Constructor Details
#initialize(*args) ⇒ MachineBatch
Returns a new instance of MachineBatch.
7 8 9 10 11 12 13 |
# File 'lib/chef/resource/machine_batch.rb', line 7 def initialize(*args) super @machines = [] @driver = run_context..current_driver @chef_server = run_context.cheffish.current_chef_server @machine_options = run_context.. end |
Instance Method Details
#add_machine_options(options) ⇒ Object
41 42 43 |
# File 'lib/chef/resource/machine_batch.rb', line 41 def () @machine_options = Chef::Mixin::DeepMerge.hash_only_merge(@machine_options, ) end |
#machine(name, &block) ⇒ Object
37 38 39 |
# File 'lib/chef/resource/machine_batch.rb', line 37 def machine(name, &block) machines << from_recipe.build_resource(:machine, name, caller[0], &block) end |
#machines(*values) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/chef/resource/machine_batch.rb', line 29 def machines(*values) if values.size == 0 @machines else @machines += values.flatten end end |
#to_text ⇒ Object
We override this because we want to hide @from_recipe and shorten @machines in error output.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chef/resource/machine_batch.rb', line 47 def to_text ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS - [ :@from_recipe, :@machines ] text = "# Declared in #{@source_line}\n\n" text << self.class.dsl_name + "(\"#{name}\") do\n" ivars.each do |ivar| if (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?) value_string = value.respond_to?(:to_text) ? value.to_text : value.inspect text << " #{ivar.to_s.sub(/^@/,'')} #{value_string}\n" end end machine_names = @machines.map do |m| if m.is_a?(ChefMetal::MachineSpec) m.name elsif m.is_a?(Chef::Resource::Machine) m.name else m end end text << " machines #{machine_names.inspect}\n" [@not_if, @only_if].flatten.each do |conditional| text << " #{conditional.to_text}\n" end text << "end\n" end |