Class: VagrantPlugins::ProviderLibvirt::Action::DestroyDomain
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::DestroyDomain
- Defined in:
- lib/vagrant-libvirt/action/destroy_domain.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ DestroyDomain
constructor
A new instance of DestroyDomain.
Constructor Details
#initialize(app, env) ⇒ DestroyDomain
Returns a new instance of DestroyDomain.
7 8 9 10 |
# File 'lib/vagrant-libvirt/action/destroy_domain.rb', line 7 def initialize(app, env) @logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_domain') @app = app end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vagrant-libvirt/action/destroy_domain.rb', line 12 def call(env) # 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. end end domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s) domain.destroy(destroy_volumes: true) @app.call(env) end |