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
2009-09-25 09:01:51 -07:00

57 lines
1.2 KiB
Ruby

module Fog
module AWS
class EC2
def instances
Fog::AWS::EC2::Instances.new(:connection => self)
end
class Instances < Fog::Collection
attribute :instance_id
def all(instance_id = [])
data = connection.describe_instances(instance_id)
instances = Fog::AWS::EC2::Instances.new(
:connection => connection,
:instance_id => instance_id
)
data['instancesSet'].each do |instance|
instances << Fog::AWS::EC2::Instances.new({
:connection => connection,
:instances => self
}.merge!(instance))
end
instances
end
def create(attributes = {})
instance = new(attributes)
instance.save
instance
end
def get(instance_id)
all(instance_id).first
rescue Fog::Errors::BadRequest
nil
end
def new(attributes = {})
Fog::AWS::EC2::Instance.new(
attributes.merge!(
:connection => connection,
:instances => self
)
)
end
def reload
all(instance_id)
end
end
end
end
end