2012-08-28 17:10:47 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
|
|
|
class Attachment < Fog::Model
|
|
|
|
attribute :server_id, :aliases => 'serverId'
|
|
|
|
attribute :volume_id, :aliases => 'volumeId'
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
private
|
2012-08-28 17:10:47 -04:00
|
|
|
def server
|
|
|
|
collection.server
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|