Sha256: 134913e0bb0a27a1a841a901f1fd027f80d6c606f98c693dd2c54571287a8473

Contents?: true

Size: 1.92 KB

Versions: 83

Compression:

Stored size: 1.92 KB

Contents

module Fog
  module Compute
    class IBM
      class Real

        # Requests a new keypair to be created
        #
        # ==== Parameters
        # * name<~String> - name to give new key
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'keyName'<~String>: name of new key
        #     * 'lastModifiedTime'<~Integer>: epoch time of last modification
        #     * 'default'<~Bool>: is default?
        #     * 'instanceIds'<~Array>: id's of instances using key (should be empty upon creation)
        #     * 'keyMaterial'<~String>: private key contents
        def create_key(name, public_key=nil)
          request(
            :method   => 'POST',
            :expects  => 200,
            :path     => '/keys',
            :body => {
              'name' => name,
              'publicKey' => public_key
            }
          )
        end

      end

      class Mock

        # SmartCloud returns the private key when create_key is called
        # We need to store both the private and public key for later use
        def create_key(name, public_key=nil)
          response = Excon::Response.new
          response.status = 200
          attributes  = {
            "keyName"           => name,
            "lastModifiedTime"  => Fog::IBM::Mock.launch_time,
            "default"           => false,
            "instanceIds"       => [],
          }
          if public_key.nil?
            private_key   = Fog::IBM::Mock.key_material
            public_key    = private_key.public_key
            response.body = attributes.merge("keyMaterial" => private_key.to_s)
          else
            response.body = { 'success' => true }
          end
          self.data[:keys][name] = attributes.merge("keyMaterial" => public_key.to_s)
          self.data[:private_keys][name] = attributes.merge("keyMaterial" => private_key.to_s)
          response
        end

      end
    end
  end
end

Version data entries

83 entries across 83 versions & 14 rubygems

Version Path
fog-1.22.0 lib/fog/ibm/requests/compute/create_key.rb
fog-1.21.0 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/ibm/requests/compute/create_key.rb
fog-1.20.0 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/ibm/requests/compute/create_key.rb
fog-1.19.0 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/ibm/requests/compute/create_key.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/ibm/requests/compute/create_key.rb