Allow use of subnet option when defining private network with dhcp type

This commit is contained in:
Chris Roberts 2019-03-19 14:35:40 -07:00
parent 670bef6596
commit 623a1815ae
1 changed files with 13 additions and 8 deletions

View File

@ -85,17 +85,22 @@ module VagrantPlugins
network_name = root_options[:name] network_name = root_options[:name]
end end
if root_options[:type].to_s == "dhcp" && !root_options[:ip] if root_options[:type].to_s == "dhcp"
if !root_options[:ip] && !root_options[:subnet]
network_name = "vagrant_network" if !network_name network_name = "vagrant_network" if !network_name
return [network_name, network_options] return [network_name, network_options]
end end
if root_options[:subnet]
if !root_options[:ip] addr = IPAddr.new(root_options[:subnet])
raise Errors::NetworkIPAddressRequired root_options[:netmask] = addr.prefix
end
end end
# Validate the IP address if root_options[:ip]
addr = IPAddr.new(root_options[:ip]) addr = IPAddr.new(root_options[:ip])
elsif addr.nil?
raise Errors::NetworkIPAddressRequired
end
# If address is ipv6, enable ipv6 support # If address is ipv6, enable ipv6 support
network_options[:ipv6] = addr.ipv6? network_options[:ipv6] = addr.ipv6?
@ -116,7 +121,7 @@ module VagrantPlugins
# With no network name, process options to find or determine # With no network name, process options to find or determine
# name for new network # name for new network
if !network_name if !network_name
subnet = IPAddr.new("#{root_options[:ip]}/#{root_options[:netmask]}") subnet = IPAddr.new("#{addr}/#{root_options[:netmask]}")
network = "#{subnet}/#{root_options[:netmask]}" network = "#{subnet}/#{root_options[:netmask]}"
network_options[:subnet] = network network_options[:subnet] = network
existing_network = env[:machine].provider.driver. existing_network = env[:machine].provider.driver.