2012-08-28 17:10:47 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
|
|
|
class Attachment < Fog::Model
|
2014-02-19 07:30:59 -05:00
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# @!attribute [r] server_id
|
2014-02-19 07:30:59 -05:00
|
|
|
# @return [String] The server id
|
2012-08-28 17:10:47 -04:00
|
|
|
attribute :server_id, :aliases => 'serverId'
|
2014-02-19 07:30:59 -05:00
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# @!attribute [r] volume_id
|
2014-02-19 07:30:59 -05:00
|
|
|
# @return [String] The volume id
|
2012-08-28 17:10:47 -04:00
|
|
|
attribute :volume_id, :aliases => 'volumeId'
|
2014-02-19 07:30:59 -05:00
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# @!attribute [r] device
|
2014-02-19 07:30:59 -05:00
|
|
|
# @return [String]device name of the device /dev/xvd[a-p]
|
2012-08-28 17:10:47 -04:00
|
|
|
attribute :device
|
|
|
|
|
2013-01-09 15:54:02 -05:00
|
|
|
def initialize(new_attributes = {})
|
|
|
|
super(new_attributes)
|
|
|
|
server_id = server.id if server #server id should come from collection
|
|
|
|
self
|
|
|
|
end
|
2014-02-19 07:30:59 -05:00
|
|
|
|
|
|
|
# Attaches volume to volume to server.
|
2013-01-30 10:05:10 -05:00
|
|
|
# Requires :server_id, :volume_id, and device to be populated
|
|
|
|
# @return [Boolean] true if volume is attaching
|
2013-04-15 14:12:14 -04:00
|
|
|
# @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
2013-01-30 10:05:10 -05:00
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Attach_Volume_to_Server.html
|
2012-08-28 17:10:47 -04:00
|
|
|
def save
|
2013-01-09 15:54:02 -05:00
|
|
|
requires :server_id, :volume_id, :device
|
|
|
|
data = service.attach_volume(server_id, volume_id, device)
|
2012-08-28 17:10:47 -04:00
|
|
|
merge_attributes(data.body['volumeAttachment'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# Detaches volume from server
|
|
|
|
# @return [Boolean] true if volume is detaching
|
2013-04-15 14:12:14 -04:00
|
|
|
# @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
2013-01-30 10:05:10 -05:00
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Delete_Volume_Attachment.html
|
2012-08-28 17:10:47 -04:00
|
|
|
def destroy
|
2013-01-09 15:54:02 -05:00
|
|
|
requires :server_id, :volume_id
|
|
|
|
service.delete_attachment(server_id, volume_id)
|
2012-08-28 17:10:47 -04:00
|
|
|
true
|
|
|
|
end
|
2013-01-09 15:54:02 -05:00
|
|
|
alias :detach :destroy
|
2014-02-19 07:30:59 -05:00
|
|
|
|
2013-01-09 15:54:02 -05:00
|
|
|
private
|
2012-08-28 17:10:47 -04:00
|
|
|
def server
|
|
|
|
collection.server
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|