2010-03-16 18:46:21 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
module EC2
|
|
|
|
class Real
|
2009-08-25 22:49:55 -04:00
|
|
|
|
|
|
|
# Detach an Amazon EBS volume from a running instance
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * volume_id<~String> - Id of amazon EBS volume to associate with instance
|
|
|
|
# * options<~Hash>:
|
|
|
|
# * 'Device'<~String> - Specifies how the device is exposed to the instance (e.g. "/dev/sdh")
|
|
|
|
# * 'Force'<~Boolean> - If true forces detach, can cause data loss/corruption
|
|
|
|
# * 'InstanceId'<~String> - Id of instance to associate volume with
|
|
|
|
#
|
|
|
|
# ==== Returns
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-25 22:49:55 -04:00
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'attachTime'<~Time> - Time of attachment was initiated at
|
|
|
|
# * 'device'<~String> - Device as it is exposed to the instance
|
|
|
|
# * 'instanceId'<~String> - Id of instance for volume
|
|
|
|
# * 'requestId'<~String> - Id of request
|
|
|
|
# * 'status'<~String> - Status of volume
|
|
|
|
# * 'volumeId'<~String> - Reference to volume
|
|
|
|
def detach_volume(volume_id, options = {})
|
|
|
|
request({
|
2010-03-16 01:15:33 -04:00
|
|
|
'Action' => 'DetachVolume',
|
|
|
|
'VolumeId' => volume_id,
|
2010-05-24 17:22:35 -04:00
|
|
|
:idempotent => true,
|
2010-03-16 01:15:33 -04:00
|
|
|
:parser => Fog::Parsers::AWS::EC2::DetachVolume.new
|
|
|
|
}.merge!(options))
|
2009-08-25 22:49:55 -04:00
|
|
|
end
|
|
|
|
|
2009-07-26 22:22:27 -04:00
|
|
|
end
|
|
|
|
|
2010-03-16 18:46:21 -04:00
|
|
|
class Mock
|
2009-08-25 22:49:55 -04:00
|
|
|
|
|
|
|
def detach_volume(volume_id, options = {})
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2009-08-25 22:49:55 -04:00
|
|
|
response.status = 200
|
2010-04-30 15:02:08 -04:00
|
|
|
if (volume = @data[:volumes][volume_id]) && !volume['attachmentSet'].empty?
|
2009-08-25 22:49:55 -04:00
|
|
|
data = volume['attachmentSet'].pop
|
2010-04-30 15:02:08 -04:00
|
|
|
volume['status'] = 'available'
|
2009-08-25 22:49:55 -04:00
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id
|
|
|
|
}.merge!(data)
|
2010-05-26 01:26:20 -04:00
|
|
|
response
|
2009-08-25 22:49:55 -04:00
|
|
|
else
|
2010-05-26 21:03:22 -04:00
|
|
|
raise Fog::AWS::EC2::NotFound.new("The volume '#{volume_id}' does not exist.")
|
2009-08-25 22:49:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-26 22:22:27 -04:00
|
|
|
end
|
|
|
|
end
|
2009-08-25 22:49:55 -04:00
|
|
|
end
|