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/instances.rb

50 lines
1.1 KiB
Ruby
Raw Normal View History

2009-09-16 02:11:06 -04:00
module Fog
module AWS
class EC2
def instances
Fog::AWS::EC2::Instances.new(:connection => self)
end
class Instances < Fog::Collection
attribute :instance_id
model Fog::AWS::EC2::Instance
2009-10-09 02:01:09 -04:00
def initialize(attributes)
@instance_id ||= []
super
end
def all(instance_id = @instance_id)
2009-10-09 02:01:09 -04:00
data = connection.describe_instances(instance_id).body
2009-09-26 22:42:08 -04:00
instances = Fog::AWS::EC2::Instances.new({
2009-10-09 02:01:09 -04:00
:connection => connection,
:instance_id => instance_id
2009-09-26 22:42:08 -04:00
}.merge!(attributes))
2009-10-09 02:01:09 -04:00
data['reservationSet'].each do |reservation|
reservation['instancesSet'].each do |instance|
instances << Fog::AWS::EC2::Instance.new({
:collection => instances,
:connection => connection
2009-10-09 02:01:09 -04:00
}.merge!(instance))
end
2009-09-16 02:11:06 -04:00
end
instances
end
def get(instance_id)
2009-10-22 23:46:15 -04:00
if instance_id
all(instance_id).first
end
rescue Excon::Errors::BadRequest
nil
end
2009-09-16 02:11:06 -04:00
end
end
end
end