Sha256: 4cefc366c4c7912df083a9a507bd75d915b2ec23620cf7253b716e68f185a977

Contents?: true

Size: 820 Bytes

Versions: 1

Compression:

Stored size: 820 Bytes

Contents

require 'vagrant-openstack-illuin-provider/action/abstract_action'

module VagrantPlugins
  module Openstack
    module Action
      class SnapshotCleanup < AbstractAction
        def initialize(app, _env)
          @app = app
        end

        def call(env)
          nova = env[:openstack_client].nova
          machine_snapshots = nova.list_snapshots(env, env[:machine].id)

          snapshots_to_clean = machine_snapshots.select do |s|
            s.metadata.key?('vagrant_snapshot')
          end

          @app.call env

          unless snapshots_to_clean.empty?
            env[:ui].info("Deleting Vagrant snapshots: #{snapshots_to_clean.map(&:name)}")
          end

          snapshots_to_clean.each do |s|
            nova.delete_snapshot(env, s.id)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-openstack-illuin-provider-0.12.0 lib/vagrant-openstack-illuin-provider/action/snapshot_cleanup.rb