Class: Ridley::SSH

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Logger
Defined in:
lib/ridley/ssh.rb,
lib/ridley/ssh/worker.rb,
lib/ridley/ssh/response.rb,
lib/ridley/ssh/response_set.rb

Overview

Author:

Defined Under Namespace

Classes: Response, ResponseSet, Worker

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nodes, options = {}) ⇒ SSH

Returns a new instance of SSH.

Parameters:



31
32
33
34
35
36
# File 'lib/ridley/ssh.rb', line 31

def initialize(nodes, options = {})
  @nodes   = nodes
  @options = options

  self.options[:timeout] ||= 1.5
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



25
26
27
# File 'lib/ridley/ssh.rb', line 25

def nodes
  @nodes
end

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/ridley/ssh.rb', line 26

def options
  @options
end

Class Method Details

.start(nodes, options = {}, &block) ⇒ Object

Parameters:



13
14
15
16
17
18
19
# File 'lib/ridley/ssh.rb', line 13

def start(nodes, options = {}, &block)
  runner = new(nodes, options)
  result = yield runner
  runner.terminate

  result
end

Instance Method Details

#finalizeObject



70
71
72
# File 'lib/ridley/ssh.rb', line 70

def finalize
  workers.collect(&:terminate)
end

#run(command) ⇒ Array

Parameters:

  • command (String)

Returns:

  • (Array)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ridley/ssh.rb', line 48

def run(command)
  workers.collect { |worker| worker.async.run(command) }

  ResponseSet.new.tap do |responses|
    until responses.length == workers.length
      receive { |msg|
        status, response = msg
        
        case status
        when :ok
          responses.add_ok(response)
        when :error
          responses.add_error(response)
        else
          error "SSH Failure: #{command}. terminating..."
          terminate
        end
      }
    end
  end
end

#workersArray<SSH::Worker>

Returns:



39
40
41
42
43
# File 'lib/ridley/ssh.rb', line 39

def workers
  @workers ||= Array(nodes).collect do |node|
    Worker.new_link(current_actor, node.public_hostname, options)
  end
end