[DRE-commits] [vagrant-libvirt] 103/104: close #70 undefine machine id should be after all operations

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Apr 24 13:55:52 UTC 2016


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

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

commit 55e31c16dfa8315117d14c4739701547e89599fb
Author: dima <pronix.service at gmail.com>
Date:   Sun Oct 20 13:57:47 2013 +0200

    close #70 undefine machine id should be after all operations
---
 lib/vagrant-libvirt/action/destroy_domain.rb   |  7 +++----
 lib/vagrant-libvirt/action/destroy_networks.rb | 25 ++++++++++++++++---------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb
index 62c56c3..c964056 100644
--- a/lib/vagrant-libvirt/action/destroy_domain.rb
+++ b/lib/vagrant-libvirt/action/destroy_domain.rb
@@ -5,13 +5,13 @@ module VagrantPlugins
     module Action
       class DestroyDomain
         def initialize(app, env)
-          @logger = Log4r::Logger.new("vagrant_libvirt::action::destroy_domain")
+          @logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_domain')
           @app = app
         end
 
         def call(env)
           # Destroy the server, remove the tracking ID
-          env[:ui].info(I18n.t("vagrant_libvirt.destroy_domain"))
+          env[:ui].info(I18n.t('vagrant_libvirt.destroy_domain'))
 
           # Must delete any snapshots before domain can be destroyed
           # Fog libvirt currently doesn't support snapshots. Use
@@ -28,8 +28,7 @@ module VagrantPlugins
           end
 
           domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
-          domain.destroy(:destroy_volumes => true)
-          env[:machine].id = nil
+          domain.destroy(destroy_volumes: true)
 
           @app.call(env)
         end
diff --git a/lib/vagrant-libvirt/action/destroy_networks.rb b/lib/vagrant-libvirt/action/destroy_networks.rb
index 53d123f..f1af002 100644
--- a/lib/vagrant-libvirt/action/destroy_networks.rb
+++ b/lib/vagrant-libvirt/action/destroy_networks.rb
@@ -9,7 +9,7 @@ module VagrantPlugins
       class DestroyNetworks
 
         def initialize(app, env)
-          @logger = Log4r::Logger.new("vagrant_libvirt::action::destroy_networks")
+          @logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_networks')
           @app = app
         end
 
@@ -18,45 +18,51 @@ module VagrantPlugins
           # data directory, created_networks file holds UUIDs of each network.
           created_networks_file = env[:machine].data_dir + 'created_networks'
 
+          @logger.info 'Attepmt destroy network'
           # If created_networks file doesn't exist, there are no networks we
           # need to remove.
-          return @app.call(env) if not File.exist?(created_networks_file)
+          unless File.exist?(created_networks_file)
+            env[:machine].id = nil
+            return @app.call(env)
+          end
+
+          @logger.info 'file with network exists'
 
           # Iterate over each created network UUID and try to remove it.
           created_networks = []
           file = File.open(created_networks_file, 'r')
           file.readlines.each do |network_uuid|
+            @logger.info network_uuid
             begin
               libvirt_network = env[:libvirt_compute].client.lookup_network_by_uuid(
                 network_uuid)
             rescue
+              raise network_uuid
               next
             end
 
             # Maybe network doesn't exist anymore.
-            next if not libvirt_network
+            next unless libvirt_network
 
             # Skip removing if network has still active connections.
             xml = Nokogiri::XML(libvirt_network.xml_desc)
             connections = xml.xpath('/network/@connections').first
+            @logger.info connections
             if connections != nil
               created_networks << network_uuid
               next
             end
 
             # Shutdown network first.
-            begin
-              libvirt_network.destroy
-            rescue => e
-            end
+            libvirt_network.destroy
 
             # Undefine network.
             begin
               libvirt_network.undefine
             rescue => e
               raise Error::DestroyNetworkError,
-                :network_name  => libvirt_network.name,
-                :error_message => e.message
+                network_name: libvirt_network.name,
+                error_message: e.message
             end
           end
           file.close
@@ -72,6 +78,7 @@ module VagrantPlugins
             File.delete(created_networks_file)
           end
 
+          env[:machine].id = nil
           @app.call(env)
         end
       end

-- 
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