Class: SSHDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/placer_dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(conn, logger) ⇒ SSHDSL

Returns a new instance of SSHDSL.



5
6
7
8
# File 'lib/placer_dsl.rb', line 5

def initialize(conn, logger)
  @conn = conn
  @logger = logger
end

Instance Method Details

#exec(*command) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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