parent
c7087a6802
commit
e68e4f8f05
2 changed files with 12 additions and 6 deletions
|
@ -35,8 +35,6 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def forward_ports
|
def forward_ports
|
||||||
@container_ip = @env[:machine].provider.driver.assigned_ip
|
|
||||||
|
|
||||||
@env[:forwarded_ports].each do |fp|
|
@env[:forwarded_ports].each do |fp|
|
||||||
message_attributes = {
|
message_attributes = {
|
||||||
# TODO: Add support for multiple adapters
|
# TODO: Add support for multiple adapters
|
||||||
|
@ -49,7 +47,12 @@ module Vagrant
|
||||||
@env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
|
@env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry",
|
||||||
message_attributes))
|
message_attributes))
|
||||||
|
|
||||||
redir_pid = redirect_port(fp[:host], fp[:guest])
|
redir_pid = redirect_port(
|
||||||
|
fp[:host_ip] || "127.0.0.1",
|
||||||
|
fp[:host],
|
||||||
|
fp[:guest_ip] || @env[:machine].provider.driver.assigned_ip,
|
||||||
|
fp[:guest]
|
||||||
|
)
|
||||||
store_redir_pid(fp[:host], redir_pid)
|
store_redir_pid(fp[:host], redir_pid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -68,8 +71,9 @@ module Vagrant
|
||||||
mappings.values
|
mappings.values
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_port(host, guest)
|
def redirect_port(host_ip, host_port, guest_ip, guest_port)
|
||||||
redir_cmd = "sudo redir --laddr=127.0.0.1 --lport=#{host} --cport=#{guest} --caddr=#{@container_ip} 2>/dev/null"
|
host_ip = "--laddr=#{host_ip}" unless host_ip.empty?
|
||||||
|
redir_cmd = "sudo redir #{host_ip} --lport=#{host_port} --caddr=#{guest_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
|
|
||||||
@logger.debug "Forwarding port with `#{redir_cmd}`"
|
@logger.debug "Forwarding port with `#{redir_cmd}`"
|
||||||
spawn redir_cmd
|
spawn redir_cmd
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
require 'unit_helper'
|
require 'unit_helper'
|
||||||
|
|
||||||
|
require 'tmpdir'
|
||||||
|
require 'vagrant-lxc/errors'
|
||||||
require 'vagrant-lxc/action/forward_ports'
|
require 'vagrant-lxc/action/forward_ports'
|
||||||
|
|
||||||
describe Vagrant::LXC::Action::ForwardPorts do
|
describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
|
@ -31,7 +33,7 @@ describe Vagrant::LXC::Action::ForwardPorts do
|
||||||
subject.stub(system: true)
|
subject.stub(system: true)
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
subject.should have_received(:spawn).with(
|
subject.should have_received(:spawn).with(
|
||||||
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --cport=#{guest_port} --caddr=#{container_ip} 2>/dev/null"
|
"sudo redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue