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
|
|
|
|
|
2009-09-25 12:01:51 -04:00
|
|
|
attribute :instance_id
|
|
|
|
|
2009-09-16 02:11:06 -04:00
|
|
|
def all(instance_id = [])
|
|
|
|
data = connection.describe_instances(instance_id)
|
2009-09-25 12:01:51 -04:00
|
|
|
instances = Fog::AWS::EC2::Instances.new(
|
|
|
|
:connection => connection,
|
|
|
|
:instance_id => instance_id
|
|
|
|
)
|
2009-09-16 02:11:06 -04:00
|
|
|
data['instancesSet'].each do |instance|
|
|
|
|
instances << Fog::AWS::EC2::Instances.new({
|
2009-09-19 15:21:31 -04:00
|
|
|
:connection => connection,
|
|
|
|
:instances => self
|
2009-09-16 02:11:06 -04:00
|
|
|
}.merge!(instance))
|
|
|
|
end
|
|
|
|
instances
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(attributes = {})
|
|
|
|
instance = new(attributes)
|
|
|
|
instance.save
|
|
|
|
instance
|
|
|
|
end
|
|
|
|
|
2009-09-25 12:01:51 -04:00
|
|
|
def get(instance_id)
|
|
|
|
all(instance_id).first
|
|
|
|
rescue Fog::Errors::BadRequest
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2009-09-16 02:11:06 -04:00
|
|
|
def new(attributes = {})
|
2009-09-20 12:21:03 -04:00
|
|
|
Fog::AWS::EC2::Instance.new(
|
|
|
|
attributes.merge!(
|
|
|
|
:connection => connection,
|
|
|
|
:instances => self
|
|
|
|
)
|
|
|
|
)
|
2009-09-16 02:11:06 -04:00
|
|
|
end
|
|
|
|
|
2009-09-25 12:01:51 -04:00
|
|
|
def reload
|
|
|
|
all(instance_id)
|
|
|
|
end
|
|
|
|
|
2009-09-16 02:11:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|