Fix all core code to use the new networking syntax
This commit is contained in:
parent
1c9af032e7
commit
36b805367d
|
@ -48,14 +48,14 @@ module Vagrant
|
||||||
usable_ports.subtract(extra_in_use)
|
usable_ports.subtract(extra_in_use)
|
||||||
|
|
||||||
# Pass one, remove all defined host ports from usable ports
|
# Pass one, remove all defined host ports from usable ports
|
||||||
with_forwarded_ports(env) do |args|
|
with_forwarded_ports(env) do |options|
|
||||||
usable_ports.delete(args[1])
|
usable_ports.delete(options[:host])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Pass two, detect/handle any collisions
|
# Pass two, detect/handle any collisions
|
||||||
with_forwarded_ports(env) do |args|
|
with_forwarded_ports(env) do |options|
|
||||||
guest_port = args[0]
|
guest_port = options[:guest]
|
||||||
host_port = args[1]
|
host_port = options[:host]
|
||||||
|
|
||||||
if remap[host_port]
|
if remap[host_port]
|
||||||
remap_port = remap[host_port]
|
remap_port = remap[host_port]
|
||||||
|
@ -86,7 +86,7 @@ module Vagrant
|
||||||
usable_ports.delete(repaired_port)
|
usable_ports.delete(repaired_port)
|
||||||
|
|
||||||
# Modify the args in place
|
# Modify the args in place
|
||||||
args[1] = repaired_port
|
options[:host] = repaired_port
|
||||||
|
|
||||||
@logger.info("Repaired FP collision: #{host_port} to #{repaired_port}")
|
@logger.info("Repaired FP collision: #{host_port} to #{repaired_port}")
|
||||||
|
|
||||||
|
@ -104,11 +104,11 @@ module Vagrant
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def with_forwarded_ports(env)
|
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
|
# Ignore anything but forwarded ports
|
||||||
next if type != :forwarded_port
|
next if type != :forwarded_port
|
||||||
|
|
||||||
yield args
|
yield options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,13 +38,10 @@ module VagrantPlugins
|
||||||
@logger.debug("Available slots for high-level adapters: #{available_slots.inspect}")
|
@logger.debug("Available slots for high-level adapters: #{available_slots.inspect}")
|
||||||
@logger.info("Determining network adapters required for high-level configuration...")
|
@logger.info("Determining network adapters required for high-level configuration...")
|
||||||
available_slots = available_slots.to_a.sort
|
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
|
# We only handle private and public networks
|
||||||
next if type != :private_network && type != :public_network
|
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)
|
options = scoped_hash_override(options, :virtualbox)
|
||||||
|
|
||||||
# Figure out the slot that this adapter will go into
|
# Figure out the slot that this adapter will go into
|
||||||
|
@ -61,14 +58,10 @@ module VagrantPlugins
|
||||||
data = nil
|
data = nil
|
||||||
if type == :private_network
|
if type == :private_network
|
||||||
# private_network = hostonly
|
# private_network = hostonly
|
||||||
|
data = [:hostonly, options]
|
||||||
config_args = [args[0], options]
|
|
||||||
data = [:hostonly, config_args]
|
|
||||||
elsif type == :public_network
|
elsif type == :public_network
|
||||||
# public_network = bridged
|
# public_network = bridged
|
||||||
|
data = [:bridged, options]
|
||||||
config_args = [options]
|
|
||||||
data = [:bridged, config_args]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Store it!
|
# Store it!
|
||||||
|
@ -80,13 +73,13 @@ module VagrantPlugins
|
||||||
adapters = []
|
adapters = []
|
||||||
networks = []
|
networks = []
|
||||||
network_adapters_config.each do |slot, data|
|
network_adapters_config.each do |slot, data|
|
||||||
type = data[0]
|
type = data[0]
|
||||||
args = data[1]
|
options = data[1]
|
||||||
|
|
||||||
@logger.info("Network slot #{slot}. Type: #{type}.")
|
@logger.info("Network slot #{slot}. Type: #{type}.")
|
||||||
|
|
||||||
# Get the normalized configuration for this type
|
# Get the normalized configuration for this type
|
||||||
config = send("#{type}_config", args)
|
config = send("#{type}_config", options)
|
||||||
config[:adapter] = slot
|
config[:adapter] = slot
|
||||||
@logger.debug("Normalized configuration: #{config.inspect}")
|
@logger.debug("Normalized configuration: #{config.inspect}")
|
||||||
|
|
||||||
|
@ -123,14 +116,14 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bridged_config(args)
|
def bridged_config(options)
|
||||||
return {
|
return {
|
||||||
:auto_config => true,
|
:auto_config => true,
|
||||||
:bridge => nil,
|
:bridge => nil,
|
||||||
:mac => nil,
|
:mac => nil,
|
||||||
:nic_type => nil,
|
:nic_type => nil,
|
||||||
:use_dhcp_assigned_default_route => false
|
:use_dhcp_assigned_default_route => false
|
||||||
}.merge(args[0] || {})
|
}.merge(options || {})
|
||||||
end
|
end
|
||||||
|
|
||||||
def bridged_adapter(config)
|
def bridged_adapter(config)
|
||||||
|
@ -213,15 +206,14 @@ module VagrantPlugins
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def hostonly_config(args)
|
def hostonly_config(options)
|
||||||
ip = args[0]
|
|
||||||
options = {
|
options = {
|
||||||
:auto_config => true,
|
:auto_config => true,
|
||||||
:netmask => "255.255.255.0"
|
:netmask => "255.255.255.0"
|
||||||
}.merge(args[1] || {})
|
}.merge(options)
|
||||||
|
|
||||||
# Calculate our network address for the given IP/netmask
|
# 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
|
# Verify that a host-only network subnet would not collide
|
||||||
# with a bridged networking interface.
|
# with a bridged networking interface.
|
||||||
|
@ -248,7 +240,7 @@ module VagrantPlugins
|
||||||
return {
|
return {
|
||||||
:adapter_ip => options[:adapter_ip],
|
:adapter_ip => options[:adapter_ip],
|
||||||
:auto_config => options[:auto_config],
|
:auto_config => options[:auto_config],
|
||||||
:ip => ip,
|
:ip => options[:ip],
|
||||||
:mac => nil,
|
:mac => nil,
|
||||||
:netmask => options[:netmask],
|
:netmask => options[:netmask],
|
||||||
:nic_type => nil,
|
:nic_type => nil,
|
||||||
|
|
|
@ -15,12 +15,11 @@ module VagrantPlugins
|
||||||
remap = {}
|
remap = {}
|
||||||
env[:port_collision_remap] = remap
|
env[:port_collision_remap] = remap
|
||||||
env[:machine].provider.driver.read_forwarded_ports.each do |_nic, name, hostport, _guestport|
|
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
|
next if type != :forwarded_port
|
||||||
|
|
||||||
# If the ID matches the name of the forwarded port, then
|
# If the ID matches the name of the forwarded port, then
|
||||||
# remap.
|
# remap.
|
||||||
options = args.last
|
|
||||||
if options[:id] == name
|
if options[:id] == name
|
||||||
remap[name] = hostport
|
remap[name] = hostport
|
||||||
break
|
break
|
||||||
|
|
|
@ -37,9 +37,9 @@ module VagrantPlugins
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def read_machine_ip(machine)
|
def read_machine_ip(machine)
|
||||||
machine.config.vm.networks.each do |type, args|
|
machine.config.vm.networks.each do |type, options|
|
||||||
if type == :private_network && args[0].is_a?(String)
|
if type == :private_network && options[:ip].is_a?(String)
|
||||||
return args[0]
|
return options[:ip]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,12 @@ module VagrantPlugins
|
||||||
def compile_forwarded_ports(config)
|
def compile_forwarded_ports(config)
|
||||||
mappings = {}
|
mappings = {}
|
||||||
|
|
||||||
config.vm.networks.each do |type, args|
|
config.vm.networks.each do |type, options|
|
||||||
if type == :forwarded_port
|
if type == :forwarded_port
|
||||||
guest_port = args[0]
|
guest_port = options[:guest]
|
||||||
host_port = args[1]
|
host_port = options[:host]
|
||||||
options = args[2] || {}
|
|
||||||
options = scoped_hash_override(options, :virtualbox)
|
options = scoped_hash_override(options, :virtualbox)
|
||||||
id = options[:id] ||
|
id = options[:id]
|
||||||
"#{guest_port.to_s(32)}-#{host_port.to_s(32)}"
|
|
||||||
|
|
||||||
mappings[host_port] =
|
mappings[host_port] =
|
||||||
Model::ForwardedPort.new(id, host_port, guest_port, options)
|
Model::ForwardedPort.new(id, host_port, guest_port, options)
|
||||||
|
|
Loading…
Reference in New Issue