Fail if any existing networks configured to have DHCP do not have it. Relates to #103 and #123.

This commit is contained in:
Brian Pitts 2014-01-17 17:03:29 -06:00
parent de553d0ea7
commit 46306503f4
4 changed files with 32 additions and 0 deletions

View File

@ -136,6 +136,18 @@ module VagrantPlugins
nil
end
# Throw an error if dhcp setting for an existing network does not
# match what was configured in the vagrantfile
# since we always enable dhcp for the default network
# this ensures we wont start a vm vagrant cant reach
def verify_dhcp
unless @options[:dhcp_enabled] == @interface_network[:dhcp_enabled]
raise Errors::DHCPMismatch,
network_name: @interface_network[:name],
requested: @options[:dhcp_enabled] ? 'enabled' : 'disabled'
end
end
# Handle only situations, when ip is specified. Variables @options and
# @available_networks should be filled before calling this function.
def handle_ip_option(env)
@ -161,6 +173,10 @@ module VagrantPlugins
end
end
if @interface_network[:created]
verify_dhcp
end
if @options[:network_name]
@logger.debug "Checking that network name does not clash with ip"
if @interface_network[:created]
@ -235,6 +251,8 @@ module VagrantPlugins
if !@interface_network
raise Errors::NetworkNotAvailableError,
network_name: @options[:network_name]
else
verify_dhcp
end
end

View File

@ -77,6 +77,10 @@ module VagrantPlugins
error_key(:network_name_and_address_mismatch)
end
class DHCPMismatch < VagrantLibvirtError
error_key(:dhcp_mismatch)
end
class CreateNetworkError < VagrantLibvirtError
error_key(:create_network_error)
end

View File

@ -27,6 +27,12 @@ module VagrantPlugins
netmask = xml.xpath('/network/ip/@netmask').first
netmask = netmask.value if netmask
if xml.at_xpath('//network/ip/dhcp')
dhcp_enabled = true
else
dhcp_enabled = false
end
# Calculate network address of network from ip address and
# netmask.
if ip && netmask
@ -40,6 +46,7 @@ module VagrantPlugins
ip_address: ip,
netmask: netmask,
network_address: network_address,
dhcp_enabled: dhcp_enabled,
bridge_name: libvirt_network.bridge_name,
created: true,
active: libvirt_network.active?,

View File

@ -106,6 +106,9 @@ en:
network_name_and_address_mismatch: |-
Address %{ip_address} does not match with network name %{network_name}.
Please fix your configuration and run vagrant again.
dhcp_mismatch: |-
Network %{network_name} exists but does not have dhcp %{requested}.
Please fix your configuration and run vagrant again.
create_network_error: |-
Error occured while creating new network: %{error_message}.
network_not_available_error: |-