Sha256: 204b5b6744eee321ae97287fefb1a680677a95385ca728aef7fc24cba88ff88d

Contents?: true

Size: 1.16 KB

Versions: 42

Compression:

Stored size: 1.16 KB

Contents

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

module Builderator
  module Model
    # :nodoc:
    module Cleaner
      def self.volumes
        @volumes ||= Volumes.new
      end

      ##
      # EC2 Volume Resources
      ##
      class Volumes < Model::Cleaner::Base
        PROPERTIES = %w(size availability_zone state volume_type iops)

        def fetch
          @resources = {}.tap do |v|
            Util.ec2.describe_volumes.each do |page|
              page.volumes.each do |vol|
                properties = Util.from_tags(vol.tags)
                properties['creation_date'] = vol.create_time.to_datetime
                PROPERTIES.each { |pp| properties[pp] = vol[pp.to_sym] }

                v[vol.volume_id] = {
                  :id => vol.volume_id,
                  :properties => properties,
                  :snapshot => vol.snapshot_id
                }
              end
            end
          end
        end

        def snapshots
          resources.values.map { |v| v[:snapshot] }
        end

        def in_use
          {}.tap do |used|
            used.merge!(select(Cleaner.instances.volumes))
          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/volumes.rb
builderator-2.1.0 lib/builderator/model/cleaner/volumes.rb
builderator-2.0.4 lib/builderator/model/cleaner/volumes.rb
builderator-2.0.3 lib/builderator/model/cleaner/volumes.rb
builderator-2.0.2 lib/builderator/model/cleaner/volumes.rb
builderator-2.0.1 lib/builderator/model/cleaner/volumes.rb
builderator-2.0.0 lib/builderator/model/cleaner/volumes.rb
builderator-1.3.2 lib/builderator/model/cleaner/volumes.rb
builderator-1.3.1 lib/builderator/model/cleaner/volumes.rb
builderator-1.3.0 lib/builderator/model/cleaner/volumes.rb
builderator-1.2.3.pre.beta.1 lib/builderator/model/cleaner/volumes.rb
builderator-1.2.2 lib/builderator/model/cleaner/volumes.rb
builderator-1.2.1 lib/builderator/model/cleaner/volumes.rb
builderator-1.2.0 lib/builderator/model/cleaner/volumes.rb
builderator-1.1.12 lib/builderator/model/cleaner/volumes.rb
builderator-1.1.11 lib/builderator/model/cleaner/volumes.rb
builderator-1.1.10 lib/builderator/model/cleaner/volumes.rb
builderator-1.1.9 lib/builderator/model/cleaner/volumes.rb
builderator-1.1.8 lib/builderator/model/cleaner/volumes.rb
builderator-1.1.7 lib/builderator/model/cleaner/volumes.rb