mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|compute_v2] added key_name and modified key_pair= to take KeyPair objects as well as strings in order to be more compatible with other fog providers.
This commit is contained in:
parent
f531f0bdd7
commit
1b4e14f2df
2 changed files with 41 additions and 3 deletions
|
@ -137,11 +137,17 @@ module Fog
|
||||||
# @return [String] The image Id.
|
# @return [String] The image Id.
|
||||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Images-d1e4435.html
|
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Images-d1e4435.html
|
||||||
attribute :image_id, :aliases => 'image', :squash => 'id'
|
attribute :image_id, :aliases => 'image', :squash => 'id'
|
||||||
|
|
||||||
# @!attribute [r] password
|
# @!attribute [r] password
|
||||||
# @return [String] Password for system adminstrator account.
|
# @return [String] Password for system adminstrator account.
|
||||||
# @note This value is ONLY populated on server creation.
|
# @note This value is ONLY populated on server creation.
|
||||||
attr_reader :password
|
attr_reader :password
|
||||||
|
|
||||||
|
# @!attribute [rw] key_name
|
||||||
|
# @return [String] The name of the key_pair used for server.
|
||||||
|
# @note The key_pair/key_name is used to specify the keypair used for server creation. It is not populated by cloud servers.
|
||||||
|
attribute :key_name
|
||||||
|
|
||||||
|
|
||||||
def initialize(attributes={})
|
def initialize(attributes={})
|
||||||
@service = attributes[:service]
|
@service = attributes[:service]
|
||||||
|
@ -170,6 +176,27 @@ module Fog
|
||||||
metadata.from_hash(hash)
|
metadata.from_hash(hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the key pair based on the key_name of the server
|
||||||
|
# @return [KeyPair]
|
||||||
|
# @note The key_pair/key_name is used to specify the keypair used for server creation. It is not populated by cloud servers.
|
||||||
|
def key_pair
|
||||||
|
requires :key_name
|
||||||
|
|
||||||
|
service.key_pairs.get(key_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sets the key_pair used by the server.
|
||||||
|
# @param new_keypair [KeyPair] key_pair object for server
|
||||||
|
# @note The key_pair/key_name is used to specify the keypair used for server creation. It is not populated by cloud servers.
|
||||||
|
def key_pair=(new_keypair)
|
||||||
|
if new_keypair.is_a?(String)
|
||||||
|
Fog::Logger.deprecation("#key_pair= should be used to set KeyPair objects. Please use #key_name method instead")
|
||||||
|
self.key_name = new_keypair
|
||||||
|
else
|
||||||
|
self.key_name = new_keypair && new_keypair.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Saves the server.
|
# Saves the server.
|
||||||
# Creates server if it is new, otherwise it will update server attributes name, accessIPv4, and accessIPv6.
|
# Creates server if it is new, otherwise it will update server attributes name, accessIPv4, and accessIPv6.
|
||||||
# @return [Boolean] true if server has started saving
|
# @return [Boolean] true if server has started saving
|
||||||
|
@ -201,11 +228,16 @@ module Fog
|
||||||
requires :name, :image_id, :flavor_id
|
requires :name, :image_id, :flavor_id
|
||||||
modified_options = Marshal.load(Marshal.dump(options))
|
modified_options = Marshal.load(Marshal.dump(options))
|
||||||
|
|
||||||
|
if attributes[:keypair]
|
||||||
|
Fog::Logger.deprecation(":keypair has been depreciated. Please use :key_name instead.")
|
||||||
|
modified_options[:key_name] = attributes[:keypair]
|
||||||
|
end
|
||||||
|
|
||||||
modified_options[:networks] ||= attributes[:networks]
|
modified_options[:networks] ||= attributes[:networks]
|
||||||
modified_options[:disk_config] = disk_config unless disk_config.nil?
|
modified_options[:disk_config] = disk_config unless disk_config.nil?
|
||||||
modified_options[:metadata] = metadata.to_hash unless @metadata.nil?
|
modified_options[:metadata] = metadata.to_hash unless @metadata.nil?
|
||||||
modified_options[:personality] = personality unless personality.nil?
|
modified_options[:personality] = personality unless personality.nil?
|
||||||
modified_options[:keypair] ||= attributes[:keypair]
|
modified_options[:key_name] ||= attributes[:key_name]
|
||||||
|
|
||||||
if modified_options[:networks]
|
if modified_options[:networks]
|
||||||
modified_options[:networks].map! { |id| { :uuid => id } }
|
modified_options[:networks].map! { |id| { :uuid => id } }
|
||||||
|
|
|
@ -59,7 +59,13 @@ module Fog
|
||||||
{ :uuid => '00000000-0000-0000-0000-000000000000' },
|
{ :uuid => '00000000-0000-0000-0000-000000000000' },
|
||||||
{ :uuid => '11111111-1111-1111-1111-111111111111' }
|
{ :uuid => '11111111-1111-1111-1111-111111111111' }
|
||||||
]
|
]
|
||||||
data['server']['key_name'] = options[:keypair] unless options[:keypair].nil?
|
|
||||||
|
if options[:keypair]
|
||||||
|
Fog::Logger.deprecation(":keypair has been depreciated. Please use :key_name instead.")
|
||||||
|
options[:key_name] = options[:keypair]
|
||||||
|
end
|
||||||
|
|
||||||
|
data['server']['key_name'] = options[:key_name] unless options[:key_name].nil?
|
||||||
|
|
||||||
request(
|
request(
|
||||||
:body => Fog::JSON.encode(data),
|
:body => Fog::JSON.encode(data),
|
||||||
|
|
Loading…
Reference in a new issue