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-10-30 03:11:50 -04:00
|
|
|
model Fog::AWS::EC2::Instance
|
2009-10-30 02:35:28 -04:00
|
|
|
|
2009-10-09 02:01:09 -04:00
|
|
|
def initialize(attributes)
|
|
|
|
@instance_id ||= []
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-10-30 02:35:28 -04:00
|
|
|
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({
|
2009-10-24 01:23:55 -04:00
|
|
|
: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
|
|
|
|
|
2009-09-25 12:01:51 -04:00
|
|
|
def get(instance_id)
|
2009-10-22 23:46:15 -04:00
|
|
|
if instance_id
|
|
|
|
all(instance_id).first
|
|
|
|
end
|
2009-11-08 15:16:52 -05:00
|
|
|
rescue Excon::Errors::BadRequest
|
2009-09-25 12:01:51 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2009-09-16 02:11:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|