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/compute/requests/aws/attach_volume.rb

86 lines
3.1 KiB
Ruby
Raw Normal View History

2010-03-16 18:46:21 -04:00
module Fog
module AWS
2010-09-08 17:40:02 -04:00
class Compute
2010-03-16 18:46:21 -04:00
class Real
2009-08-25 22:49:55 -04:00
2011-01-07 19:52:09 -05:00
require 'fog/compute/parsers/aws/attach_volume'
2010-06-12 18:31:17 -04:00
2009-08-25 22:49:55 -04:00
# Attach an Amazon EBS volume with a running instance, exposing as specified device
#
# ==== Parameters
# * instance_id<~String> - Id of instance to associate volume with
# * volume_id<~String> - Id of amazon EBS volume to associate with instance
# * device<~String> - Specifies how the device is exposed to the instance (e.g. "/dev/sdh")
#
# ==== 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
def attach_volume(instance_id, volume_id, device)
request(
'Action' => 'AttachVolume',
'VolumeId' => volume_id,
'InstanceId' => instance_id,
'Device' => device,
:idempotent => true,
2010-09-08 17:40:02 -04:00
:parser => Fog::Parsers::AWS::Compute::AttachVolume.new
)
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 attach_volume(instance_id, volume_id, device)
2009-11-20 14:08:08 -05:00
response = Excon::Response.new
if instance_id && volume_id && device
2009-08-25 22:49:55 -04:00
response.status = 200
2010-03-16 18:46:21 -04:00
instance = @data[:instances][instance_id]
volume = @data[:volumes][volume_id]
if instance && volume
2011-03-22 14:17:02 -04:00
unless volume['status'] == 'available'
raise Fog::AWS::Compute::Error.new("Client.VolumeInUse => Volume #{volume_id} is unavailable")
end
data = {
'attachTime' => Time.now,
'device' => device,
'instanceId' => instance_id,
'status' => 'attaching',
'volumeId' => volume_id
}
volume['attachmentSet'] = [data]
2010-04-01 17:07:26 -04:00
volume['status'] = 'attaching'
response.status = 200
response.body = {
'requestId' => Fog::AWS::Mock.request_id
}.merge!(data)
response
elsif !instance
2010-09-09 20:50:38 -04:00
raise Fog::AWS::Compute::NotFound.new("The instance ID '#{instance_id}' does not exist.")
elsif !volume
2010-09-09 20:50:38 -04:00
raise Fog::AWS::Compute::NotFound.new("The volume '#{volume_id}' does not exist.")
end
2009-08-25 22:49:55 -04:00
else
message = 'MissingParameter => '
if !instance_id
message << 'The request must contain the parameter instance_id'
elsif !volume_id
message << 'The request must contain the parameter volume_id'
else
message << 'The request must contain the parameter device'
end
2010-09-09 20:50:38 -04:00
raise Fog::AWS::Compute::Error.new(message)
2009-08-25 22:49:55 -04:00
end
end
end
end
end
2010-03-16 18:46:21 -04:00
end