From 10c3ede74ad3480f8322c036de418b71ee1159b0 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Sun, 16 Mar 2014 01:20:00 +0100 Subject: [PATCH 1/2] Catches fog exception when machine could not be found --- lib/vagrant-libvirt/action/read_state.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-libvirt/action/read_state.rb b/lib/vagrant-libvirt/action/read_state.rb index 4b06d3b..22d39c3 100644 --- a/lib/vagrant-libvirt/action/read_state.rb +++ b/lib/vagrant-libvirt/action/read_state.rb @@ -18,9 +18,15 @@ module VagrantPlugins def read_state(libvirt, machine) return :not_created if machine.id.nil? - + + begin + server = libvirt.servers.get(machine.id) + rescue Libvirt::RetrieveError => e + server = nil + @logger.debug('Machine not found #{e}.') + end # Find the machine - server = libvirt.servers.get(machine.id) + if server.nil? || [:'shutting-down', :terminated].include?(server.state.to_sym) # The machine can't be found @logger.info('Machine not found or terminated, assuming it got destroyed.') From 29efbf77d7a1c2146a74d66bc8f2fa20107af414 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Mon, 10 Mar 2014 22:10:23 +0100 Subject: [PATCH 2/2] Catches the following exception to prevent stack from being displayed: Bringing machine 'default' up with 'libvirt' provider... /home/teto/vagrant-libvirt/vendor/bundle/ruby/1.9.1/gems/fog-1.20.0/lib/fog/libvirt/models/compute/volume.rb:84:in `default_pool_name': No storage pools are defined (Fog::Errors::Error) from /home/teto/vagrant-libvirt/vendor/bundle/ruby/1.9.1/gems/fog-1.20.0/lib/fog/libvirt/models/compute/volume.rb:33:in `initialize' from /home/teto/vagrant-libvirt/vendor/bundle/ruby/1.9.1/gems/fog-1.20.0/lib/fog/core/collection.rb:114:in `new' --- lib/vagrant-libvirt/action/set_name_of_domain.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-libvirt/action/set_name_of_domain.rb b/lib/vagrant-libvirt/action/set_name_of_domain.rb index a42e1eb..1aeffdf 100644 --- a/lib/vagrant-libvirt/action/set_name_of_domain.rb +++ b/lib/vagrant-libvirt/action/set_name_of_domain.rb @@ -21,10 +21,16 @@ module VagrantPlugins env[:domain_name] << '_' env[:domain_name] << env[:machine].name.to_s + begin @logger.info("Looking for domain #{env[:domain_name]} through list #{env[:libvirt_compute].servers.all}") # Check if the domain name is not already taken - domain = ProviderLibvirt::Util::Collection.find_matching( + + domain = ProviderLibvirt::Util::Collection.find_matching( env[:libvirt_compute].servers.all, env[:domain_name]) + rescue Fog::Errors::Error => e + @logger.info("#{e}") + domain = nil + end @logger.info("Looking for domain #{env[:domain_name]}")