Sha256: ad2876cd05e5e04ba39c45afda5f33ca7eda25754d878acdc766087b2a04f908

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

unless Fog.mocking?

  module Fog
    module AWS
      class EC2

        # Describe all or specified IP addresses.
        #
        # ==== Parameters
        # * public_ip<~Array> - List of ips to describe, defaults to all
        #
        # ==== Returns
        # * response<~Fog::AWS::Response>:
        #   * body<~Hash>:
        #     * 'requestId'<~String> - Id of request
        #     * 'addressesSet'<~Array>:
        #       * 'instanceId'<~String> - instance for ip address
        #       * 'publicIp'<~String> - ip address for instance
        def describe_addresses(public_ip = [])
          params = indexed_params('PublicIp', public_ip)
          request({
            'Action' => 'DescribeAddresses'
          }.merge!(params), Fog::Parsers::AWS::EC2::DescribeAddresses.new)
        end

      end
    end
  end

else

  module Fog
    module AWS
      class EC2

        def describe_addresses(public_ip = [])
          public_ip = [*public_ip]
          response = Fog::Response.new
          if public_ip != []
            addresses_set = @data[:addresses].reject {|key, value| !public_ip.include?(key)}.values
          else
            addresses_set = @data[:addresses].values
          end
          if public_ip.length == 0 || public_ip.length == addresses_set.length
            response.status = 200
            response.body = {
              'requestId'     => Fog::AWS::Mock.request_id,
              'addressesSet'  => addresses_set
            }
          else
            response.status = 400
            raise(Fog::Errors.status_error(200, 400, response))
          end
          response
        end

      end
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geemus-fog-0.0.0 lib/fog/aws/requests/ec2/describe_addresses.rb
geemus-fog-0.0.1 lib/fog/aws/requests/ec2/describe_addresses.rb
geemus-fog-0.0.3 lib/fog/aws/requests/ec2/describe_addresses.rb