lib/fog/rackspace/models/compute_v2/server.rb in fog-maestrodev-1.19.0.20140212012611 vs lib/fog/rackspace/models/compute_v2/server.rb in fog-maestrodev-1.20.0.20140305101305
- old
+ new
@@ -135,16 +135,22 @@
# @!attribute [r] image_id
# @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={})
@service = attributes[:service]
super
end
@@ -168,10 +174,31 @@
# @param [Hash] hash contains key value pairs
def metadata=(hash={})
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
def save(options = {})
if persisted?
@@ -199,15 +226,20 @@
# * BUILD -> ERROR (on error)
def create(options)
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 } }
end
data = service.create_server(name, image_id, flavor_id, 1, 1, modified_options)
@@ -519,18 +551,23 @@
end
# Setup server for SSH access
# @see Servers#bootstrap
def setup(credentials = {})
- requires :public_ip_address, :identity, :public_key, :username
+ requires :ssh_ip_address, :identity, :public_key, :username
+
commands = [
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
password_lock,
%{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
%{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
- ].compact
- Fog::SSH.new(public_ip_address, username, credentials).run(commands)
+ ]
+ commands.compact
+
+ @password = nil if password_lock
+
+ Fog::SSH.new(ssh_ip_address, username, credentials).run(commands)
rescue Errno::ECONNREFUSED
sleep(1)
retry
end