Delete any snapshots when destroying a domain

This commit is contained in:
Brian Pitts 2013-10-19 13:50:28 -05:00
parent c7b01893cd
commit 69f97cf33a
3 changed files with 20 additions and 0 deletions

View File

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

View File

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

View File

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