2010-03-16 18:46:21 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
module EC2
|
|
|
|
class Real
|
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
|
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 attach_volume(instance_id, volume_id, device)
|
2010-03-16 01:15:33 -04:00
|
|
|
request(
|
|
|
|
'Action' => 'AttachVolume',
|
|
|
|
'VolumeId' => volume_id,
|
|
|
|
'InstanceId' => instance_id,
|
|
|
|
'Device' => device,
|
2010-05-24 17:22:35 -04:00
|
|
|
:idempotent => true,
|
2010-03-16 01:15:33 -04:00
|
|
|
:parser => Fog::Parsers::AWS::EC2::AttachVolume.new
|
|
|
|
)
|
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 attach_volume(instance_id, volume_id, device)
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2009-10-22 23:46:46 -04:00
|
|
|
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]
|
2009-10-22 23:46:46 -04:00
|
|
|
if instance && volume
|
|
|
|
data = {
|
|
|
|
'attachTime' => Time.now,
|
|
|
|
'device' => device,
|
|
|
|
'instanceId' => instance_id,
|
|
|
|
'status' => 'attaching',
|
|
|
|
'volumeId' => volume_id
|
|
|
|
}
|
2010-04-01 00:28:32 -04:00
|
|
|
volume['attachmentSet'] = [data]
|
2010-04-01 17:07:26 -04:00
|
|
|
volume['status'] = 'attaching'
|
2009-10-22 23:46:46 -04:00
|
|
|
response.status = 200
|
|
|
|
response.body = {
|
|
|
|
'requestId' => Fog::AWS::Mock.request_id
|
|
|
|
}.merge!(data)
|
|
|
|
else
|
|
|
|
response.status = 400
|
2009-11-20 14:08:08 -05:00
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
2009-10-22 23:46:46 -04:00
|
|
|
end
|
2009-08-25 22:49:55 -04:00
|
|
|
else
|
|
|
|
response.status = 400
|
2009-10-22 23:46:46 -04:00
|
|
|
response.body = {
|
|
|
|
'Code' => 'MissingParameter'
|
|
|
|
}
|
|
|
|
if !instance_id
|
|
|
|
response['Message'] = 'The request must contain the parameter instance_id'
|
|
|
|
elsif !volume_id
|
|
|
|
response['Message'] = 'The request must contain the parameter volume_id'
|
|
|
|
else
|
|
|
|
response['Message'] = 'The request must contain the parameter device'
|
|
|
|
end
|
2009-08-25 22:49:55 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-26 22:22:27 -04:00
|
|
|
end
|
|
|
|
end
|
2010-03-16 18:46:21 -04:00
|
|
|
end
|