diff --git a/lib/vagrant-libvirt/action/destroy_domain.rb b/lib/vagrant-libvirt/action/destroy_domain.rb index e00daf6..62c56c3 100644 --- a/lib/vagrant-libvirt/action/destroy_domain.rb +++ b/lib/vagrant-libvirt/action/destroy_domain.rb @@ -13,6 +13,20 @@ module VagrantPlugins # Destroy the server, remove the tracking ID 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 + # ruby-libvirt client directly. Note this is racy, see + # http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames + libvirt_domain = env[:libvirt_compute].client.lookup_domain_by_uuid(env[:machine].id) + libvirt_domain.list_snapshots.each do |name| + @logger.info("Deleting snapshot '#{name}'") + begin + libvirt_domain.lookup_snapshot_by_name(name).delete + rescue => e + raise Errors::DeleteSnapshotError, error_message: e.message + end + end + domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s) domain.destroy(:destroy_volumes => true) env[:machine].id = nil diff --git a/lib/vagrant-libvirt/errors.rb b/lib/vagrant-libvirt/errors.rb index 0c754b5..4758083 100644 --- a/lib/vagrant-libvirt/errors.rb +++ b/lib/vagrant-libvirt/errors.rb @@ -118,6 +118,10 @@ module VagrantPlugins error_key(:no_ip_address_error) end + class DeleteSnapshotError < VagrantLibvirtError + error_key(:delete_snapshot_error) + end + end end end diff --git a/locales/en.yml b/locales/en.yml index e19438c..e7ea0db 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -115,6 +115,8 @@ en: Error while setting up autostart on network: %{error_message}. destroy_network_error: |- Error while removing network %{network_name}. %{error_message}. + delete_snapshot_error: |- + Error while deleting snapshot: %{error_message}. states: short_paused: |-