Method: CloudFlock::App::Common#ssh_connect
- Defined in:
- lib/cloudflock/app/common/servers.rb
#ssh_connect(host, attempts = 5) ⇒ Object
Public: Connect to a host via SSH, automatically retrying a set number of times, and prompting whether to continue trying beyond that.
host - Hash containing information about the host. Defaults are
defined in the CloudFlock::Remote::SSH Class.
attempts - Number of times to retry connecting before alerting the user
to failures and asking whether to continue. (Default: 5)
Returns an SSH Object.
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/cloudflock/app/common/servers.rb', line 388 def ssh_connect(host, attempts = 5) attempt = 0 UI.spinner("Logging in to #{host[:hostname]}") do begin SSH.new(host) rescue Net::SSH::Disconnect sleep 10 attempt += 1 retry if attempt < 5 end end rescue Net::SSH::Disconnect retry_exit('Unable to establish a connection.') retry rescue Errno::ECONNREFUSED retry_exit("Connection refused from #{host[:hostname]}") retry rescue ArgumentError retry_exit('Incorrect passphrase provided for ssh key.') host.delete(:passphrase) check_option_pw(host, :passphrase, "Key passphrase", default_answer: '', allow_empty: true) end |