Class: Ridley::SSH
- Inherits:
-
Object
- Object
- Ridley::SSH
- 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
Defined Under Namespace
Classes: Response, ResponseSet, Worker
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(nodes, options = {}) ⇒ SSH
constructor
A new instance of SSH.
- #run(command) ⇒ Array
- #workers ⇒ Array<SSH::Worker>
Constructor Details
#initialize(nodes, options = {}) ⇒ SSH
Returns a new instance of SSH.
31 32 33 34 35 36 |
# File 'lib/ridley/ssh.rb', line 31 def initialize(nodes, = {}) @nodes = nodes @options = self.[:timeout] ||= 1.5 end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
25 26 27 |
# File 'lib/ridley/ssh.rb', line 25 def nodes @nodes end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/ridley/ssh.rb', line 26 def @options end |
Class Method Details
.start(nodes, options = {}, &block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/ridley/ssh.rb', line 13 def start(nodes, = {}, &block) runner = new(nodes, ) result = yield runner runner.terminate result end |
Instance Method Details
#finalize ⇒ Object
70 71 72 |
# File 'lib/ridley/ssh.rb', line 70 def finalize workers.collect(&:terminate) end |
#run(command) ⇒ 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 |
#workers ⇒ Array<SSH::Worker>
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, ) end end |