Method: Configure#ssh_connect_to

Defined in:
lib/maws/commands/configure.rb

#ssh_connect_to(instance) ⇒ Object

Raises:

  • (ArgumentError)


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/maws/commands/configure.rb', line 93

def ssh_connect_to(instance)
  host = options.hostname || instance.dns_name
  user = options.

  identity_file = options.identity_file || File.join(KEYPAIRS_PATH, "#{instance.keypair}.pem")
  raise ArgumentError.new("Missing identity file: #{identity_file}") if !File.exists?(identity_file)

  info "connecting to '#{user}@#{host}'..."

  3.times { # retry on host unreachable errors
    begin
      return Net::SSH.start(host, user, { :keys => [identity_file], :verbose => :warn, :auth_methods => ["publickey"], :keys_only => true })
    rescue Errno::EHOSTUNREACH
      sleep 2
    end
  }
end