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
# File 'lib/ridley/ssh.rb', line 31

def initialize(nodes, options = {})
  @nodes   = Array(nodes)
  @options = options
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

#run(command) ⇒ Array

Parameters:

  • command (String)

Returns:

  • (Array)

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ridley/ssh.rb', line 39

def run(command)
  workers = Array.new
  futures = self.nodes.collect do |node|
    workers << worker = Worker.new_link(self.options.freeze)
    worker.future.run(node.public_hostname, 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