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

58 lines
1.3 KiB
Ruby
Raw Normal View History

2009-08-14 12:19:40 -04:00
module Fog
module AWS
class EC2
2009-10-10 01:54:17 -04:00
def volumes(attributes = {})
Fog::AWS::EC2::Volumes.new({
:connection => self
}.merge!(attributes))
2009-08-14 12:19:40 -04:00
end
class Volumes < Fog::Collection
2009-09-24 00:23:54 -04:00
attribute :volume_id
attribute :instance
2009-09-24 00:23:54 -04:00
klass Fog::AWS::EC2::Volume
def initialize(attributes)
@volume_id ||= []
super
end
def all(volume_id = @volume_id)
2009-09-24 00:23:54 -04:00
data = connection.describe_volumes(volume_id).body
2009-09-26 22:42:08 -04:00
volumes = Fog::AWS::EC2::Volumes.new({
:connection => connection,
:volume_id => volume_id
2009-09-26 22:42:08 -04:00
}.merge!(attributes))
2009-08-14 12:19:40 -04:00
data['volumeSet'].each do |volume|
volumes << Fog::AWS::EC2::Volume.new({
:collection => volumes,
:connection => connection
2009-08-14 12:19:40 -04:00
}.merge!(volume))
end
if instance
volumes = volumes.select {|volume| volume.instance_id == instance.id}
2009-10-06 21:55:39 -04:00
end
2009-08-14 12:19:40 -04:00
volumes
end
2009-09-24 00:23:54 -04:00
def get(volume_id)
2009-10-22 23:46:15 -04:00
if volume_id
all(volume_id).first
end
2009-09-24 00:23:54 -04:00
rescue Fog::Errors::BadRequest
nil
end
2009-08-14 12:19:40 -04:00
def new(attributes = {})
super({ :instance => instance }.merge!(attributes))
2009-09-24 00:23:54 -04:00
end
2009-08-14 12:19:40 -04:00
end
end
end
end