class Aerosol::Connection
Public Instance Methods
with_connection(overridden_host=nil, &block)
click to toggle source
# File lib/aerosol/connection.rb, line 11 def with_connection(overridden_host=nil, &block) actual_host = overridden_host || host unless actual_host.is_a?(String) actual_host = actual_host.address end if jump info "connecting to gateway #{jump[:user] || user}@#{jump[:host]}" gateway = nil Timeout.timeout(20) do gateway = Net::SSH::Gateway.new(jump[:host], jump[:user] || user, :forward_agent => true) end begin info "connecting to #{user}@#{actual_host} through gateway" gateway.ssh(actual_host, user, &block) ensure info "shutting down gateway connection" gateway.shutdown! end else info "connecting to #{user}@#{actual_host}" Net::SSH.start(actual_host, user, &block) end rescue Timeout::Error => ex error "Timeout error #{ex.message}" error ex.backtrace.join("\n") end