Class: Fog::AWS::EC2::Servers

Inherits:
Collection show all
Defined in:
lib/fog/aws/models/ec2/servers.rb

Instance Method Summary collapse

Methods inherited from Collection

#_dump, _load, aliases, attribute, #attributes, attributes, #connection, #connection=, #create, #inspect, #load, #merge_attributes, model, #model, #new, #reload, #table, #to_json

Constructor Details

#initialize(attributes) ⇒ Servers

Returns a new instance of Servers.


26
27
28
29
# File 'lib/fog/aws/models/ec2/servers.rb', line 26

def initialize(attributes)
  @server_id ||= []
  super
end

Instance Method Details

#all(server_id = @server_id) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/aws/models/ec2/servers.rb', line 31

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

#get(server_id) ⇒ Object


43
44
45
46
47
48
49
# File 'lib/fog/aws/models/ec2/servers.rb', line 43

def get(server_id)
  if server_id
    all(server_id).first
  end
rescue Excon::Errors::BadRequest
  nil
end