2009-08-14 12:19:40 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EC2
|
|
|
|
|
|
|
|
class Volume < Fog::Model
|
|
|
|
|
2009-09-05 23:50:40 -04:00
|
|
|
attribute :attachment_time, 'attachmentTime'
|
|
|
|
attribute :availability_zone, 'availabilityZone'
|
2009-09-18 03:01:10 -04:00
|
|
|
attribute :create_time, 'createTime'
|
|
|
|
attribute :device
|
2009-09-05 23:50:40 -04:00
|
|
|
attribute :instance_id, 'instanceId'
|
|
|
|
attribute :size
|
|
|
|
attribute :snapshot_id, 'snapshotId'
|
|
|
|
attribute :status, 'status'
|
|
|
|
attribute :volume_id, 'volumeId'
|
2009-08-14 12:19:40 -04:00
|
|
|
|
|
|
|
def initialize(attributes = {})
|
|
|
|
if attributes['attachmentSet']
|
|
|
|
attributes.merge!(attributes.delete('attachmentSet'))
|
|
|
|
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)
|
2009-09-05 23:50:40 -04:00
|
|
|
true
|
2009-08-14 12:19:40 -04:00
|
|
|
end
|
|
|
|
|
2009-09-19 15:31:15 -04:00
|
|
|
def reload
|
|
|
|
new_attributes = volumes.all(@volume_id).first.attributes
|
|
|
|
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'}
|
|
|
|
update_attributes(new_attributes)
|
2009-09-05 23:50:40 -04:00
|
|
|
true
|
2009-08-14 12:19:40 -04:00
|
|
|
end
|
|
|
|
|
2009-09-06 13:48:12 -04:00
|
|
|
def snapshots
|
2009-09-19 15:31:15 -04:00
|
|
|
connection.snapshots.all.select {|snapshot| snapshot.volume_id == @volume_id}
|
2009-09-06 13:48:12 -04:00
|
|
|
end
|
|
|
|
|
2009-09-19 15:21:31 -04:00
|
|
|
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
|