2010-03-16 18:46:21 -04:00
|
|
|
require 'fog/collection'
|
|
|
|
require 'fog/aws/models/ec2/snapshot'
|
|
|
|
|
2009-09-06 13:48:12 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-03-16 18:46:21 -04:00
|
|
|
module EC2
|
2009-09-06 13:48:12 -04:00
|
|
|
|
2010-03-16 18:46:21 -04:00
|
|
|
class Mock
|
|
|
|
def snapshots(attributes = {})
|
|
|
|
Fog::AWS::EC2::Snapshots.new({
|
|
|
|
:connection => self
|
|
|
|
}.merge!(attributes))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
def snapshots(attributes = {})
|
|
|
|
Fog::AWS::EC2::Snapshots.new({
|
|
|
|
:connection => self
|
|
|
|
}.merge!(attributes))
|
|
|
|
end
|
2009-09-06 13:48:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Snapshots < Fog::Collection
|
|
|
|
|
2009-09-24 22:18:41 -04:00
|
|
|
attribute :snapshot_id
|
2009-12-05 17:53:42 -05:00
|
|
|
attribute :volume
|
2009-09-24 22:18:41 -04:00
|
|
|
|
2009-10-30 03:11:50 -04:00
|
|
|
model Fog::AWS::EC2::Snapshot
|
2009-10-30 02:35:28 -04:00
|
|
|
|
2009-09-28 00:31:15 -04:00
|
|
|
def initialize(attributes)
|
|
|
|
@snapshot_id ||= []
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-10-30 02:35:28 -04:00
|
|
|
def all(snapshot_id = @snapshot_id)
|
2010-01-05 01:03:24 -05:00
|
|
|
@snapshot_id = snapshot_id
|
2009-09-26 22:42:08 -04:00
|
|
|
data = connection.describe_snapshots(snapshot_id).body
|
2010-03-06 23:02:10 -05:00
|
|
|
load(data['snapshotSet'])
|
2009-12-05 17:53:42 -05:00
|
|
|
if volume
|
2010-03-06 23:02:10 -05:00
|
|
|
self.replace(self.select {|snapshot| snapshot.volume_id == volume.id})
|
2009-09-30 01:02:33 -04:00
|
|
|
end
|
2010-03-06 23:02:10 -05:00
|
|
|
self
|
2009-09-06 13:48:12 -04:00
|
|
|
end
|
|
|
|
|
2009-09-24 22:18:41 -04:00
|
|
|
def get(snapshot_id)
|
2009-10-22 23:46:15 -04:00
|
|
|
if snapshot_id
|
|
|
|
all(snapshot_id).first
|
|
|
|
end
|
2009-11-08 15:16:52 -05:00
|
|
|
rescue Excon::Errors::BadRequest
|
2009-09-24 22:18:41 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2009-09-06 13:48:12 -04:00
|
|
|
def new(attributes = {})
|
2009-12-05 17:53:42 -05:00
|
|
|
if volume
|
|
|
|
super({ :volume_id => volume.id }.merge!(attributes))
|
|
|
|
else
|
|
|
|
super
|
2009-09-30 01:02:33 -04:00
|
|
|
end
|
2009-09-06 13:48:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|