Sha256: fde6b6856eac085f816b048210f25cfbe34abbc01417b25a328eaca2dbfbc502

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

module Meroku
  class Tunnel

    attr_accessor :ip, :username, :keys, :verify_host_key, :verbose

    def initialize(ip:,username:,keys:,verify_host_key:,verbose:)
      @ip = ip
      @username = username
      @keys = keys
      @verify_host_key = verify_host_key
      @verbose = verbose
    end

    def run(cmd)
      @verbose=true
      retries ||= 0
      Net::SSH.start(@ip,
                     @username,
                     password: 'password',
                     keys: @keys,
                     verify_host_key: @verify_host_key,
                     timeout: 90) do |ssh|
        channel = ssh.open_channel do |ch|
          STDERR.print cmd
          ch.exec cmd do |ch, success|
            raise "could not execute command" unless success
            ch.on_data do |c, data|
              if @verbose
                $stdout.print data
              else
                $stdout.print "."
              end
            end
            ch.on_extended_data do |c, type, data|
              if @verbose
                $stderr.print data
              else
                $stderr.print "."
              end
            end
            ch.on_close { print "\n" }
          end
        end
        channel.wait
      end
    rescue Errno::ECONNREFUSED => e
      retry if (retries += 1) < 10
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
meroku-2.0.7 lib/meroku/tunnel.rb
meroku-2.0.6 lib/meroku/tunnel.rb
meroku-2.0.5 lib/meroku/tunnel.rb
meroku-2.0.4 lib/meroku/tunnel.rb
meroku-2.0.3 lib/meroku/tunnel.rb
meroku-2.0.2 lib/meroku/tunnel.rb
meroku-2.0.1 lib/meroku/tunnel.rb