class Proclib::Commands::Ssh
Constants
- SSHError
Attributes
ssh_session[R]
Public Class Methods
new(ssh_session:, **args)
click to toggle source
Calls superclass method
Proclib::Commands::Base::new
# File lib/proclib/commands/ssh.rb, line 10 def initialize(ssh_session:, **args) @ssh_session = ssh_session super(**args) end
Public Instance Methods
cmdline()
click to toggle source
Calls superclass method
# File lib/proclib/commands/ssh.rb, line 36 def cmdline if !run_dir.nil? "cd #{run_dir}; #{super}" else super end end
spawn()
click to toggle source
# File lib/proclib/commands/ssh.rb, line 15 def spawn write_pipes open_channel do |channel| channel.exec(cmdline) do |_, success| raise SSHError, "Command Failed" unless success if !stdin.nil? while msg = stdin.read(STDIN_BUF_SIZE) channel.send_data(msg) end channel.eof! end end end end
wait()
click to toggle source
# File lib/proclib/commands/ssh.rb, line 32 def wait ssh_session.loop end
Private Instance Methods
open_channel() { |channel| ... }
click to toggle source
# File lib/proclib/commands/ssh.rb, line 48 def open_channel ssh_session.open_channel do |channel| channel.on_open_failed do |ch, code, desc, lang| raise SSHError, desc end channel.on_data {|_, data| write_pipes[:stdout].write(data) } channel.on_extended_data {|_, data| write_pipes[:stderr].write(data) } channel.on_request("exit-status") do |_, data| write_pipes.each {|k,v| v.close } @result = data.read_long end yield channel end end
write_pipes()
click to toggle source
# File lib/proclib/commands/ssh.rb, line 68 def write_pipes @write_pipes ||= %i(stdout stderr).map do |type| read, write = IO.pipe pipes[type] = read [type, write] end.to_h end