Class: Builderator::Model::Cleaner::Volumes

Inherits:
Base
  • Object
show all
Defined in:
lib/builderator/model/cleaner/volumes.rb

Overview

EC2 Volume Resources

Constant Summary collapse

PROPERTIES =
%w(size availability_zone state volume_type iops)

Instance Attribute Summary

Attributes inherited from Base

#resources

Instance Method Summary collapse

Methods inherited from Base

#find, #in_use?, #initialize, #select, #unused

Constructor Details

This class inherits a constructor from Builderator::Model::Cleaner::Base

Instance Method Details

#fetchObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/builderator/model/cleaner/volumes.rb', line 18

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

#in_useObject



40
41
42
43
44
# File 'lib/builderator/model/cleaner/volumes.rb', line 40

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

#snapshotsObject



36
37
38
# File 'lib/builderator/model/cleaner/volumes.rb', line 36

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