diff --git a/config/default.rb b/config/default.rb index 1eb5251dd..d8559b894 100644 --- a/config/default.rb +++ b/config/default.rb @@ -13,6 +13,7 @@ Vagrant::Config.run do |config| config.ssh.timeout = 30 config.ssh.private_key_path = File.join(PROJECT_ROOT, 'keys', 'vagrant') + config.vm.auto_port_range = (2200..2250) config.vm.box_ovf = "box.ovf" config.vm.base_mac = "0800279C2E42" config.vm.project_directory = "/vagrant" diff --git a/lib/vagrant/actions/vm/forward_ports.rb b/lib/vagrant/actions/vm/forward_ports.rb index 1e9db059f..c0bd3accd 100644 --- a/lib/vagrant/actions/vm/forward_ports.rb +++ b/lib/vagrant/actions/vm/forward_ports.rb @@ -9,7 +9,7 @@ module Vagrant vm.forwarded_ports.each do |fp| @runner.env.config.vm.forwarded_ports.each do |name, options| if fp.hostport.to_s == options[:hostport].to_s - raise ActionException.new(:vm_port_collision, :name => name, :hostport => fp.hostport.to_s, :guestport => options[:guestport].to_s, :instance => options[:instance]) + raise ActionException.new(:vm_port_collision, :name => name, :hostport => fp.hostport.to_s, :guestport => options[:guestport].to_s, :adapter => options[:adapter]) end end end @@ -30,7 +30,7 @@ module Vagrant logger.info "Forwarding ports..." @runner.env.config.vm.forwarded_ports.each do |name, options| - adapter = options[:instance] + adapter = options[:adapter] # 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 diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index b10d2eb22..845774b82 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -77,6 +77,7 @@ module Vagrant class VMConfig < Base include Util::StackedProcRunner + attr_accessor :auto_port_range attr_accessor :box attr_accessor :box_ovf attr_accessor :base_mac @@ -102,13 +103,15 @@ module Vagrant @provisioner = nil end - def forward_port(name, guestport, hostport, protocol="TCP", instance=0) - forwarded_ports[name] = { + def forward_port(name, guestport, hostport, options=nil) + options = { :guestport => guestport, :hostport => hostport, - :protocol => protocol, - :instance => instance - } + :protocol => "TCP", + :adapter => 0 + }.merge(options || {}) + + forwarded_ports[name] = options end def share_folder(name, guestpath, hostpath = nil, opts = {}) diff --git a/test/vagrant/actions/vm/forward_ports_test.rb b/test/vagrant/actions/vm/forward_ports_test.rb index 1de0fb053..a9c6c0461 100644 --- a/test/vagrant/actions/vm/forward_ports_test.rb +++ b/test/vagrant/actions/vm/forward_ports_test.rb @@ -72,16 +72,16 @@ class ForwardPortsActionTest < Test::Unit::TestCase should "create a port forwarding for the VM" do forwarded_ports = mock("forwarded_ports") network_adapter = mock("network_adapter") - + @vm.expects(:network_adapters).returns([network_adapter]) network_adapter.expects(:attachment_type).returns(:nat) - + @mock_vm.env.config.vm.forwarded_ports.each do |name, opts| forwarded_ports.expects(:<<).with do |port| assert_equal name, port.name assert_equal opts[:hostport], port.hostport assert_equal opts[:guestport], port.guestport - assert_equal opts[:instance], port.instance + assert_equal opts[:adapter], port.instance true end end @@ -96,9 +96,9 @@ class ForwardPortsActionTest < Test::Unit::TestCase should "No port forwarding for non NAT interfaces" do forwarded_ports = mock("forwarded_ports") network_adapter = mock("network_adapter") - + @vm.expects(:network_adapters).returns([network_adapter]) - network_adapter.expects(:attachment_type).returns(:host_only) + network_adapter.expects(:attachment_type).returns(:host_only) @vm.expects(:save).once @action.forward_ports end