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/servers.rb
2010-03-16 15:46:21 -07:00

55 lines
1.1 KiB
Ruby

require 'fog/collection'
require 'fog/aws/models/ec2/server'
module Fog
module AWS
module EC2
class Mock
def servers
Fog::AWS::EC2::Servers.new(:connection => self)
end
end
class Real
def servers
Fog::AWS::EC2::Servers.new(:connection => self)
end
end
class Servers < Fog::Collection
attribute :server_id
model Fog::AWS::EC2::Server
def initialize(attributes)
@server_id ||= []
super
end
def all(server_id = @server_id)
@server_id = server_id
data = connection.describe_instances(server_id).body
load(
data['reservationSet'].map do |reservation|
reservation['instancesSet'].map do |instance|
instance.merge(:groups => reservation['groupSet'])
end
end.flatten
)
end
def get(server_id)
if server_id
all(server_id).first
end
rescue Excon::Errors::BadRequest
nil
end
end
end
end
end