Merge pull request #621 from bitprophet/clean-ssh-option
Allow 'vagrant ssh' to strip most non-port options.
This commit is contained in:
commit
a6c3551064
|
@ -14,6 +14,12 @@ module Vagrant
|
|||
opts.on("-c", "--command COMMAND", "Execute an SSH command directly.") do |c|
|
||||
options[:command] = c
|
||||
end
|
||||
opts.on(
|
||||
"-p",
|
||||
"Act more like vanilla 'ssh <vm>'"
|
||||
) do |p|
|
||||
options[:port_only] = p
|
||||
end
|
||||
end
|
||||
|
||||
argv = parse_options(opts)
|
||||
|
@ -29,7 +35,7 @@ module Vagrant
|
|||
if options[:command]
|
||||
ssh_execute(vm, options[:command])
|
||||
else
|
||||
ssh_connect(vm)
|
||||
ssh_connect(vm, {:port_only => options[:port_only]})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -63,9 +69,9 @@ module Vagrant
|
|||
exit exit_status
|
||||
end
|
||||
|
||||
def ssh_connect(vm)
|
||||
def ssh_connect(vm, opts)
|
||||
@logger.debug("`exec` into ssh prompt")
|
||||
vm.ssh.connect
|
||||
vm.ssh.connect(opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,9 @@ module Vagrant
|
|||
# Connects to the environment's virtual machine, replacing the ruby
|
||||
# process with an SSH process. This method optionally takes a hash
|
||||
# of options which override the configuration values.
|
||||
# One specific option, :port_only, if set to true, will cause this method
|
||||
# to skip filling in some default values, such as private_key_path and
|
||||
# username.
|
||||
def connect(opts={})
|
||||
if Util::Platform.windows?
|
||||
raise Errors::SSHUnavailableWindows, :key_path => private_key_path,
|
||||
|
@ -30,6 +33,7 @@ module Vagrant
|
|||
|
||||
raise Errors::SSHUnavailable if !Kernel.system("which ssh > /dev/null 2>&1")
|
||||
|
||||
port_only = opts[:port_only]
|
||||
options = {}
|
||||
options[:port] = port(opts)
|
||||
options[:private_key_path] = private_key_path
|
||||
|
@ -42,7 +46,8 @@ module Vagrant
|
|||
# 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"]
|
||||
"-o LogLevel=ERROR"]
|
||||
command_options << "-i #{options[:private_key_path]}" unless port_only
|
||||
command_options << "-o ForwardAgent=yes" if @vm.config.ssh.forward_agent
|
||||
|
||||
if @vm.config.ssh.forward_x11
|
||||
|
@ -51,7 +56,9 @@ module Vagrant
|
|||
command_options << "-o ForwardX11Trusted=yes"
|
||||
end
|
||||
|
||||
command = "ssh #{command_options.join(" ")} #{options[:username]}@#{options[:host]}".strip
|
||||
host_string = options[:host]
|
||||
host_string = "#{options[:username]}@" + host_string unless port_only
|
||||
command = "ssh #{command_options.join(" ")} #{host_string}".strip
|
||||
@logger.info("Invoking SSH: #{command}")
|
||||
safe_exec(command)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue