2009-08-15 18:19:07 -04:00
|
|
|
unless Fog.mocking?
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
|
|
|
# Describe all or specified volumes.
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * volume_id<~Array> - List of volumes to describe, defaults to all
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Fog::AWS::Response>:
|
|
|
|
# * 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 = [])
|
|
|
|
params = indexed_params('VolumeId', volume_id)
|
|
|
|
request({
|
|
|
|
'Action' => 'DescribeVolumes'
|
|
|
|
}.merge!(params), Fog::Parsers::AWS::EC2::DescribeVolumes.new)
|
|
|
|
end
|
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
2009-08-15 18:19:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
2009-07-13 22:14:59 -04:00
|
|
|
|
2009-08-15 18:19:07 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
|
|
|
def describe_volumes(volume_id = [])
|
|
|
|
volume_id = [*volume_id]
|
|
|
|
response = Fog::Response.new
|
|
|
|
if volume_id != []
|
2009-08-16 15:32:36 -04:00
|
|
|
volume_set = @data[:volumes].reject {|key,value| !volume_id.include?(key)}.values
|
2009-08-15 18:19:07 -04:00
|
|
|
else
|
2009-08-16 15:32:36 -04:00
|
|
|
volume_set = @data[:volumes].values
|
2009-08-15 18:19:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
volume_set.each do |volume|
|
|
|
|
case volume['status']
|
|
|
|
when 'creating'
|
|
|
|
if Time.now - volume['createTime'] > 2
|
|
|
|
volume['status'] = 'available'
|
|
|
|
end
|
|
|
|
when 'deleting'
|
|
|
|
if Time.now - @data[:deleted_at][volume['volumeId']] > 2
|
|
|
|
@data[:deleted_at].delete(volume['volumeId'])
|
2009-08-16 15:32:36 -04:00
|
|
|
@data[:volumes].delete(volume['volumeId'])
|
2009-08-15 18:19:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if volume_id.length == 0 || volume_id.length == volume_set.length
|
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id,
|
|
|
|
'volumeSet' => volume_set
|
|
|
|
}
|
|
|
|
else
|
|
|
|
response.status = 400
|
2009-08-17 01:19:35 -04:00
|
|
|
raise(Fog::Errors.status_error(200, 400, response))
|
2009-08-15 18:19:07 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
end
|
2009-08-15 18:19:07 -04:00
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|