2012-07-09 20:58:46 -04:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class HP
|
|
|
|
class Real
|
|
|
|
|
|
|
|
# Attach a block storage volume to an existing server
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * server_id<~Integer> - Id of server to attach the volume to
|
|
|
|
# * volume_id<~Integer> - Id of the volume to be attached to the server
|
|
|
|
# * device<~String> - Device name that is the mount point that the volume will be attached to. e.g. /dev/sdf
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'volumeAttachment'<~Hash>:
|
|
|
|
# * <~Hash>
|
|
|
|
# * 'volumeId':<~Integer> - The volume id
|
|
|
|
# * 'device':<~String> - The name of the device
|
|
|
|
def attach_volume(server_id, volume_id, device)
|
|
|
|
data = { 'volumeAttachment' =>
|
|
|
|
{ 'volumeId' => volume_id,
|
|
|
|
'device' => device
|
|
|
|
}
|
|
|
|
}
|
|
|
|
response = request(
|
2013-01-18 15:08:27 -05:00
|
|
|
:body => Fog::JSON.encode(data),
|
2012-07-09 20:58:46 -04:00
|
|
|
:expects => 200,
|
|
|
|
:method => 'POST',
|
|
|
|
:path => "servers/#{server_id}/os-volume_attachments"
|
|
|
|
)
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock # :nodoc:all
|
|
|
|
|
|
|
|
def attach_volume(server_id, volume_id, device)
|
|
|
|
response = Excon::Response.new
|
|
|
|
if server = self.data[:servers][server_id]
|
|
|
|
# mock the case when the volume is already attached to the server
|
|
|
|
if server['volumeAttachments'] && server['volumeAttachments'].select {|v| v['id'] == volume_id}
|
|
|
|
response.status = 400
|
|
|
|
response.body = '{"badRequest": {"message": "Volume status must be available", "code": 400}}'
|
|
|
|
raise(Excon::Errors.status_error({:expects => 200}, response))
|
|
|
|
else
|
|
|
|
resp_data = { "volumeAttachment" =>
|
|
|
|
{
|
|
|
|
"volumeId" => volume_id,
|
2012-07-12 01:03:41 -04:00
|
|
|
"id" => volume_id
|
2012-07-09 20:58:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
response.body = resp_data
|
|
|
|
response.status = 200
|
|
|
|
|
|
|
|
data = {
|
2012-07-12 01:03:41 -04:00
|
|
|
"device" => device,
|
2012-07-09 20:58:46 -04:00
|
|
|
"serverId" => server_id,
|
2012-07-12 01:03:41 -04:00
|
|
|
"id" => volume_id,
|
2012-07-09 20:58:46 -04:00
|
|
|
"volumeId" => volume_id,
|
|
|
|
}
|
|
|
|
if server['volumeAttachments']
|
|
|
|
server['volumeAttachments'] << data
|
|
|
|
else
|
|
|
|
server['volumeAttachments'] = [data]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise Fog::Compute::HP::NotFound
|
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|