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.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/cloudflock/app/common/servers.rb', line 323 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 if retry_prompt('Unable to establish a connection.') raise end |