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

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

Instance Attribute Summary

Attributes inherited from Collection

#connection

Instance Method Summary collapse

Methods inherited from Collection

#clear, #create, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Fog::Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Attributes::InstanceMethods

#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

#initialize(attributes) ⇒ Servers

Returns a new instance of Servers.



20
21
22
23
# File 'lib/fog/aws/models/ec2/servers.rb', line 20

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

Instance Method Details

#all(server_id = @server_id) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/aws/models/ec2/servers.rb', line 25

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



37
38
39
40
41
42
43
# File 'lib/fog/aws/models/ec2/servers.rb', line 37

def get(server_id)
  if server_id
    all(server_id).first
  end
rescue Fog::Errors::NotFound
  nil
end