2010-03-16 18:46:21 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
module EC2
|
|
|
|
class Real
|
|
|
|
|
2009-08-20 22:26:14 -04:00
|
|
|
# Describe all or specified snapshots
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * snapshot_id<~Array> - List of snapshots to describe, defaults to all
|
2010-04-23 14:59:41 -04:00
|
|
|
# * options<~Array>:
|
|
|
|
# * 'Owner'<~String> - Owner of snapshot in ['self', 'amazon', account_id]
|
|
|
|
# * 'RestorableBy'<~String> - Account id of user who can create volumes from this snapshot
|
2009-08-20 22:26:14 -04:00
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-20 22:26:14 -04:00
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'requestId'<~String> - Id of request
|
|
|
|
# * 'snapshotSet'<~Array>:
|
|
|
|
# * 'progress'<~String>: The percentage progress of the snapshot
|
|
|
|
# * 'snapshotId'<~String>: Id of the snapshot
|
|
|
|
# * 'startTime'<~Time>: Timestamp of when snapshot was initiated
|
|
|
|
# * 'status'<~String>: Snapshot state, in ['pending', 'completed']
|
|
|
|
# * 'volumeId'<~String>: Id of volume that snapshot contains
|
2010-04-23 14:59:41 -04:00
|
|
|
def describe_snapshots(snapshot_id = [], options = {})
|
|
|
|
options['Owner'] ||= 'self'
|
|
|
|
options.merge!(AWS.indexed_param('SnapshotId', snapshot_id))
|
2009-08-20 22:26:14 -04:00
|
|
|
request({
|
2010-03-16 01:15:33 -04:00
|
|
|
'Action' => 'DescribeSnapshots',
|
|
|
|
:parser => Fog::Parsers::AWS::EC2::DescribeSnapshots.new
|
2010-04-23 14:59:41 -04:00
|
|
|
}.merge!(options))
|
2009-08-20 22:26:14 -04:00
|
|
|
end
|
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
2009-08-20 22:26:14 -04:00
|
|
|
|
2010-03-16 18:46:21 -04:00
|
|
|
class Mock
|
2009-07-13 22:14:59 -04:00
|
|
|
|
2009-08-20 22:26:14 -04:00
|
|
|
def describe_snapshots(snapshot_id = [])
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2009-08-20 22:26:14 -04:00
|
|
|
snapshot_id = [*snapshot_id]
|
|
|
|
if snapshot_id != []
|
2010-03-16 18:46:21 -04:00
|
|
|
snapshot_set = @data[:snapshots].reject {|key,value| !snapshot_id.include?(key)}.values
|
2009-08-20 22:26:14 -04:00
|
|
|
else
|
2010-03-16 18:46:21 -04:00
|
|
|
snapshot_set = @data[:snapshots].values
|
2009-08-20 22:26:14 -04:00
|
|
|
end
|
|
|
|
|
2010-04-13 17:42:16 -04:00
|
|
|
if snapshot_id.length == 0 || snapshot_id.length == snapshot_set.length
|
|
|
|
snapshot_set.each do |snapshot|
|
|
|
|
case snapshot['status']
|
|
|
|
when 'in progress', 'pending'
|
|
|
|
if Time.now - snapshot['startTime'] > Fog::Mock.delay * 2
|
|
|
|
snapshot['progress'] = '100%'
|
|
|
|
snapshot['status'] = 'completed'
|
|
|
|
elsif Time.now - snapshot['startTime'] > Fog::Mock.delay
|
|
|
|
snapshot['progress'] = '50%'
|
|
|
|
snapshot['status'] = 'in progress'
|
|
|
|
end
|
2009-08-20 22:26:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id,
|
|
|
|
'snapshotSet' => snapshot_set
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response.status = 400
|
2009-11-20 14:08:08 -05:00
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
2009-08-20 22:26:14 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|