2012-02-24 07:03:55 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
require 'fog/openstack/models/compute/metadata'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class OpenStack
|
|
|
|
|
|
|
|
class Volume < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :name, :aliases => 'displayName'
|
|
|
|
attribute :description, :aliases => 'displayDescription'
|
|
|
|
attribute :status
|
|
|
|
attribute :size
|
|
|
|
attribute :type, :aliases => 'volumeType'
|
|
|
|
attribute :snapshot_id, :aliases => 'snapshotId'
|
|
|
|
attribute :availability_zone, :aliases => 'availabilityZone'
|
|
|
|
attribute :created_at, :aliases => 'createdAt'
|
|
|
|
attribute :attachments
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(attributes)
|
2012-12-19 17:28:04 -05:00
|
|
|
# Old 'connection' is renamed as service and should be used instead
|
|
|
|
prepare_service_value(attributes)
|
2012-02-24 07:03:55 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
requires :name, :description, :size
|
2012-12-22 18:24:36 -05:00
|
|
|
data = service.create_volume(name, description, size, attributes)
|
2012-02-24 07:03:55 -05:00
|
|
|
merge_attributes(data.body['volume'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
2012-12-22 18:24:36 -05:00
|
|
|
service.delete_volume(id)
|
2012-02-24 07:03:55 -05:00
|
|
|
true
|
|
|
|
end
|
2012-03-01 07:24:36 -05:00
|
|
|
|
|
|
|
def attach(server_id, name)
|
|
|
|
requires :id
|
2012-12-22 18:24:36 -05:00
|
|
|
data = service.attach_volume(id, server_id, name)
|
2012-03-01 07:24:36 -05:00
|
|
|
merge_attributes(:attachments => attachments << data.body['volumeAttachment'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def detach(server_id, attachment_id)
|
|
|
|
requires :id
|
2012-12-22 18:24:36 -05:00
|
|
|
service.detach_volume(server_id, attachment_id)
|
2012-03-01 07:24:36 -05:00
|
|
|
true
|
|
|
|
end
|
2012-02-24 07:03:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|