mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
61 lines
1.6 KiB
Ruby
61 lines
1.6 KiB
Ruby
module Fog
|
|
module AWS
|
|
class EC2
|
|
|
|
class Volume < Fog::Model
|
|
|
|
identity :volume_id, 'volumeId'
|
|
|
|
attribute :attach_time, 'attachTime'
|
|
attribute :availability_zone, 'availabilityZone'
|
|
attribute :create_time, 'createTime'
|
|
attribute :device
|
|
attribute :instance_id, 'instanceId'
|
|
attribute :size
|
|
attribute :snapshot_id, 'snapshotId'
|
|
attribute :status
|
|
|
|
def initialize(attributes = {})
|
|
if attributes['attachmentSet']
|
|
attributes.merge!(attributes.delete('attachmentSet').first || {})
|
|
end
|
|
super
|
|
end
|
|
|
|
def destroy
|
|
connection.delete_volume(@volume_id)
|
|
true
|
|
end
|
|
|
|
def instance=(new_instance)
|
|
if !@volume_id
|
|
@instance = new_instance
|
|
if new_instance
|
|
@availability_zone = new_instance.availability_zone
|
|
end
|
|
elsif new_instance
|
|
@instance = nil
|
|
@instance_id = new_instance.instance_id
|
|
connection.attach_volume(@instance_id, @volume_id, @device)
|
|
end
|
|
end
|
|
|
|
def save
|
|
data = connection.create_volume(@availability_zone, @size, @snapshot_id).body
|
|
new_attributes = data.reject {|key,value| key == 'requestId'}
|
|
merge_attributes(new_attributes)
|
|
if @instance
|
|
self.instance = @instance
|
|
end
|
|
true
|
|
end
|
|
|
|
def snapshots
|
|
connection.snapshots(:volume_id => volume_id)
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|