Sha256: 3b82447d5678ed011df44539a717960e749b9afb933e1e9fcfaab73914e20c9c

Contents?: true

Size: 910 Bytes

Versions: 4

Compression:

Stored size: 910 Bytes

Contents

module Fog
  module AWS
    class EC2

      def servers
        Fog::AWS::EC2::Servers.new(:connection => self)
      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
          )
        end

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

      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fog-0.0.51 lib/fog/aws/models/ec2/servers.rb
fog-0.0.50 lib/fog/aws/models/ec2/servers.rb
fog-0.0.49 lib/fog/aws/models/ec2/servers.rb
fog-0.0.48 lib/fog/aws/models/ec2/servers.rb