1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #1383: Check errors in keypair creation. Move requires to keypair module

This commit is contained in:
Ruben S. Montero 2012-09-26 11:44:46 +02:00
parent 27a746f97c
commit 307ee69c38
2 changed files with 15 additions and 7 deletions

View File

@ -18,10 +18,7 @@ require 'rubygems'
require 'erb'
require 'time'
require 'base64'
require 'json'
require 'openssl'
require 'digest/md5'
require 'net/ssh'
require 'AWS'

View File

@ -14,6 +14,11 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
require 'json'
require 'openssl'
require 'digest/md5'
require 'net/ssh'
module Keypair
############################################################################
# Extends the OpenNebula::User class to include Keypair management
@ -73,13 +78,19 @@ module Keypair
user = User.new_with_id(OpenNebula::User::SELF, @client)
user.info
kp = user.get_keypair
rsa_kp = OpenSSL::PKey::RSA.generate(2048)
begin
kp = user.get_keypair
rsa_kp = OpenSSL::PKey::RSA.generate(2048)
rescue Exception => e
return OpenNebula::Error.new("Error in create_keypair: #{e.message}")
end
erb_private_key = rsa_kp
erb_public_key = rsa_kp.public_key
erb_key_fingerprint = Digest::MD5.hexdigest(rsa_kp.to_der).gsub(/(.{2})(?=.)/, '\1:\2')
erb_key_fingerprint = Digest::MD5.hexdigest(rsa_kp.to_der)
erb_key_fingerprint.gsub!(/(.{2})(?=.)/, '\1:\2')
erb_ssh_public_key = erb_public_key.ssh_type <<
" " <<
[ erb_public_key.to_blob ].pack('m0') <<