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/volumes.rb
2010-01-04 22:03:24 -08:00

60 lines
1.2 KiB
Ruby

module Fog
module AWS
class EC2
def volumes(attributes = {})
Fog::AWS::EC2::Volumes.new({
:connection => self
}.merge!(attributes))
end
class Volumes < Fog::Collection
attribute :volume_id
attribute :instance
model Fog::AWS::EC2::Volume
def initialize(attributes)
@volume_id ||= []
super
end
def all(volume_id = @volume_id)
@volume_id = volume_id
if @loaded
clear
end
@loaded = true
data = connection.describe_volumes(volume_id).body
volumes = []
data['volumeSet'].each do |volume|
volumes << new(volume)
end
if instance
volumes = volumes.select {|volume| volume.instance_id == instance.id}
end
self.replace(volumes)
end
def get(volume_id)
if volume_id
all(volume_id).first
end
rescue Excon::Errors::BadRequest
nil
end
def new(attributes = {})
if instance
super({ :instance => instance }.merge!(attributes))
else
super
end
end
end
end
end
end