Class: Vagrant::Action::Builtin::SSHExec

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/vagrant/action/builtin/ssh_exec.rb

Overview

This class will exec into a full fledged SSH console into the remote machine. This middleware assumes that the VM is running and ready for SSH, and uses the Machine#ssh_info method to retrieve SSH information necessary to connect.

Note: If there are any middleware after ‘SSHExec`, they will not run, since exec replaces the currently running process.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SSHExec

Returns a new instance of SSHExec.



19
20
21
# File 'lib/vagrant/action/builtin/ssh_exec.rb', line 19

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vagrant/action/builtin/ssh_exec.rb', line 23

def call(env)
  # Grab the SSH info from the machine
  info = env[:machine].ssh_info

  # If the result is nil, then the machine is telling us that it is
  # not yet ready for SSH, so we raise this exception.
  raise Errors::SSHNotReady if info.nil?

  if info[:private_key_path]
    # Check the SSH key permissions
    SSH.check_key_permissions(Pathname.new(info[:private_key_path]))
  end

  # Exec!
  SSH.exec(info, env[:ssh_opts])
end