[DRE-commits] [vagrant-libvirt] 55/67: Fail if any existing networks configured to have DHCP do not have it. Relates to #103 and #123.

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Apr 24 13:56:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag 0.0.14
in repository vagrant-libvirt.

commit 46306503f48f9efcc99aa065e104b357be62d032
Author: Brian Pitts <brian at polibyte.com>
Date:   Fri Jan 17 17:03:29 2014 -0600

    Fail if any existing networks configured to have DHCP do not have it. Relates to #103 and #123.
---
 lib/vagrant-libvirt/action/create_networks.rb | 18 ++++++++++++++++++
 lib/vagrant-libvirt/errors.rb                 |  4 ++++
 lib/vagrant-libvirt/util/libvirt_util.rb      |  7 +++++++
 locales/en.yml                                |  3 +++
 4 files changed, 32 insertions(+)

diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb
index abfd01f..455b781 100644
--- a/lib/vagrant-libvirt/action/create_networks.rb
+++ b/lib/vagrant-libvirt/action/create_networks.rb
@@ -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
 
diff --git a/lib/vagrant-libvirt/errors.rb b/lib/vagrant-libvirt/errors.rb
index 9a79a38..7c00f66 100644
--- a/lib/vagrant-libvirt/errors.rb
+++ b/lib/vagrant-libvirt/errors.rb
@@ -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
diff --git a/lib/vagrant-libvirt/util/libvirt_util.rb b/lib/vagrant-libvirt/util/libvirt_util.rb
index 6f357bd..9a4eced 100644
--- a/lib/vagrant-libvirt/util/libvirt_util.rb
+++ b/lib/vagrant-libvirt/util/libvirt_util.rb
@@ -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?,
diff --git a/locales/en.yml b/locales/en.yml
index 55bda9e..f1f3d89 100644
--- a/locales/en.yml
+++ b/locales/en.yml
@@ -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: |-

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git



More information about the Pkg-ruby-extras-commits mailing list