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.
|
# environment.
|
||||||
register(:start, Builder.new do
|
register(:start, Builder.new do
|
||||||
use VM::CleanMachineFolder
|
use VM::CleanMachineFolder
|
||||||
use VM::Customize
|
|
||||||
use VM::ClearForwardedPorts
|
use VM::ClearForwardedPorts
|
||||||
use VM::ForwardPorts
|
use VM::ForwardPorts
|
||||||
use VM::Provision
|
use VM::Provision
|
||||||
|
@ -23,6 +22,7 @@ module Vagrant
|
||||||
use VM::ShareFolders
|
use VM::ShareFolders
|
||||||
use VM::HostName
|
use VM::HostName
|
||||||
use VM::Network
|
use VM::Network
|
||||||
|
use VM::Customize
|
||||||
use VM::Boot
|
use VM::Boot
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
@ -103,16 +103,15 @@ 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.
|
||||||
if @env["vm"].vm.network_adapters[adapter].attachment_type == :nat
|
@env["config"].vm.customize do |vm|
|
||||||
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes))
|
if @env["vm"].vm.network_adapters[adapter].attachment_type == :nat
|
||||||
forward_port(name, options)
|
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.forwarding_entry", message_attributes))
|
||||||
else
|
forward_port(vm, name, options)
|
||||||
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.non_nat", message_attributes))
|
else
|
||||||
|
@env.ui.info(I18n.t("vagrant.actions.vm.forward_ports.non_nat", message_attributes))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@env["vm"].vm.save
|
|
||||||
@env["vm"].reload!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
|
@ -120,13 +119,13 @@ module Vagrant
|
||||||
#--------------------------------------------------------------
|
#--------------------------------------------------------------
|
||||||
|
|
||||||
# Forwards a port.
|
# Forwards a port.
|
||||||
def forward_port(name, options)
|
def forward_port(vm, name, options)
|
||||||
port = VirtualBox::NATForwardedPort.new
|
port = VirtualBox::NATForwardedPort.new
|
||||||
port.name = name
|
port.name = name
|
||||||
port.guestport = options[:guestport]
|
port.guestport = options[:guestport]
|
||||||
port.hostport = options[:hostport]
|
port.hostport = options[:hostport]
|
||||||
port.protocol = options[:protocol] || :tcp
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue