Module: Cloner::SSH

Extended by:
ActiveSupport::Concern
Included in:
Internal
Defined in:
lib/cloner/ssh.rb

Instance Method Summary collapse

Instance Method Details

#check_ssh_err(ret) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/cloner/ssh.rb', line 46

def check_ssh_err(ret)
  if ret[2] != 0
    puts "Error: SSH command exited with #{ret[2]}"
    puts ret[0]
    puts ret[1]
    exit 1
  end
end

#do_ssh(&block) ⇒ Object



8
9
10
11
12
# File 'lib/cloner/ssh.rb', line 8

def do_ssh(&block)
  Net::SSH.start(ssh_host, ssh_user, ssh_opts) do |ssh|
    yield ssh
  end
end

#ssh_exec!(ssh, command) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cloner/ssh.rb', line 15

def ssh_exec!(ssh, command)
  stdout_data = ""
  stderr_data = ""
  exit_code = nil
  exit_signal = nil
  ssh.open_channel do |channel|
    channel.exec(command) do |ch, success|
      unless success
        abort "FAILED: couldn't execute command (ssh.channel.exec)"
      end
      channel.on_data do |ch,data|
        stdout_data+=data
      end

      channel.on_extended_data do |ch,type,data|
        stderr_data+=data
      end

      channel.on_request("exit-status") do |ch,data|
        exit_code = data.read_long
      end

      channel.on_request("exit-signal") do |ch, data|
        exit_signal = data.read_long
      end
    end
  end
  ssh.loop
  [stdout_data, stderr_data, exit_code, exit_signal]
end

#ssh_optsObject



4
5
6
# File 'lib/cloner/ssh.rb', line 4

def ssh_opts
  {}
end