Move port forwarding into customize block to run in a single VM lock.
This commit is contained in:
parent
17e86c40fc
commit
1ecd04e0ac
|
@ -14,7 +14,6 @@ module Vagrant
|
|||
# environment.
|
||||
register(:start, Builder.new do
|
||||
use VM::CleanMachineFolder
|
||||
use VM::Customize
|
||||
use VM::ClearForwardedPorts
|
||||
use VM::ForwardPorts
|
||||
use VM::Provision
|
||||
|
@ -23,6 +22,7 @@ module Vagrant
|
|||
use VM::ShareFolders
|
||||
use VM::HostName
|
||||
use VM::Network
|
||||
use VM::Customize
|
||||
use VM::Boot
|
||||
end)
|
||||
|
||||
|
|
|
@ -103,16 +103,15 @@ module Vagrant
|
|||
# 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
|
||||
# attachment types has uncertain behaviour.
|
||||
if @env["vm"].vm.network_adapters[adapter].attachment_type == :nat
|
||||
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes))
|
||||
forward_port(name, options)
|
||||
else
|
||||
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.non_nat", message_attributes))
|
||||
@env["config"].vm.customize do |vm|
|
||||
if @env["vm"].vm.network_adapters[adapter].attachment_type == :nat
|
||||
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes))
|
||||
forward_port(vm, name, options)
|
||||
else
|
||||
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.non_nat", message_attributes))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@env["vm"].vm.save
|
||||
@env["vm"].reload!
|
||||
end
|
||||
|
||||
#--------------------------------------------------------------
|
||||
|
@ -120,13 +119,13 @@ module Vagrant
|
|||
#--------------------------------------------------------------
|
||||
|
||||
# Forwards a port.
|
||||
def forward_port(name, options)
|
||||
def forward_port(vm, name, options)
|
||||
port = VirtualBox::NATForwardedPort.new
|
||||
port.name = name
|
||||
port.guestport = options[:guestport]
|
||||
port.hostport = options[:hostport]
|
||||
port.protocol = options[:protocol] || :tcp
|
||||
@env["vm"].vm.network_adapters[options[:adapter]].nat_driver.forwarded_ports << port
|
||||
vm.network_adapters[options[:adapter]].nat_driver.forwarded_ports << port
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue