lib/dcmgr/models/ssh_key_pair.rb in wakame-vdc-agents-10.12.0 vs lib/dcmgr/models/ssh_key_pair.rb in wakame-vdc-agents-11.06.0

- old
+ new

@@ -7,10 +7,11 @@ class SshKeyPair < AccountResource taggable 'ssh' inheritable_schema do String :name, :size=>100, :null=>false + String :finger_print, :size=>100, :null=>false Text :public_key, :null=>false Text :private_key, :null=>true index [:account_id, :name], {:unique=>true} end @@ -33,18 +34,30 @@ begin system("ssh-keygen -q -t rsa -C '' -N '' -f %s >/dev/null" % [pkey]) unless $?.exitstatus == 0 raise "Failed to run ssh-keygen: exitcode=#{$?.exitstatus}" end + + # get finger print of pkey file + fp = `ssh-keygen -l -f #{pkey}` + unless $?.exitstatus == 0 + raise "Failed to collect finger print value" + end + fp = fp.split(/\s+/)[1] {:private_key=>IO.read(pkey), - :public_key=>IO.read(pubkey)} + :public_key=>IO.read(pubkey), + :finger_print => fp} rescue # clean up tmp key files [pkey, pubkey].each { |i| File.unlink(i) if File.exist?(i) } end + end + + def to_api_document + to_hash end private def self.randstr Array.new(10) { (('a'..'z').to_a + (0..9).to_a)[rand(36)] }.join