mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2606 from rackspace/key_pairs
[rackspace|compute_v2] added key_name and modified key_pair= to KeyPair Objects
This commit is contained in:
commit
65d25f074d
2 changed files with 41 additions and 3 deletions
|
@ -137,10 +137,16 @@ module Fog
|
|||
# @return [String] The image Id.
|
||||
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Images-d1e4435.html
|
||||
attribute :image_id, :aliases => 'image', :squash => 'id'
|
||||
|
||||
# @!attribute [r] password
|
||||
# @return [String] Password for system adminstrator account.
|
||||
# @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={})
|
||||
|
@ -170,6 +176,27 @@ module Fog
|
|||
metadata.from_hash(hash)
|
||||
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.
|
||||
# Creates server if it is new, otherwise it will update server attributes name, accessIPv4, and accessIPv6.
|
||||
# @return [Boolean] true if server has started saving
|
||||
|
@ -201,11 +228,16 @@ module Fog
|
|||
requires :name, :image_id, :flavor_id
|
||||
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[:disk_config] = disk_config unless disk_config.nil?
|
||||
modified_options[:metadata] = metadata.to_hash unless @metadata.nil?
|
||||
modified_options[:personality] = personality unless personality.nil?
|
||||
modified_options[:keypair] ||= attributes[:keypair]
|
||||
modified_options[:key_name] ||= attributes[:key_name]
|
||||
|
||||
if modified_options[:networks]
|
||||
modified_options[:networks].map! { |id| { :uuid => id } }
|
||||
|
|
|
@ -59,7 +59,13 @@ module Fog
|
|||
{ :uuid => '00000000-0000-0000-0000-000000000000' },
|
||||
{ :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(
|
||||
:body => Fog::JSON.encode(data),
|
||||
|
|
Loading…
Reference in a new issue