def wait_for_status(state_name, instances, &block)
      # Wait for each node to reach status :running
      @logger.notify("aws-sdk: Waiting for all hosts to be #{state_name}")
      instances.each do |x|
        name = x[:host] ? x[:host].name : x[:name]
        instance = x[:instance]
        @logger.notify("aws-sdk: Wait for node #{name} to be #{state_name}")
        # Here we keep waiting for the machine state to reach 'running' with an
        # exponential backoff for each poll.
        # TODO: should probably be a in a shared method somewhere
        for tries in 1..10
          refreshed_instance = instance_by_id(instance.instance_id)

          if refreshed_instance.nil?
            @logger.debug("Instance #{name} not yet available (#{e})")
          else
            if block_given?
              test_result = yield refreshed_instance
            else
              test_result = refreshed_instance.state.name.to_s == state_name.to_s
            end
            if test_result
              x[:instance] = refreshed_instance
              # Always sleep, so the next command won't cause a throttle
              backoff_sleep(tries)
              break
            elsif tries == 10
              raise "Instance never reached state #{state_name}"
            end
          end

          backoff_sleep(tries)
        end
      end
    end
def wait_for_status(state_name, instances, &block)
      # Wait for each node to reach status :running
      @logger.notify("aws-sdk: Waiting for all hosts to be #{state_name}")
      instances.each do |x|
        name = x[:host] ? x[:host].name : x[:name]
        instance = x[:instance]
        @logger.notify("aws-sdk: Wait for node #{name} to be #{state_name}")
        # Here we keep waiting for the machine state to reach 'running' with an
        # exponential backoff for each poll.
        # TODO: should probably be a in a shared method somewhere
        for tries in 1..10
          refreshed_instance = instance_by_id(instance.instance_id)

          if refreshed_instance.nil?
            @logger.debug("Instance #{name} not yet available (#{e})")
          else
            if block_given?
              test_result = yield refreshed_instance
            else
              test_result = refreshed_instance.state.name.to_s == state_name.to_s
            end
            if test_result
              x[:instance] = refreshed_instance
              # Always sleep, so the next command won't cause a throttle
              backoff_sleep(tries)
              break
            elsif tries == 10
              raise "Instance never reached state #{state_name}"
            end
          end

          backoff_sleep(tries)
        end
      end
    end
Wait until all instances reach the desired state.  Each Hash in
 instances must contain an :instance and :host value.

 @param state_name [String] EC2 state to wait for, 'running', 'stopped', etc.
 @param instances Enumerable<Hash{Symbol=>EC2::Instance,Host}>
 @param block [Proc] more complex checks can be made by passing a
                     block in.  This overrides the status parameter.
                     EC2::Instance objects from the hosts will be
                     yielded to the passed block
 @return [void]
 @api private
 FIXME: rename to #wait_for_state