2013-07-17 09:18:27 +02:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
|
|
|
class Real
|
2013-07-26 16:04:29 +02:00
|
|
|
# Request a new keypair to be created
|
|
|
|
# @param [String] key_name: unique name of the keypair to create
|
|
|
|
# @return [Excon::Response] response :
|
|
|
|
# * body [Hash]: -
|
|
|
|
# * 'keypair' [Hash]: -
|
|
|
|
# * 'fingerprint' [String]: unique fingerprint of the keypair
|
|
|
|
# * 'name' [String]: unique name of the keypair
|
|
|
|
# * 'private_key' [String]: the private key of the keypair (only available here, at creation time)
|
|
|
|
# * 'public_key' [String]: the public key of the keypair
|
|
|
|
# * 'user_id' [String]: the user id
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::NotFound]
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::BadRequest]
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::InternalServerError]
|
|
|
|
# @raise [Fog::Compute::RackspaceV2::ServiceError]
|
|
|
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/CreateKeyPair.html
|
2014-01-07 16:26:36 -06:00
|
|
|
def create_keypair(key_name, attributes = nil)
|
|
|
|
key_data = { 'name' => key_name }
|
|
|
|
|
|
|
|
if attributes.is_a?(String)
|
|
|
|
Fog::Logger.deprecation "Passing the public key as the 2nd arg is deprecated, please pass a hash of attributes."
|
|
|
|
key_data.merge!("public_key" => attributes)
|
|
|
|
end
|
|
|
|
|
2014-01-07 21:02:48 -06:00
|
|
|
key_data.merge!(attributes) if attributes.is_a?(Hash)
|
2014-01-07 16:26:36 -06:00
|
|
|
|
2013-07-17 09:18:27 +02:00
|
|
|
data = {
|
2014-01-07 16:26:36 -06:00
|
|
|
'keypair' => key_data
|
2013-07-17 09:18:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
request(
|
|
|
|
:method => 'POST',
|
|
|
|
:expects => 200,
|
|
|
|
:path => '/os-keypairs',
|
|
|
|
:body => Fog::JSON.encode(data)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2013-07-19 11:07:47 +02:00
|
|
|
|
|
|
|
class Mock
|
2014-01-07 16:26:36 -06:00
|
|
|
def create_keypair(key_name, attributes = nil)
|
2013-07-26 08:57:02 +02:00
|
|
|
# 409 response when already existing
|
2013-07-26 16:04:29 +02:00
|
|
|
raise Fog::Compute::RackspaceV2::ServiceError if not self.data[:keypairs].select { |k| key_name.include? k['keypair']['name'] }.first.nil?
|
2013-07-26 08:57:02 +02:00
|
|
|
|
2014-01-07 16:26:36 -06:00
|
|
|
if attributes.is_a?(String)
|
|
|
|
Fog::Logger.deprecation "Passing the public key as the 2nd arg is deprecated, please pass a hash of attributes."
|
|
|
|
end
|
|
|
|
|
2013-07-24 16:29:44 +02:00
|
|
|
k = self.data[:keypair]
|
2013-07-26 16:04:29 +02:00
|
|
|
k['name'] = key_name
|
2013-07-24 16:29:44 +02:00
|
|
|
self.data[:keypairs] << { 'keypair' => k }
|
2013-07-19 11:07:47 +02:00
|
|
|
|
2013-07-24 17:45:41 +02:00
|
|
|
response( :status => 200,
|
|
|
|
:body => { 'keypair' => k } )
|
2013-07-19 11:07:47 +02:00
|
|
|
end
|
|
|
|
end
|
2013-07-17 09:18:27 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|