Class: Ridley::SSH::Worker Private
- Inherits:
-
Object
- Object
- Ridley::SSH::Worker
- Includes:
- Celluloid, Celluloid::Logger
- Defined in:
- lib/ridley/ssh/worker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Worker
constructor
private
A new instance of Worker.
- #run(host, command) ⇒ Array private
Constructor Details
#initialize(options = {}) ⇒ Worker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Worker.
10 11 12 13 |
# File 'lib/ridley/ssh/worker.rb', line 10 def initialize( = {}) @options = @user = .fetch(:user) end |
Instance Method Details
#run(host, command) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ridley/ssh/worker.rb', line 19 def run(host, command) response = Response.new("", "") debug "Running SSH command: '#{command}' on: '#{host}' as: '#{user}'" Net::SSH.start(host, user, ) do |ssh| ssh.open_channel do |channel| channel.exec(command) do |ch, success| unless success raise "FAILURE: could not execute command" end channel.on_data do |ch, data| response.stdout += data end channel.on_extended_data do |ch, type, data| response.stderr += data end channel.on_request("exit-status") do |ch, data| response.exit_code = data.read_long end channel.on_request("exit-signal") do |ch, data| response.exit_signal = data.read_string end end end ssh.loop end case response.exit_code when 0 debug "Successfully ran SSH command: '#{command}' on: '#{host}' as: '#{user}' and it succeeded" [ :ok, response ] else debug "Successfully ran SSH command: '#{command}' on: '#{host}' as: '#{user}' but it failed" [ :error, response ] end rescue => e debug "Failed to run SSH command: '#{command}' on: '#{host}' as: '#{user}'" [ :error, e. ] end |