Change `instance` option to forwarding ports to `adapter` and make thoes options a hash at the end.

This commit is contained in:
Mitchell Hashimoto 2010-05-27 12:34:08 -07:00
parent 6f287aa17a
commit b174645fb7
4 changed files with 16 additions and 12 deletions

View File

@ -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"

View File

@ -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

View File

@ -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 = {})

View File

@ -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