class SSHDSL

Public Class Methods

new(conn, logger) click to toggle source
# File lib/placer_dsl.rb, line 5
def initialize(conn, logger)
  @conn = conn
  @logger = logger
end

Public Instance Methods

exec(*command) click to toggle source
# File lib/placer_dsl.rb, line 10
def exec(*command)
  cmd = command.flatten.join(' ')
  @logger.log(:ssh_exec, "Executing command #{cmd} on remote")
  @conn.exec!(cmd) do |channel, stream, data|
    {:stdout => :ssh_info, :stderr => :ssh_error}.each do |s, l|
      data.lines.each{ |d| @logger.log(l, d) if stream == s }
    end

    channel.on_request("exit-status") do |ch, data|
      exit_code = data.read_long
      raise "remote command: \"#{cmd}\" returned with non-zero exit code: #{exit_code}" if exit_code != 0
    end
  end
end