Sha256: c9c23f33f00b0889b7490c580e83a20a08b8dfd98830eedff2620cb2208cfb73

Contents?: true

Size: 1.3 KB

Versions: 42

Compression:

Stored size: 1.3 KB

Contents

require 'aws-sdk'
require_relative '../../util'

module Builderator
  module Model
    # :nodoc:
    module Cleaner
      def self.snapshots
        @snapshots ||= Snapshots.new
      end

      ##
      # EC2 Snapshot Resources
      ##
      class Snapshots < Model::Cleaner::Base
        PROPERTIES = %w(state owner_id description volume_size)

        def fetch
          @resources = {}.tap do |s|
            Util.ec2.describe_snapshots(:filters => [
              {
                :name => 'status',
                :values => %w(completed)
              }
            ], :owner_ids => ['self']).each do |page|
              page.snapshots.each do |snap|
                properties = Util.from_tags(snap.tags)
                properties['creation_date'] = snap.start_time.to_datetime
                PROPERTIES.each { |pp| properties[pp] = snap[pp.to_sym] }

                s[snap.snapshot_id] = {
                  :id => snap.snapshot_id,
                  :properties => properties,
                  :volume => snap.volume_id
                }
              end
            end
          end
        end

        def in_use
          {}.tap do |used|
            used.merge!(select(Cleaner.volumes.snapshots))
            used.merge!(select(Cleaner.images.snapshots))
          end
        end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
builderator-2.1.1 lib/builderator/model/cleaner/snapshots.rb
builderator-2.1.0 lib/builderator/model/cleaner/snapshots.rb
builderator-2.0.4 lib/builderator/model/cleaner/snapshots.rb
builderator-2.0.3 lib/builderator/model/cleaner/snapshots.rb
builderator-2.0.2 lib/builderator/model/cleaner/snapshots.rb
builderator-2.0.1 lib/builderator/model/cleaner/snapshots.rb
builderator-2.0.0 lib/builderator/model/cleaner/snapshots.rb
builderator-1.3.2 lib/builderator/model/cleaner/snapshots.rb
builderator-1.3.1 lib/builderator/model/cleaner/snapshots.rb
builderator-1.3.0 lib/builderator/model/cleaner/snapshots.rb
builderator-1.2.3.pre.beta.1 lib/builderator/model/cleaner/snapshots.rb
builderator-1.2.2 lib/builderator/model/cleaner/snapshots.rb
builderator-1.2.1 lib/builderator/model/cleaner/snapshots.rb
builderator-1.2.0 lib/builderator/model/cleaner/snapshots.rb
builderator-1.1.12 lib/builderator/model/cleaner/snapshots.rb
builderator-1.1.11 lib/builderator/model/cleaner/snapshots.rb
builderator-1.1.10 lib/builderator/model/cleaner/snapshots.rb
builderator-1.1.9 lib/builderator/model/cleaner/snapshots.rb
builderator-1.1.8 lib/builderator/model/cleaner/snapshots.rb
builderator-1.1.7 lib/builderator/model/cleaner/snapshots.rb