class Tengine::Job::Runtime::SshJob::ShellClient
Public Class Methods
new(channel, script, callback)
click to toggle source
# File lib/tengine/job/runtime/ssh_job.rb, line 69 def initialize(channel, script, callback) @channel, @script, @callback = channel, script, callback @status = :preparing # :preparing, :waiting, :exiting end
Public Instance Methods
dispatch(line)
click to toggle source
# File lib/tengine/job/runtime/ssh_job.rb, line 92 def dispatch(line) # puts "line: #{line.inspect}" case @status when :preparing then execute when :waiting then if line.strip == one_time_token returns else @result << line end when :exiting then # do nothing... else raise Error, "Unknown shell channel status: #{@status.inspect}" end end
execute()
click to toggle source
# File lib/tengine/job/runtime/ssh_job.rb, line 119 def execute actual = @script.force_encoding("binary") Tengine.logger.info("now exec on ssh: " << @script) # puts("now exec on ssh: " << @script) @result = "" @status = :waiting @channel.send_data(actual + "; echo \"#{one_time_token}\"\n") end
one_time_token()
click to toggle source
# File lib/tengine/job/runtime/ssh_job.rb, line 134 def one_time_token "one_time_token" end
prepare()
click to toggle source
# File lib/tengine/job/runtime/ssh_job.rb, line 113 def prepare cmd = "export PS1=;" Tengine.logger.info("now exec on ssh: \"#{cmd}\"") @channel.send_data("#{cmd}\n") end
returns()
click to toggle source
# File lib/tengine/job/runtime/ssh_job.rb, line 128 def returns @callback.call(@channel, @result) if @callback @status = :exiting @channel.send_data("exit\n") end
setup()
click to toggle source
# File lib/tengine/job/runtime/ssh_job.rb, line 74 def setup @data = "" @result = nil @channel.on_data do |ch, data| # puts "on_data: #{data.inspect}" @data << data Tengine.logger.info("got STDOUT data: #{data.inspect}") end @channel.on_process do |ch| while @data =~ %r!^.*?\n! @data = $' dispatch($&) end end end
start()
click to toggle source
# File lib/tengine/job/runtime/ssh_job.rb, line 109 def start prepare # execute, returnsはdispatchから呼ばれます end