lib/capissh/connection_manager.rb
def execute_on_servers(servers, options={}, &block)
      raise ArgumentError, "expected a block" unless block_given?

      connect_to_servers = ServerDefinition.wrap_list(*servers)

      if options[:continue_on_error]
        connect_to_servers.delete_if { |s| has_failed?(s) }
      end

      if connect_to_servers.empty?
        raise Capissh::NoMatchingServersError, "no servers found to match #{options.inspect}" unless options[:continue_on_no_matching_servers]
        return
      end

      logger.trace "servers: #{connect_to_servers.map { |s| s.host }.inspect}"

      max_hosts = (options[:max_hosts] || connect_to_servers.size).to_i
      is_subset = max_hosts < connect_to_servers.size

      if max_hosts <= 0
        raise Capissh::NoMatchingServersError, "max_hosts is invalid for #{options.inspect}" unless options[:continue_on_no_matching_servers]
        return
      end

      # establish connections to those servers in groups of max_hosts, as necessary
      connect_to_servers.each_slice(max_hosts) do |servers_slice|
        begin
          establish_connections_to(servers_slice)
        rescue ConnectionError => error
          raise error unless options[:continue_on_error]
          error.hosts.each do |h|
            servers_slice.delete(h)
            failed!(h)
          end
        end

        begin
          yield Sessions.new(servers_slice.map { |server| sessions[server] })
        rescue RemoteError => error
          raise error unless options[:continue_on_error]
          error.hosts.each { |h| failed!(h) }
        end

        # if dealing with a subset (e.g., :max_hosts is less than the
        # number of servers available) teardown the subset of connections
        # that were just made, so that we can make room for the next subset.
        teardown_connections_to(servers_slice) if is_subset
      end
    end
# Determines the set of servers and establishes connections to them,
# and then yields that list of servers.
#
# All options will be used to find servers. (see find_servers)
#
# The additional options below will also be used as follows:
#
# * +continue_on_no_matching_servers+: (optional), set to :continue to return
#   instead of raising when no servers are found
# * +max_hosts+: (optional), integer to batch commands in chunks of hosts
# * +continue_on_error+: (optional), continue on connection errors
#
Determines the set of servers and establishes connections to them,
and then yields that list of servers.

All options will be used to find servers.

The additional options below will also be used as follows.


Determines the set of servers and establishes connections to them and then yields that list of servers . All options will be used to find servers . The additional options below will also be used as follows .
def execute_on_servers(servers, options={}, &block)
      raise ArgumentError, "expected a block" unless block_given?
      connect_to_servers = ServerDefinition.wrap_list(*servers)
      if options[:continue_on_error]
        connect_to_servers.delete_if { |s| has_failed?(s) }
      end
      if connect_to_servers.empty?
        raise Capissh::NoMatchingServersError, "no servers found to match #{options.inspect}" unless options[:continue_on_no_matching_servers]
        return
      end
      logger.trace "servers: #{connect_to_servers.map { |s| s.host }.inspect}"
      max_hosts = (options[:max_hosts] || connect_to_servers.size).to_i
      is_subset = max_hosts < connect_to_servers.size
      if max_hosts <= 0
        raise Capissh::NoMatchingServersError, "max_hosts is invalid for #{options.inspect}" unless options[:continue_on_no_matching_servers]
        return
      end
      connect_to_servers.each_slice(max_hosts) do |servers_slice|
        begin
          establish_connections_to(servers_slice)
        rescue ConnectionError => error
          raise error unless options[:continue_on_error]
          error.hosts.each do |h|
            servers_slice.delete(h)
            failed!(h)
          end
        end
        begin
          yield Sessions.new(servers_slice.map { |server| sessions[server] })
        rescue RemoteError => error
          raise error unless options[:continue_on_error]
          error.hosts.each { |h| failed!(h) }
        end
        teardown_connections_to(servers_slice) if is_subset
      end
    end
def execute_on_servers ( servers , options = { } , & block ) raise ArgumentError , "expected a block" unless block_given? connect_to_servers = ServerDefinition . wrap_list ( * servers ) if options [ :continue_on_error ] connect_to_servers . delete_if { | s | has_failed? ( s ) } end if connect_to_servers . empty? raise Capissh :: NoMatchingServersError , "no servers found to match #{options.inspect}" unless options [ :continue_on_no_matching_servers ] return end logger . trace "servers: #{connect_to_servers.map { |s| s.host }.inspect}" max_hosts = ( options [ :max_hosts ] || connect_to_servers . size ) . to_i is_subset = max_hosts < connect_to_servers . size if max_hosts <= 0 raise Capissh :: NoMatchingServersError , "max_hosts is invalid for #{options.inspect}" unless options [ :continue_on_no_matching_servers ] return end connect_to_servers . each_slice ( max_hosts ) do | servers_slice | begin establish_connections_to ( servers_slice ) rescue ConnectionError => error raise error unless options [ :continue_on_error ] error . hosts . each do | h | servers_slice . delete ( h ) failed! ( h ) end end begin yield Sessions . new ( servers_slice . map { | server | sessions [ server ] } ) rescue RemoteError => error raise error unless options [ :continue_on_error ] error . hosts . each { | h | failed! ( h ) } end teardown_connections_to ( servers_slice ) if is_subset end end
Determines the set of servers and establishes connections to them,
and then yields that list of servers.
Determines the set of servers and establishes connections to them and then yields that list of servers .
# establish connections to those servers in groups of max_hosts, as necessary # if dealing with a subset (e.g., :max_hosts is less than the # number of servers available) teardown the subset of connections # that were just made, so that we can make room for the next subset.
servers
options
block