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/requests/ec2/describe_snapshots.rb
2010-04-08 15:39:25 -07:00

73 lines
2.4 KiB
Ruby

module Fog
module AWS
module EC2
class Real
require 'fog/aws/parsers/ec2/describe_snapshots'
# Describe all or specified snapshots
#
# ==== Parameters
# * snapshot_id<~Array> - List of snapshots to describe, defaults to all
#
# ==== Returns
# * response<~Excon::Response>:
# * 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
def describe_snapshots(snapshot_id = [])
params = AWS.indexed_param('SnapshotId', snapshot_id)
request({
'Action' => 'DescribeSnapshots',
:parser => Fog::Parsers::AWS::EC2::DescribeSnapshots.new
}.merge!(params))
end
end
class Mock
def describe_snapshots(snapshot_id = [])
response = Excon::Response.new
snapshot_id = [*snapshot_id]
if snapshot_id != []
snapshot_set = @data[:snapshots].reject {|key,value| !snapshot_id.include?(key)}.values
else
snapshot_set = @data[:snapshots].values
end
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
end
end
if snapshot_id.length == 0 || snapshot_id.length == snapshot_set.length
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id,
'snapshotSet' => snapshot_set
}
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end
end
end
end
end