2010-03-16 18:46:21 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
module EC2
|
|
|
|
class Real
|
2009-08-15 18:19:07 -04:00
|
|
|
|
|
|
|
# Describe all or specified volumes.
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * volume_id<~Array> - List of volumes to describe, defaults to all
|
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-15 18:19:07 -04:00
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'volumeSet'<~Array>:
|
|
|
|
# * 'availabilityZone'<~String> - Availability zone for volume
|
|
|
|
# * 'createTime'<~Time> - Timestamp for creation
|
|
|
|
# * 'size'<~Integer> - Size in GiBs for volume
|
|
|
|
# * 'snapshotId'<~String> - Snapshot volume was created from, if any
|
|
|
|
# * 'status'<~String> - State of volume
|
|
|
|
# * 'volumeId'<~String> - Reference to volume
|
|
|
|
# * 'attachmentSet'<~Array>:
|
|
|
|
# * 'attachmentTime'<~Time> - Timestamp for attachment
|
|
|
|
# * 'device'<~String> - How value is exposed to instance
|
|
|
|
# * 'instanceId'<~String> - Reference to attached instance
|
|
|
|
# * 'status'<~String> - Attachment state
|
|
|
|
# * 'volumeId'<~String> - Reference to volume
|
|
|
|
def describe_volumes(volume_id = [])
|
2010-01-31 17:07:26 -05:00
|
|
|
params = AWS.indexed_param('VolumeId', volume_id)
|
2009-08-15 18:19:07 -04:00
|
|
|
request({
|
2010-03-16 01:15:33 -04:00
|
|
|
'Action' => 'DescribeVolumes',
|
|
|
|
:parser => Fog::Parsers::AWS::EC2::DescribeVolumes.new
|
|
|
|
}.merge!(params))
|
2009-08-15 18:19:07 -04:00
|
|
|
end
|
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
2009-08-15 18:19:07 -04:00
|
|
|
|
2010-03-16 18:46:21 -04:00
|
|
|
class Mock
|
2009-08-15 18:19:07 -04:00
|
|
|
|
|
|
|
def describe_volumes(volume_id = [])
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2009-08-20 22:25:52 -04:00
|
|
|
volume_id = [*volume_id]
|
2009-08-15 18:19:07 -04:00
|
|
|
if volume_id != []
|
2010-03-16 18:46:21 -04:00
|
|
|
volume_set = @data[:volumes].reject {|key,value| !volume_id.include?(key)}.values
|
2009-08-15 18:19:07 -04:00
|
|
|
else
|
2010-03-16 18:46:21 -04:00
|
|
|
volume_set = @data[:volumes].values
|
2009-08-15 18:19:07 -04:00
|
|
|
end
|
|
|
|
|
2010-04-13 17:42:16 -04:00
|
|
|
if volume_id.length == 0 || volume_id.length == volume_set.length
|
|
|
|
volume_set.each do |volume|
|
|
|
|
case volume['status']
|
|
|
|
when 'attaching'
|
|
|
|
if Time.now - volume['attachmentSet'].first['attachTime'] > Fog::Mock.delay
|
|
|
|
volume['attachmentSet'].first['status'] = 'attached'
|
|
|
|
volume['status'] = 'attached'
|
|
|
|
end
|
|
|
|
when 'creating'
|
|
|
|
if Time.now - volume['createTime'] > Fog::Mock.delay
|
|
|
|
volume['status'] = 'available'
|
|
|
|
end
|
|
|
|
when 'deleting'
|
|
|
|
if Time.now - @data[:deleted_at][volume['volumeId']] > Fog::Mock.delay
|
|
|
|
@data[:deleted_at].delete(volume['volumeId'])
|
|
|
|
@data[:volumes].delete(volume['volumeId'])
|
|
|
|
end
|
2009-08-15 18:19:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-01 17:07:26 -04:00
|
|
|
volume_set = volume_set.reject {|volume| !@data[:volumes][volume['volumeId']]}
|
2009-08-15 18:19:07 -04:00
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id,
|
|
|
|
'volumeSet' => volume_set
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response.status = 400
|
2009-11-20 14:08:08 -05:00
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
2009-08-15 18:19:07 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|