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.timeout = 30
config.ssh.private_key_path = File.join(PROJECT_ROOT, 'keys', 'vagrant') 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.box_ovf = "box.ovf"
config.vm.base_mac = "0800279C2E42" config.vm.base_mac = "0800279C2E42"
config.vm.project_directory = "/vagrant" config.vm.project_directory = "/vagrant"

View File

@ -9,7 +9,7 @@ module Vagrant
vm.forwarded_ports.each do |fp| vm.forwarded_ports.each do |fp|
@runner.env.config.vm.forwarded_ports.each do |name, options| @runner.env.config.vm.forwarded_ports.each do |name, options|
if fp.hostport.to_s == options[:hostport].to_s 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 end
end end
@ -30,7 +30,7 @@ module Vagrant
logger.info "Forwarding ports..." logger.info "Forwarding ports..."
@runner.env.config.vm.forwarded_ports.each do |name, options| @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. # 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

View File

@ -77,6 +77,7 @@ module Vagrant
class VMConfig < Base class VMConfig < Base
include Util::StackedProcRunner include Util::StackedProcRunner
attr_accessor :auto_port_range
attr_accessor :box attr_accessor :box
attr_accessor :box_ovf attr_accessor :box_ovf
attr_accessor :base_mac attr_accessor :base_mac
@ -102,13 +103,15 @@ module Vagrant
@provisioner = nil @provisioner = nil
end end
def forward_port(name, guestport, hostport, protocol="TCP", instance=0) def forward_port(name, guestport, hostport, options=nil)
forwarded_ports[name] = { options = {
:guestport => guestport, :guestport => guestport,
:hostport => hostport, :hostport => hostport,
:protocol => protocol, :protocol => "TCP",
:instance => instance :adapter => 0
} }.merge(options || {})
forwarded_ports[name] = options
end end
def share_folder(name, guestpath, hostpath = nil, opts = {}) def share_folder(name, guestpath, hostpath = nil, opts = {})

View File

@ -81,7 +81,7 @@ class ForwardPortsActionTest < Test::Unit::TestCase
assert_equal name, port.name assert_equal name, port.name
assert_equal opts[:hostport], port.hostport assert_equal opts[:hostport], port.hostport
assert_equal opts[:guestport], port.guestport assert_equal opts[:guestport], port.guestport
assert_equal opts[:instance], port.instance assert_equal opts[:adapter], port.instance
true true
end end
end end