1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/ec2/volume.rb

73 lines
1.8 KiB
Ruby
Raw Normal View History

2009-08-14 12:19:40 -04:00
module Fog
module AWS
class EC2
class Volume < Fog::Model
2009-10-09 15:16:00 -04:00
attribute :attach_time, 'attachTime'
attribute :availability_zone, 'availabilityZone'
attribute :create_time, 'createTime'
attribute :device
attribute :instance_id, 'instanceId'
attribute :size
attribute :snapshot_id, 'snapshotId'
2009-10-06 23:35:46 -04:00
attribute :status
attribute :volume_id, 'volumeId'
2009-08-14 12:19:40 -04:00
def initialize(attributes = {})
if attributes['attachmentSet']
2009-09-24 00:23:54 -04:00
attributes.merge!(attributes.delete('attachmentSet').first || {})
2009-08-14 12:19:40 -04:00
end
super
end
2009-09-20 12:21:03 -04:00
def destroy
2009-08-14 12:19:40 -04:00
connection.delete_volume(@volume_id)
true
2009-08-14 12:19:40 -04:00
end
2009-10-06 21:55:39 -04:00
def instance=(new_instance)
if !@volume_id
@instance = new_instance
elsif new_instance
@instance = nil
@instance_id = new_instance.instance_id
connection.attach_volume(@instance_id, @volume_id, @device)
end
2009-10-06 21:55:39 -04:00
end
2009-09-19 15:31:15 -04:00
def reload
2009-09-24 22:18:20 -04:00
new_attributes = volumes.get(@volume_id).attributes
2009-09-19 15:31:15 -04:00
merge_attributes(new_attributes)
end
2009-08-14 12:19:40 -04:00
def save
data = connection.create_volume(@availability_zone, @size, @snapshot_id).body
new_attributes = data.reject {|key,value| key == 'requestId'}
2009-09-24 00:23:54 -04:00
merge_attributes(new_attributes)
if @instance
instance = @instance
end
true
2009-08-14 12:19:40 -04:00
end
2009-09-06 13:48:12 -04:00
def snapshots
2009-09-30 01:02:33 -04:00
connection.snapshots(:volume_id => volume_id)
2009-09-06 13:48:12 -04:00
end
def volumes
@volumes
end
private
def volumes=(new_volumes)
@volumes = new_volumes
end
2009-08-14 12:19:40 -04:00
end
end
end
end