mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Delete any snapshots when destroying a domain
This commit is contained in:
parent
c7b01893cd
commit
69f97cf33a
@ -13,6 +13,20 @@ module VagrantPlugins
|
|||||||
# Destroy the server, remove the tracking ID
|
# 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
|
||||||
|
# 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 = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
|
||||||
domain.destroy(:destroy_volumes => true)
|
domain.destroy(:destroy_volumes => true)
|
||||||
env[:machine].id = nil
|
env[:machine].id = nil
|
||||||
|
@ -118,6 +118,10 @@ module VagrantPlugins
|
|||||||
error_key(:no_ip_address_error)
|
error_key(:no_ip_address_error)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class DeleteSnapshotError < VagrantLibvirtError
|
||||||
|
error_key(:delete_snapshot_error)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -115,6 +115,8 @@ en:
|
|||||||
Error while setting up autostart on network: %{error_message}.
|
Error while setting up autostart on network: %{error_message}.
|
||||||
destroy_network_error: |-
|
destroy_network_error: |-
|
||||||
Error while removing network %{network_name}. %{error_message}.
|
Error while removing network %{network_name}. %{error_message}.
|
||||||
|
delete_snapshot_error: |-
|
||||||
|
Error while deleting snapshot: %{error_message}.
|
||||||
|
|
||||||
states:
|
states:
|
||||||
short_paused: |-
|
short_paused: |-
|
||||||
|
Loading…
Reference in New Issue
Block a user