Class: Snapshoter::Provider::EC2Provider
- Inherits:
-
Object
- Object
- Snapshoter::Provider::EC2Provider
- Defined in:
- lib/snapshoter/provider/ec2.rb
Instance Method Summary collapse
- #delete_old_snapshots(volume) ⇒ Object
-
#initialize(config) ⇒ EC2Provider
constructor
A new instance of EC2Provider.
-
#last_snapshot_at(volume) ⇒ Object
Returns the most recent time a snapshot was started for a given volume or nil if there are none.
- #refresh ⇒ Object
- #snapshot_volume(volume) ⇒ Object
Constructor Details
#initialize(config) ⇒ EC2Provider
Returns a new instance of EC2Provider.
6 7 8 |
# File 'lib/snapshoter/provider/ec2.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#delete_old_snapshots(volume) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/snapshoter/provider/ec2.rb', line 25 def delete_old_snapshots(volume) deleted_count = 0 old_snapshots = snapshots_by_volume_id(volume.id)[volume.keep..-1] if old_snapshots && old_snapshots.any? logger.info "[Volume #{volume.id}] Deleting #{old_snapshots.length} old snapshots for #{volume.id}" old_snapshots.each do |snapshot| if snapshot[:aws_status] == 'completed' logger.debug "[Volume #{volume.id}][Snapshot #{snapshot[:aws_id]}] Deleting snapshot created on #{snapshot[:aws_started_at]} #{snapshot[:aws_id]}" if ec2.delete_snapshot(snapshot[:aws_id]) deleted_count += 1 logger.debug "[Volume #{volume.id}][Snapshot #{snapshot[:aws_id]}] Snapshot deleted" else logger.error "[Volume #{volume.id}][Snapshot #{snapshot.id}] Snapshot delete failed!" end else logger.info "[Volume #{volume.id}][Snapshot #{snapshot.id}] Could not be deleted because status is '#{snapshot[:aws_status]}'" end end else logger.debug "[Volume #{volume.id}] No old snapshots to delete" end deleted_count end |
#last_snapshot_at(volume) ⇒ Object
Returns the most recent time a snapshot was started for a given volume or nil if there are none
11 12 13 14 |
# File 'lib/snapshoter/provider/ec2.rb', line 11 def last_snapshot_at(volume) snapshots = snapshots_by_volume_id(volume.id) snapshots.any? ? snapshots.first[:aws_started_at] : nil end |
#refresh ⇒ Object
49 50 51 |
# File 'lib/snapshoter/provider/ec2.rb', line 49 def refresh snapshots(true) if @snapshots end |
#snapshot_volume(volume) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/snapshoter/provider/ec2.rb', line 16 def snapshot_volume(volume) logger.info "[Volume #{volume.id}] Snapshot started" if ec2.create_snapshot(volume.id) logger.info "[Volume #{volume.id}] Snapshot complete" else logger.error "[Volume #{volume.id}] Snapshot failed!" end end |