vaguerent/plugins/providers/virtualbox/util/compile_forwarded_ports.rb
Pravinchandar Raajendiran af9d0df635 Fix for #4608
Added support for Port forwarding in an IP aliased environment. The change
makes the following forwarding rule(s) possible.

Ex: eth0 is ip aliased to have a range of IP addresses 10.20.30.0/24.

In the Vagrant file, we can now have an entry like the following and
it will just work! Note the host port 8081 is the same for both .1 and .2.

  Vagrant.configure("2") do |config|
    config.vm.network "forwarded_port", guest: 80, host: 8080
    config.vm.network "forwarded_port", guest: 81, host: 8081, host_ip: 10.20.30.1
    config.vm.network "forwarded_port", guest: 82, host: 8081, host_ip: 10.20.30.2
  end
2016-02-14 22:16:24 +11:00

38 lines
1.1 KiB
Ruby

require "vagrant/util/scoped_hash_override"
module VagrantPlugins
module ProviderVirtualBox
module Util
module CompileForwardedPorts
include Vagrant::Util::ScopedHashOverride
# This method compiles the forwarded ports into {ForwardedPort}
# models.
def compile_forwarded_ports(config)
mappings = {}
config.vm.networks.each do |type, options|
if type == :forwarded_port
guest_port = options[:guest]
host_port = options[:host]
host_ip = options[:host_ip]
protocol = options[:protocol] || "tcp"
options = scoped_hash_override(options, :virtualbox)
id = options[:id]
# If the forwarded port was marked as disabled, ignore.
next if options[:disabled]
key = "#{host_ip}#{protocol}#{host_port}"
mappings[key] =
Model::ForwardedPort.new(id, host_port, guest_port, options)
end
end
mappings.values
end
end
end
end
end