Sha256: e7245ef3d6d8a5480ea2754eed2b980fd3d6b96a190aacf4d0986445cb360b23

Contents?: true

Size: 1.2 KB

Versions: 17

Compression:

Stored size: 1.2 KB

Contents

module Cloner::SSH
  extend ActiveSupport::Concern

  def ssh_opts
    {}
  end

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

  # http://stackoverflow.com/questions/3386233/how-to-get-exit-status-with-rubys-netssh-library
  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

  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
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
cloner-0.13.0 lib/cloner/ssh.rb
cloner-0.12.0 lib/cloner/ssh.rb
cloner-0.11.0 lib/cloner/ssh.rb
cloner-0.10.0 lib/cloner/ssh.rb
cloner-0.9.2 lib/cloner/ssh.rb
cloner-0.9.1 lib/cloner/ssh.rb
cloner-0.9.0 lib/cloner/ssh.rb
cloner-0.8.0 lib/cloner/ssh.rb
cloner-0.7.0 lib/cloner/ssh.rb
cloner-0.6.1 lib/cloner/ssh.rb
cloner-0.6.0 lib/cloner/ssh.rb
cloner-0.5.7 lib/cloner/ssh.rb
cloner-0.5.6 lib/cloner/ssh.rb
cloner-0.5.5 lib/cloner/ssh.rb
cloner-0.5.4 lib/cloner/ssh.rb
cloner-0.5.3 lib/cloner/ssh.rb
cloner-0.5.2 lib/cloner/ssh.rb