diff --git a/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb b/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb index 505461b5b..a69769a59 100644 --- a/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb +++ b/lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb @@ -48,14 +48,14 @@ module Vagrant usable_ports.subtract(extra_in_use) # Pass one, remove all defined host ports from usable ports - with_forwarded_ports(env) do |args| - usable_ports.delete(args[1]) + with_forwarded_ports(env) do |options| + usable_ports.delete(options[:host]) end # Pass two, detect/handle any collisions - with_forwarded_ports(env) do |args| - guest_port = args[0] - host_port = args[1] + with_forwarded_ports(env) do |options| + guest_port = options[:guest] + host_port = options[:host] if remap[host_port] remap_port = remap[host_port] @@ -86,7 +86,7 @@ module Vagrant usable_ports.delete(repaired_port) # Modify the args in place - args[1] = repaired_port + options[:host] = repaired_port @logger.info("Repaired FP collision: #{host_port} to #{repaired_port}") @@ -104,11 +104,11 @@ module Vagrant protected def with_forwarded_ports(env) - env[:machine].config.vm.networks.each do |type, args| + env[:machine].config.vm.networks.each do |type, options| # Ignore anything but forwarded ports next if type != :forwarded_port - yield args + yield options end end end diff --git a/plugins/providers/virtualbox/action/network.rb b/plugins/providers/virtualbox/action/network.rb index 21aa88e79..9975aa29e 100644 --- a/plugins/providers/virtualbox/action/network.rb +++ b/plugins/providers/virtualbox/action/network.rb @@ -38,13 +38,10 @@ module VagrantPlugins @logger.debug("Available slots for high-level adapters: #{available_slots.inspect}") @logger.info("Determining network adapters required for high-level configuration...") available_slots = available_slots.to_a.sort - env[:machine].config.vm.networks.each do |type, args| + env[:machine].config.vm.networks.each do |type, options| # We only handle private and public networks next if type != :private_network && type != :public_network - options = nil - options = args.last if args.last.is_a?(Hash) - options ||= {} options = scoped_hash_override(options, :virtualbox) # Figure out the slot that this adapter will go into @@ -61,14 +58,10 @@ module VagrantPlugins data = nil if type == :private_network # private_network = hostonly - - config_args = [args[0], options] - data = [:hostonly, config_args] + data = [:hostonly, options] elsif type == :public_network # public_network = bridged - - config_args = [options] - data = [:bridged, config_args] + data = [:bridged, options] end # Store it! @@ -80,13 +73,13 @@ module VagrantPlugins adapters = [] networks = [] network_adapters_config.each do |slot, data| - type = data[0] - args = data[1] + type = data[0] + options = data[1] @logger.info("Network slot #{slot}. Type: #{type}.") # Get the normalized configuration for this type - config = send("#{type}_config", args) + config = send("#{type}_config", options) config[:adapter] = slot @logger.debug("Normalized configuration: #{config.inspect}") @@ -123,14 +116,14 @@ module VagrantPlugins end end - def bridged_config(args) + def bridged_config(options) return { :auto_config => true, :bridge => nil, :mac => nil, :nic_type => nil, :use_dhcp_assigned_default_route => false - }.merge(args[0] || {}) + }.merge(options || {}) end def bridged_adapter(config) @@ -213,15 +206,14 @@ module VagrantPlugins } end - def hostonly_config(args) - ip = args[0] + def hostonly_config(options) options = { :auto_config => true, :netmask => "255.255.255.0" - }.merge(args[1] || {}) + }.merge(options) # Calculate our network address for the given IP/netmask - netaddr = network_address(ip, options[:netmask]) + netaddr = network_address(options[:ip], options[:netmask]) # Verify that a host-only network subnet would not collide # with a bridged networking interface. @@ -248,7 +240,7 @@ module VagrantPlugins return { :adapter_ip => options[:adapter_ip], :auto_config => options[:auto_config], - :ip => ip, + :ip => options[:ip], :mac => nil, :netmask => options[:netmask], :nic_type => nil, diff --git a/plugins/providers/virtualbox/action/prepare_forwarded_port_collision_params.rb b/plugins/providers/virtualbox/action/prepare_forwarded_port_collision_params.rb index 4ae9df415..52836f42f 100644 --- a/plugins/providers/virtualbox/action/prepare_forwarded_port_collision_params.rb +++ b/plugins/providers/virtualbox/action/prepare_forwarded_port_collision_params.rb @@ -15,12 +15,11 @@ module VagrantPlugins remap = {} env[:port_collision_remap] = remap env[:machine].provider.driver.read_forwarded_ports.each do |_nic, name, hostport, _guestport| - env[:machine].config.vm.networks.each do |type, args| + env[:machine].config.vm.networks.each do |type, options| next if type != :forwarded_port # If the ID matches the name of the forwarded port, then # remap. - options = args.last if options[:id] == name remap[name] = hostport break diff --git a/plugins/providers/virtualbox/action/prepare_nfs_settings.rb b/plugins/providers/virtualbox/action/prepare_nfs_settings.rb index 9c49e7652..742f34612 100644 --- a/plugins/providers/virtualbox/action/prepare_nfs_settings.rb +++ b/plugins/providers/virtualbox/action/prepare_nfs_settings.rb @@ -37,9 +37,9 @@ module VagrantPlugins # # @return [String] def read_machine_ip(machine) - machine.config.vm.networks.each do |type, args| - if type == :private_network && args[0].is_a?(String) - return args[0] + machine.config.vm.networks.each do |type, options| + if type == :private_network && options[:ip].is_a?(String) + return options[:ip] end end diff --git a/plugins/providers/virtualbox/util/compile_forwarded_ports.rb b/plugins/providers/virtualbox/util/compile_forwarded_ports.rb index fe281c970..f7ae01a51 100644 --- a/plugins/providers/virtualbox/util/compile_forwarded_ports.rb +++ b/plugins/providers/virtualbox/util/compile_forwarded_ports.rb @@ -11,14 +11,12 @@ module VagrantPlugins def compile_forwarded_ports(config) mappings = {} - config.vm.networks.each do |type, args| + config.vm.networks.each do |type, options| if type == :forwarded_port - guest_port = args[0] - host_port = args[1] - options = args[2] || {} + guest_port = options[:guest] + host_port = options[:host] options = scoped_hash_override(options, :virtualbox) - id = options[:id] || - "#{guest_port.to_s(32)}-#{host_port.to_s(32)}" + id = options[:id] mappings[host_port] = Model::ForwardedPort.new(id, host_port, guest_port, options)