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/compute/detach_volume.rb

66 lines
2.4 KiB
Ruby
Raw Normal View History

2010-03-16 18:46:21 -04:00
module Fog
module Compute
class AWS
2010-03-16 18:46:21 -04:00
class Real
2009-08-25 22:49:55 -04:00
require 'fog/aws/parsers/compute/detach_volume'
2010-06-12 18:31:17 -04:00
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
# * 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
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DetachVolume.html]
2009-08-25 22:49:55 -04:00
def detach_volume(volume_id, options = {})
request({
'Action' => 'DetachVolume',
'VolumeId' => volume_id,
:idempotent => true,
:parser => Fog::Parsers::Compute::AWS::DetachVolume.new
}.merge!(options))
2009-08-25 22:49:55 -04:00
end
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
if (volume = self.data[:volumes][volume_id])
if !volume['attachmentSet'].empty?
data = volume['attachmentSet'].pop
volume['status'] = 'available'
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id
}.merge!(data)
response
else
# real response has spacing issue below
raise Fog::Compute::AWS::Error.new("IncorrectState => Volume '#{volume_id}'is in the 'available' state.")
end
2009-08-25 22:49:55 -04:00
else
raise Fog::Compute::AWS::NotFound.new("The volume '#{volume_id}' does not exist.")
2009-08-25 22:49:55 -04:00
end
end
end
end
end
2009-08-25 22:49:55 -04:00
end