class Bcome::Ssh::CommandExec
Attributes
commands[R]
Public Class Methods
new(commands)
click to toggle source
# File lib/objects/ssh/command_exec.rb, line 7 def initialize(commands) @commands = commands end
Public Instance Methods
execute!()
click to toggle source
# File lib/objects/ssh/command_exec.rb, line 25 def execute! @commands.each do |command| node = command.node ssh = node.ssh_driver.ssh_connection begin ssh_exec!(ssh, command) rescue IOError # Typically occurs after a timeout if the session has been left idle node.reopen_ssh_connection ssh = node.ssh_driver.ssh_connection ssh_exec!(ssh, command) # retry, once end output_append("\n(#{node.namespace})$".terminal_prompt + ">\s#{command.raw}\n") output_append(command.output.to_s) end print_output unless ::Bcome::Orchestrator.instance.command_output_silenced? || ::Bcome::Orchestrator.instance.tail_all_command_output? end
log_window()
click to toggle source
# File lib/objects/ssh/command_exec.rb, line 15 def log_window ::Bcome::Ssh::Window.instance end
output_append(output_string)
click to toggle source
# File lib/objects/ssh/command_exec.rb, line 11 def output_append(output_string) @output_string = "#{@output_string}#{output_string}" end
print_output()
click to toggle source
# File lib/objects/ssh/command_exec.rb, line 19 def print_output print "#{@output_string}\n\n" rescue StandardError => e puts "Could not print #{@output_string.inspect}" end
ssh_exec!(ssh, command)
click to toggle source
# File lib/objects/ssh/command_exec.rb, line 45 def ssh_exec!(ssh, command) # NON PTY (i.e no pseudo-terminal) ssh.open_channel do |channel| channel.exec(command.raw) do |_cha, success| abort "FAILED: couldn't execute command (ssh.channel.exec)" unless success channel.on_data do |_ch, data| log_window.add(command.node, data) if ::Bcome::Orchestrator.instance.tail_all_command_output? command.stdout += data end channel.on_extended_data do |_ch, _type, data| command.stderr += data end channel.on_request('exit-status') do |_ch, data| command.exit_code = data.read_long end channel.on_request('exit-signal') do |_ch, data| command.exit_code = data.read_long end end end ssh.loop end