Class: Vagrant::SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/cuken/api/vagrant.rb

Instance Method Summary collapse

Instance Method Details

#ssh_connect_command(opts = {}) ⇒ Object

In order to run Aruba’s ‘When I type “…”’ steps: Returns a Vagrant SSH connection string for the environment’s virtual machine, This method optionally takes a hash of options which override the configuration values.

Raises:

  • (Errors::SSHUnavailable)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cuken/api/vagrant.rb', line 51

def ssh_connect_command(opts={})
 if Mario::Platform.windows?
   raise Errors::SSHUnavailableWindows, :key_path => env.config.ssh.private_key_path,
                                        :ssh_port => port(opts)
 end

 raise Errors::SSHUnavailable if !Kernel.system("which ssh > /dev/null 2>&1")

 options = {}
 options[:port] = port(opts)
 [:host, :username, :private_key_path].each do |param|
   options[param] = opts[param] || env.config.ssh.send(param)
 end

 check_key_permissions(options[:private_key_path])

 # Command line options
 command_options = ["-p #{options[:port]}", "-o UserKnownHostsFile=/dev/null",
                    "-o StrictHostKeyChecking=no", "-o IdentitiesOnly=yes",
                    "-i #{options[:private_key_path]}", "-o LogLevel=ERROR"]
 command_options << "-o ForwardAgent=yes" if env.config.ssh.forward_agent

 if env.config.ssh.forward_x11
   # Both are required so that no warnings are shown regarding X11
   command_options << "-o ForwardX11=yes"
   command_options << "-o ForwardX11Trusted=yes"
 end

 "ssh #{command_options.join(" ")} #{options[:username]}@#{options[:host]}".strip
end