Change `instance` option to forwarding ports to `adapter` and make thoes options a hash at the end.
This commit is contained in:
parent
6f287aa17a
commit
b174645fb7
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 = {})
|
||||||
|
|
|
@ -72,16 +72,16 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
should "create a port forwarding for the VM" do
|
should "create a port forwarding for the VM" do
|
||||||
forwarded_ports = mock("forwarded_ports")
|
forwarded_ports = mock("forwarded_ports")
|
||||||
network_adapter = mock("network_adapter")
|
network_adapter = mock("network_adapter")
|
||||||
|
|
||||||
@vm.expects(:network_adapters).returns([network_adapter])
|
@vm.expects(:network_adapters).returns([network_adapter])
|
||||||
network_adapter.expects(:attachment_type).returns(:nat)
|
network_adapter.expects(:attachment_type).returns(:nat)
|
||||||
|
|
||||||
@mock_vm.env.config.vm.forwarded_ports.each do |name, opts|
|
@mock_vm.env.config.vm.forwarded_ports.each do |name, opts|
|
||||||
forwarded_ports.expects(:<<).with do |port|
|
forwarded_ports.expects(:<<).with do |port|
|
||||||
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
|
||||||
|
@ -96,9 +96,9 @@ class ForwardPortsActionTest < Test::Unit::TestCase
|
||||||
should "No port forwarding for non NAT interfaces" do
|
should "No port forwarding for non NAT interfaces" do
|
||||||
forwarded_ports = mock("forwarded_ports")
|
forwarded_ports = mock("forwarded_ports")
|
||||||
network_adapter = mock("network_adapter")
|
network_adapter = mock("network_adapter")
|
||||||
|
|
||||||
@vm.expects(:network_adapters).returns([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
|
@vm.expects(:save).once
|
||||||
@action.forward_ports
|
@action.forward_ports
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue