1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/ec2/snapshots.rb

54 lines
1.1 KiB
Ruby
Raw Normal View History

2009-09-06 10:48:12 -07:00
module Fog
module AWS
class EC2
2009-09-29 22:02:33 -07:00
def snapshots(attributes = {})
Fog::AWS::EC2::Snapshots.new({
:connection => self
}.merge!(attributes))
2009-09-06 10:48:12 -07:00
end
class Snapshots < Fog::Collection
2009-09-24 19:18:41 -07:00
attribute :snapshot_id
attribute :volume
2009-09-24 19:18:41 -07:00
model Fog::AWS::EC2::Snapshot
def initialize(attributes)
@snapshot_id ||= []
super
end
def all(snapshot_id = @snapshot_id)
2010-01-04 22:03:24 -08:00
@snapshot_id = snapshot_id
2009-09-26 19:42:08 -07:00
data = connection.describe_snapshots(snapshot_id).body
load(data['snapshotSet'])
if volume
self.replace(self.select {|snapshot| snapshot.volume_id == volume.id})
2009-09-29 22:02:33 -07:00
end
self
2009-09-06 10:48:12 -07:00
end
2009-09-24 19:18:41 -07:00
def get(snapshot_id)
2009-10-22 20:46:15 -07:00
if snapshot_id
all(snapshot_id).first
end
rescue Excon::Errors::BadRequest
2009-09-24 19:18:41 -07:00
nil
end
2009-09-06 10:48:12 -07:00
def new(attributes = {})
if volume
super({ :volume_id => volume.id }.merge!(attributes))
else
super
2009-09-29 22:02:33 -07:00
end
2009-09-06 10:48:12 -07:00
end
end
end
end
end