Sha256: ff6a68c46bf1c4e67a4b831bfdcf2fdf3b89db673f1dc74d5c72ddb5da498dfa

Contents?: true

Size: 1018 Bytes

Versions: 33

Compression:

Stored size: 1018 Bytes

Contents

require 'fog/collection'
require 'fog/aws/models/ec2/server'

module Fog
  module AWS
    module EC2

      module Collections
        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 Fog::Errors::NotFound
          nil
        end

      end

    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
fog-0.2.10 lib/fog/aws/models/ec2/servers.rb
fog-0.2.9 lib/fog/aws/models/ec2/servers.rb
fog-0.2.8 lib/fog/aws/models/ec2/servers.rb
fog-0.2.7 lib/fog/aws/models/ec2/servers.rb
fog-0.2.6 lib/fog/aws/models/ec2/servers.rb
fog-0.2.5 lib/fog/aws/models/ec2/servers.rb
fog-0.2.4 lib/fog/aws/models/ec2/servers.rb
fog-0.2.3 lib/fog/aws/models/ec2/servers.rb
fog-0.2.2 lib/fog/aws/models/ec2/servers.rb
fog-0.2.1 lib/fog/aws/models/ec2/servers.rb
fog-0.2.0 lib/fog/aws/models/ec2/servers.rb
fog-0.1.10 lib/fog/aws/models/ec2/servers.rb
fog-0.1.9 lib/fog/aws/models/ec2/servers.rb