Sha256: aca15f709e2d95931e1f63c3c3ae5d66409187187141a9b5de14878c2d37807a

Contents?: true

Size: 1.27 KB

Versions: 16

Compression:

Stored size: 1.27 KB

Contents

require 'log4r'

module VagrantPlugins
  module ProviderLibvirt
    module Action
      class DestroyDomain
        def initialize(app, env)
          @logger = Log4r::Logger.new('vagrant_libvirt::action::destroy_domain')
          @app = app
        end

        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.message
            end
          end

          domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
          domain.destroy(destroy_volumes: true)

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
vagrant-libvirt-0.0.26 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.25 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.24 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.23 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.22 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.21 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.20 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.19 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.18 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.17 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.16 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.15 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.14 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.13 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.12 lib/vagrant-libvirt/action/destroy_domain.rb
vagrant-libvirt-0.0.11 lib/vagrant-libvirt/action/destroy_domain.rb