478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
# File 'lib/cluster/infrastructures/amazon.rb', line 478
def period(args)
shots = {}
ecc.describe_snapshots.each do |shot|
next unless shot[:aws_owner].to_s == @options.owner.to_s
next unless shot[:aws_status] == 'completed'
shot[:started_at] = Time.parse shot[:aws_started_at]
aid = shot[:aws_volume_id]
if shots.include? aid
shots[aid].push shot
else
shots.merge! aid => [shot]
end
end
stores = @options.volumes['stores'] || []
defaults = if @options.volumes.include?('defaults')
@options.volumes['defaults']
else
{}
end
shots.keys.each do |k|
opts = if v = stores.detect {|v| v['aws_id'] == k}
defaults.merge v
else
defaults
end
snap_count = opts['snaps'] || 2
snap_count = 2 unless snap_count > 1
ordered = shots[k].sort {|a,b| a[:started_at] <=> b[:started_at] }.reverse
ordered.slice(snap_count, ordered.length).map {|shot|
ecc.delete_snapshot shot[:aws_id]
shot[:aws_id]
}
end
end
|