Improved lock-reducing of forwarded ports action
This commit is contained in:
parent
2492f479d5
commit
268f7f7bc2
|
@ -83,14 +83,15 @@ module Vagrant
|
||||||
def call(env)
|
def call(env)
|
||||||
@env = env
|
@env = env
|
||||||
|
|
||||||
forward_ports
|
@env["config"].vm.customize do |vm|
|
||||||
|
@env.ui.info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
|
||||||
|
forward_ports(vm)
|
||||||
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def forward_ports
|
def forward_ports(vm)
|
||||||
@env.ui.info I18n.t("vagrant.actions.vm.forward_ports.forwarding")
|
|
||||||
|
|
||||||
@env.env.config.vm.forwarded_ports.each do |name, options|
|
@env.env.config.vm.forwarded_ports.each do |name, options|
|
||||||
adapter = options[:adapter]
|
adapter = options[:adapter]
|
||||||
message_attributes = {
|
message_attributes = {
|
||||||
|
@ -103,8 +104,7 @@ module Vagrant
|
||||||
# Assuming the only reason to establish port forwarding is because the VM is using Virtualbox NAT networking.
|
# Assuming the only reason to establish port forwarding is because the VM is using Virtualbox NAT networking.
|
||||||
# Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these
|
# Host-only or Bridged networking don't require port-forwarding and establishing forwarded ports on these
|
||||||
# attachment types has uncertain behaviour.
|
# attachment types has uncertain behaviour.
|
||||||
@env["config"].vm.customize do |vm|
|
if vm.network_adapters[adapter].attachment_type == :nat
|
||||||
if @env["vm"].vm.network_adapters[adapter].attachment_type == :nat
|
|
||||||
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes))
|
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes))
|
||||||
forward_port(vm, name, options)
|
forward_port(vm, name, options)
|
||||||
else
|
else
|
||||||
|
@ -112,7 +112,6 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
# General Helpers
|
# General Helpers
|
||||||
|
|
|
@ -123,6 +123,7 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
|
||||||
context "calling" do
|
context "calling" do
|
||||||
should "clear all previous ports and forward new ports" do
|
should "clear all previous ports and forward new ports" do
|
||||||
exec_seq = sequence("exec_seq")
|
exec_seq = sequence("exec_seq")
|
||||||
|
@env["config"].vm.expects(:customize).yields(@internal_vm).in_sequence(exec_seq)
|
||||||
@instance.expects(:forward_ports).once.in_sequence(exec_seq)
|
@instance.expects(:forward_ports).once.in_sequence(exec_seq)
|
||||||
@app.expects(:call).once.with(@env).in_sequence(exec_seq)
|
@app.expects(:call).once.with(@env).in_sequence(exec_seq)
|
||||||
@instance.call(@env)
|
@instance.call(@env)
|
||||||
|
@ -144,8 +145,7 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
@instance.expects(:forward_port).once
|
@instance.expects(:forward_port).once
|
||||||
|
|
||||||
@env["config"].vm.stubs(:customize).yields(@internal_vm)
|
@instance.forward_ports(@internal_vm)
|
||||||
@instance.forward_ports
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not port forward for non NAT interfaces" do
|
should "not port forward for non NAT interfaces" do
|
||||||
|
@ -155,8 +155,7 @@ class ForwardPortsVMActionTest < Test::Unit::TestCase
|
||||||
@internal_vm.expects(:network_adapters).returns([network_adapter])
|
@internal_vm.expects(:network_adapters).returns([network_adapter])
|
||||||
network_adapter.expects(:attachment_type).returns(:host_only)
|
network_adapter.expects(:attachment_type).returns(:host_only)
|
||||||
|
|
||||||
@env["config"].vm.stubs(:customize).yields(@internal_vm)
|
@instance.forward_ports(@internal_vm)
|
||||||
@instance.forward_ports
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue