Class: Cindy::Executor::SSH
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #exec_imp(command, stdin_str) ⇒ Object
-
#initialize(uri, logger) ⇒ SSH
constructor
A new instance of SSH.
Methods inherited from Base
Constructor Details
#initialize(uri, logger) ⇒ SSH
Returns a new instance of SSH.
11 12 13 14 |
# File 'lib/cindy/executor/ssh.rb', line 11 def initialize(uri, logger) @cnx = Net::SSH.start(uri.host, uri.user) super logger end |
Class Method Details
.handle?(uri) ⇒ Boolean
7 8 9 |
# File 'lib/cindy/executor/ssh.rb', line 7 def self.handle?(uri) 'ssh' == uri.scheme end |
Instance Method Details
#close ⇒ Object
38 39 40 |
# File 'lib/cindy/executor/ssh.rb', line 38 def close @cnx.close end |
#exec_imp(command, stdin_str) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cindy/executor/ssh.rb', line 16 def exec_imp(command, stdin_str) exit_status = 1 stdout_str = stderr_str = '' @cnx.open_channel do |channel| channel.exec(command) do |ch, success| channel.on_data do |ch, data| stdout_str += data end channel.on_extended_data do |ch, type, data| stderr_str += data end channel.on_request 'exit-status' do |ch, data| exit_status = data.read_long end channel.send_data stdin_str.force_encoding('ASCII-8BIT') if stdin_str channel.eof! end end @cnx.loop [ stdout_str, stderr_str, exit_status ] end |