[DRE-commits] [vagrant-libvirt] 64/67: Handle network that vagrant created missing when destroy is run. Closes #128
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Apr 24 13:56:08 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 1484a9fb36d74068904fb3712e9d513da418058e
Author: Brian Pitts <brian at polibyte.com>
Date: Mon Jan 20 15:30:51 2014 -0600
Handle network that vagrant created missing when destroy is run. Closes #128
---
lib/vagrant-libvirt/action/destroy_networks.rb | 33 ++++++++++++++++----------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/lib/vagrant-libvirt/action/destroy_networks.rb b/lib/vagrant-libvirt/action/destroy_networks.rb
index f1af002..6dfcaca 100644
--- a/lib/vagrant-libvirt/action/destroy_networks.rb
+++ b/lib/vagrant-libvirt/action/destroy_networks.rb
@@ -18,7 +18,7 @@ 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'
+ @logger.info 'Checking if any networks were created'
# If created_networks file doesn't exist, there are no networks we
# need to remove.
unless File.exist?(created_networks_file)
@@ -26,39 +26,45 @@ module VagrantPlugins
return @app.call(env)
end
- @logger.info 'file with network exists'
+ @logger.info 'File with created networks 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
+ @logger.info "Checking for #{network_uuid}"
+ # lookup_network_by_uuid throws same exception
+ # if there is an error or if the network just doesn't exist
begin
libvirt_network = env[:libvirt_compute].client.lookup_network_by_uuid(
network_uuid)
- rescue
- raise network_uuid
- next
+ rescue Libvirt::RetrieveError => e
+ # this network is already destroyed, so move on
+ if e.message =~ /Network not found/
+ @logger.info "It is already undefined"
+ next
+ # some other error occured, so raise it again
+ else
+ raise e
+ end
end
- # Maybe network doesn't exist anymore.
- 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
+ @logger.info "Still has connections so will not undefine"
created_networks << network_uuid
next
end
- # Shutdown network first.
- libvirt_network.destroy
+ # Shutdown network first.
# Undefine network.
begin
+ libvirt_network.destroy
libvirt_network.undefine
+ @logger.info "Undefined it"
rescue => e
raise Error::DestroyNetworkError,
network_name: libvirt_network.name,
@@ -68,13 +74,16 @@ module VagrantPlugins
file.close
# Update status of created networks after removing some/all of them.
+ # Not sure why we are doing this, something else seems to always delete the file
if created_networks.length > 0
File.open(created_networks_file, 'w') do |file|
+ @logger.info "Writing new created_networks file"
created_networks.each do |network_uuid|
file.puts network_uuid
end
end
else
+ @logger.info "Deleting created_networks file"
File.delete(created_networks_file)
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