class Chef::Resource::MachineBatch
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/chef/resource/machine_batch.rb, line 10 def initialize(*args) super @machines = [] @driver = run_context.chef_provisioning.current_driver @chef_server = run_context.cheffish.current_chef_server @machine_options = run_context.chef_provisioning.current_machine_options end
Public Instance Methods
add_machine_options(options)
click to toggle source
# File lib/chef/resource/machine_batch.rb, line 44 def add_machine_options(options) @machine_options = Chef::Mixin::DeepMerge.hash_only_merge(@machine_options, options) end
machine(name, &block)
click to toggle source
# File lib/chef/resource/machine_batch.rb, line 40 def machine(name, &block) machines << from_recipe.build_resource(:machine, name, &block) end
machines(*values)
click to toggle source
# File lib/chef/resource/machine_batch.rb, line 32 def machines(*values) if values.size == 0 @machines else @machines += values.flatten end end
to_text()
click to toggle source
We override this because we want to hide @from_recipe and shorten @machines in error output.
# File lib/chef/resource/machine_batch.rb, line 50 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.resource_name.to_s + "(\"#{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?(Chef::Provisioning::ManagedEntry) 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