Forwarded ports no longer require a name paramter

This commit is contained in:
Mitchell Hashimoto 2012-01-03 10:18:10 -08:00
parent aac9bb5ec5
commit 2d1ed88bcd
5 changed files with 32 additions and 7 deletions

View File

@ -4,6 +4,7 @@
of argument. Previously where you had `config.vm.network "33.33.33.10"` you
should now put `config.vm.network :hostonly, "33.33.33.10"`. This is in order
to support bridged networking, as well.
- `config.vm.forward_port` no longer requires a name parameter.
- Bridged networking. `config.vm.network` with `:bridged` as the option will
setup a bridged network.
- `config.vm.customize` now takes a command to send to `VBoxManage`, so any

View File

@ -16,7 +16,7 @@ Vagrant::Config.run do |config|
config.vm.auto_port_range = (2200..2250)
config.vm.box_url = nil
config.vm.base_mac = nil
config.vm.forward_port("ssh", 22, 2222, :auto => true)
config.vm.forward_port 22, 2222, :name => "ssh", :auto => true
config.vm.boot_mode = "headless"
config.vm.guest = :linux

View File

@ -33,13 +33,13 @@ module Vagrant
end
def forward_ports(vm)
counter = 0
ports = []
interfaces = @env[:vm].driver.read_network_interfaces
@env[:vm].config.vm.forwarded_ports.each do |name, options|
message_attributes = {
:name => name,
:guest_port => options[:guestport],
:host_port => options[:hostport],
:adapter => options[:adapter]
@ -54,14 +54,23 @@ module Vagrant
# Port forwarding requires the network interface to be a NAT interface,
# so verify that that is the case.
if interfaces[adapter][:type] != :nat
if interfaces[options[:adapter]][:type] != :nat
@env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.non_nat",
message_attributes))
next
end
# VirtualBox requires a unique name for the forwarded port, so we
# will give it one.
name = options[:name]
if !name
# Auto-generate the name based on a counter of every forwarded port
name = "fp#{counter}"
counter += 1
end
# Add the options to the ports array to send to the driver later
ports << options.merge(:name => name, :adapter => adapter)
ports << options.merge(:name => name, :adapter => options[:adapter])
end
@env[:vm].driver.forward_ports(ports)

View File

@ -26,12 +26,26 @@ module Vagrant
@customizations = []
end
def forward_port(name, guestport, hostport, options=nil)
def forward_port(guestport, hostport, options=nil)
if !guestport.kind_of?(Integer)
raise Errors::DeprecationError, :message => <<-MESSAGE
`config.vm.forward_port` changed in 0.9.0 where the required name
argument is now removed. Vagrant will now automatically generate
a unique name for your forwarded port. For example, to forward
port 80 to port 8080 you now do the following:
config.vm.forward_port 80, 8080
Please change your configurations to match this new syntax.
MESSAGE
end
options = {
:name => nil,
:guestport => guestport,
:hostport => hostport,
:protocol => :tcp,
:adapter => 0,
:adapter => 1,
:auto => false
}.merge(options || {})

View File

@ -369,7 +369,8 @@ en:
fixed_collision: Fixed port collision '%{name}'. Now on port %{new_port}.
forwarding: Forwarding ports...
forwarding_entry: "-- %{name}: %{guest_port} => %{host_port} (adapter %{adapter})"
forwarding_entry: |-
-- %{guest_port} => %{host_port} (adapter %{adapter})
non_nat: |-
VirtualBox adapter #%{adapter} not configured as "NAT". Skipping: '%{name}'.
privileged_ports: |-