Method: Beaker::SshConnection#connect

Defined in:
lib/beaker/ssh_connection.rb

#connect(options = {}) ⇒ Object

Connect to the host, creating a new connection if required

Parameters:

  • options (Hash{Symbol=>String}) (defaults to: {})

    Options hash to control method conditionals

Options Hash (options):



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/beaker/ssh_connection.rb', line 99

def connect options = {}
  # Try three ways to connect to host (vmhostname, ip, hostname)
  # Try each method in turn until we succeed
  methods = @ssh_connection_preference.dup
  while (not @ssh) && (not methods.empty?) do
    unless instance_variable_get("@#{methods[0]}").nil?
      if SUPPORTED_CONNECTION_METHODS.include?(methods[0])
        @ssh = connect_block(instance_variable_get("@#{methods[0].to_s}"), @user, @ssh_opts, options)
      else
        @logger.warn "Beaker does not support #{methods[0]} to SSH to host, trying next available method."
        @ssh_connection_preference.delete(methods[0])
      end
    else
      @logger.warn "Skipping #{methods[0]} method to ssh to host as its value is not set. Refer to https://github.com/puppetlabs/beaker/tree/master/docs/how_to/ssh_connection_preference.md to remove this warning"
    end
    methods.shift
  end
  unless @ssh
    @logger.error "Failed to connect to #{@hostname}, attempted #{@ssh_connection_preference.join(', ')}"
    raise RuntimeError, "Cannot connect to #{@hostname}"
  end
  @ssh
end