providers/docker: `vagrant ssh` proxies through the host VM
This commit is contained in:
parent
aa1abdd1c4
commit
e714720052
|
@ -162,6 +162,8 @@ module VagrantPlugins
|
||||||
b3.use Message, I18n.t("docker_provider.messages.not_running")
|
b3.use Message, I18n.t("docker_provider.messages.not_running")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
b3.use PrepareSSH
|
||||||
b3.use SSHExec
|
b3.use SSHExec
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -222,6 +224,7 @@ module VagrantPlugins
|
||||||
autoload :ForwardPorts, action_root.join("forward_ports")
|
autoload :ForwardPorts, action_root.join("forward_ports")
|
||||||
autoload :HasSSH, action_root.join("has_ssh")
|
autoload :HasSSH, action_root.join("has_ssh")
|
||||||
autoload :HostMachine, action_root.join("host_machine")
|
autoload :HostMachine, action_root.join("host_machine")
|
||||||
|
autoload :PrepareSSH, action_root.join("prepare_ssh")
|
||||||
autoload :Stop, action_root.join("stop")
|
autoload :Stop, action_root.join("stop")
|
||||||
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")
|
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")
|
||||||
autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
|
autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
module VagrantPlugins
|
||||||
|
module DockerProvider
|
||||||
|
module Action
|
||||||
|
class PrepareSSH
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
# If we aren't using a host VM, then don't worry about it
|
||||||
|
return @app.call(env) if !env[:machine].provider.host_vm?
|
||||||
|
|
||||||
|
# Get the container's SSH info
|
||||||
|
info = env[:machine].ssh_info
|
||||||
|
info[:port] ||= 22
|
||||||
|
|
||||||
|
# Modify the SSH info to be the host VM's info
|
||||||
|
env[:ssh_info] = env[:machine].provider.host_vm.ssh_info
|
||||||
|
|
||||||
|
# Modify the SSH options for when we `vagrant ssh`...
|
||||||
|
ssh_opts = env[:ssh_opts] || {}
|
||||||
|
|
||||||
|
# Append "-t" to force a TTY allocation
|
||||||
|
ssh_opts[:extra_args] = Array(ssh_opts[:extra_args])
|
||||||
|
ssh_opts[:extra_args] << "-t"
|
||||||
|
|
||||||
|
# Append our real SSH command
|
||||||
|
ssh_opts[:extra_args] <<
|
||||||
|
"ssh -i /home/vagrant/insecure " +
|
||||||
|
"-p#{info[:port]} " +
|
||||||
|
"#{info[:username]}@#{info[:host]}"
|
||||||
|
|
||||||
|
# Set the opts
|
||||||
|
env[:ssh_opts] = ssh_opts
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -123,21 +123,17 @@ module VagrantPlugins
|
||||||
|
|
||||||
# Returns the SSH info for accessing the Container.
|
# Returns the SSH info for accessing the Container.
|
||||||
def ssh_info
|
def ssh_info
|
||||||
# If the Container is not created then we cannot possibly SSH into it, so
|
# If the container isn't running, we can't SSH into it
|
||||||
# we return nil.
|
return nil if state.id != :running
|
||||||
return nil if state == :not_created
|
|
||||||
|
|
||||||
network = driver.inspect_container(@machine.id)['NetworkSettings']
|
network = driver.inspect_container(@machine.id)['NetworkSettings']
|
||||||
ip = network['IPAddress']
|
ip = network['IPAddress']
|
||||||
|
|
||||||
# If we were not able to identify the container's IP, we return nil
|
# If we were not able to identify the container's IP, we return nil
|
||||||
# here and we let Vagrant core deal with it ;)
|
# here and we let Vagrant core deal with it ;)
|
||||||
return nil unless ip
|
return nil if !ip
|
||||||
|
|
||||||
{
|
{ host: ip }
|
||||||
:host => ip,
|
|
||||||
:port => @machine.config.ssh.guest_port
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def state
|
def state
|
||||||
|
|
Loading…
Reference in New Issue