Sha256: 57309825c2c18e79797d6ea2be9100a60ef92830fbd7803ba696caf1a0def540

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

require 'net/ssh'

module Ridley
  module HostConnector
    # @author Jamie Winsor <reset@riotgames.com>
    class SSH
      autoload :Worker, 'ridley/host_connector/ssh/worker'

      class << self
        # @param [Ridley::NodeResource, Array<Ridley::NodeResource>] nodes
        # @param [Hash] options
        def start(nodes, options = {}, &block)
          runner = new(nodes, options)
          result = yield runner
          runner.terminate

          result
        ensure
          runner.terminate if runner && runner.alive?          
        end
      end

      include Celluloid
      include Celluloid::Logger

      attr_reader :nodes
      attr_reader :options

      # @param [Ridley::NodeResource, Array<Ridley::NodeResource>] nodes
      # @param [Hash] options
      #   @see Net::SSH
      def initialize(nodes, options = {})
        @nodes   = Array(nodes)
        @options = options
      end

      # @param [String] command
      #
      # @return [Array]
      def run(command)
        workers = Array.new
        futures = self.nodes.collect do |node|
          workers << worker = Worker.new(node.public_hostname, self.options.freeze)
          worker.future.run(command)
        end

        ResponseSet.new.tap do |response_set|
          futures.each do |future|
            status, response = future.value
            response_set.add_response(response)
          end
        end
      ensure
        workers.map(&:terminate)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ridley-0.10.2 lib/ridley/host_connector/ssh.rb
ridley-0.10.1 lib/ridley/host_connector/ssh.rb
ridley-0.10.0 lib/ridley/host_connector/ssh.rb
ridley-0.10.0.rc3 lib/ridley/host_connector/ssh.rb
ridley-0.10.0.rc2 lib/ridley/host_connector/ssh.rb
ridley-0.10.0.rc1 lib/ridley/host_connector/ssh.rb