Class: EbsPruneSnapshot::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ebs_prune_snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/ebs_prune_snapshot.rb', line 9

def initialize(args={})
  @aws = Aws.new(args[:aws])
  @rotation = Rotation.new(args[:rotation])
end

Instance Attribute Details

#awsObject (readonly)

Returns the value of attribute aws.



7
8
9
# File 'lib/ebs_prune_snapshot.rb', line 7

def aws
  @aws
end

#rotationObject (readonly)

Returns the value of attribute rotation.



7
8
9
# File 'lib/ebs_prune_snapshot.rb', line 7

def rotation
  @rotation
end

Instance Method Details

#describeObject



30
31
32
33
# File 'lib/ebs_prune_snapshot.rb', line 30

def describe
  puts rotation
  volumes.keys.each { |volume_id| describe_volume(volume_id) }
end

#describe_volume(volume_id) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/ebs_prune_snapshot.rb', line 39

def describe_volume(volume_id)
  analyzer = SnapshotAnalyzer.new(volume(volume_id), rotation)
  puts "VOLUME: #{volume_id}"
  analyzer.to_skip.each {|snapshot| puts   "  SKIP: #{snapshot.snapshot_id} : #{snapshot.date}"}
  analyzer.to_save.each {|snapshot| puts   "  KEEP: #{snapshot.snapshot_id} : #{snapshot.date}"}
  analyzer.to_delete.each {|snapshot| puts "  DELE: #{snapshot.snapshot_id} : #{snapshot.date}"}
end

#pruneObject



35
36
37
# File 'lib/ebs_prune_snapshot.rb', line 35

def prune
  volumes.keys.each { |volume_id| prune_volume(volume_id) }
end

#prune_volume(volume_id) ⇒ Object



47
48
49
50
# File 'lib/ebs_prune_snapshot.rb', line 47

def prune_volume(volume_id)
  analyzer = SnapshotAnalyzer.new(volume(volume_id), rotation)
  analyzer.to_delete.each { |snapshot| aws.delete(snapshot) }
end

#volume(volume_id) ⇒ Object



26
27
28
# File 'lib/ebs_prune_snapshot.rb', line 26

def volume(volume_id)
  volumes[volume_id]
end

#volumesObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ebs_prune_snapshot.rb', line 14

def volumes
  @volumes ||= begin
    volumes = {}
    aws.snapshots.each do |snapshot|
      _snapshot = Snapshot.new(snapshot)
      volumes[_snapshot.volume_id] ||= []
      volumes[_snapshot.volume_id].push(_snapshot)
    end
    volumes
  end
end