Sha256: efae5f943d9454d77681004da1c7ad4a1dbd4660103686ecb442a283ffb4ecff

Contents?: true

Size: 1.54 KB

Versions: 27

Compression:

Stored size: 1.54 KB

Contents

unless Fog.mocking?

  module Fog
    module AWS
      class EC2

        # Create a new key pair
        #
        # ==== Parameters
        # * key_name<~String> - Unique name for key pair.
        #
        # ==== Returns
        # * response<~Fog::AWS::Response>:
        #   * body<~Hash>:
        #     * 'keyFingerprint'<~String> - SHA-1 digest of DER encoded private key
        #     * 'keyMaterial'<~String> - Unencrypted encoded PEM private key
        #     * 'keyName'<~String> - Name of key
        #     * 'requestId'<~String> - Id of request
        def create_key_pair(key_name)
          request({
            'Action' => 'CreateKeyPair',
            'KeyName' => key_name
          }, Fog::Parsers::AWS::EC2::CreateKeyPair.new)
        end

      end
    end
  end

else

  module Fog
    module AWS
      class EC2

        def create_key_pair(key_name)
          response = Fog::Response.new
          unless Fog::AWS::EC2.data[:key_pairs][key_name]
            response.status = 200
            data = {
              'keyFingerprint'  => Fog::AWS::Mock.key_fingerprint,
              'keyMaterial'     => Fog::AWS::Mock.key_material,
              'keyName'         => key_name
            }
            Fog::AWS::EC2.data[:key_pairs][key_name] = data
            response.body = {
              'requestId' => Fog::AWS::Mock.request_id
            }.merge!(data)
          else
            response.status = 400
            raise(Fog::Errors.status_error(200, 400, response))
          end
          response
        end

      end
    end
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
fog-0.0.29 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.28 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.27 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.26 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.25 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.24 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.23 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.22 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.21 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.20 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.19 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.18 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.17 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.16 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.15 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.14 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.13 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.12 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.11 lib/fog/aws/requests/ec2/create_key_pair.rb
fog-0.0.10 lib/fog/aws/requests/ec2/create_key_pair.rb