Class: Dcmgr::Models::SshKeyPair

Inherits:
AccountResource show all
Defined in:
lib/dcmgr/models/ssh_key_pair.rb

Overview

SSH Key database for account.

Constant Summary

Constants inherited from BaseNew

BaseNew::LOCK_TABLES_KEY

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AccountResource

#account

Methods inherited from BaseNew

Proxy, dataset, install_data, install_data_hooks, lock!, unlock!

Class Method Details

.generate_key_pairHash

Returns string’, :public_key=>‘pubkey string’.

Returns:

  • (Hash)

    string’, :public_key=>‘pubkey string’



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dcmgr/models/ssh_key_pair.rb', line 30

def self.generate_key_pair()
  pkey = File.expand_path(randstr, Dir.tmpdir)
  pubkey = pkey + '.pub'
  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
    
    {:private_key=>IO.read(pkey),
      :public_key=>IO.read(pubkey)}
  rescue
    # clean up tmp key files
    [pkey, pubkey].each { |i|
      File.unlink(i) if File.exist?(i)
    }
  end
end

Instance Method Details

#before_destroyObject



22
23
24
25
# File 'lib/dcmgr/models/ssh_key_pair.rb', line 22

def before_destroy
  # TODO: check running instances which are associated to ssh key
  # pairs. reject deletion if exist.
end

#validateObject



19
20
# File 'lib/dcmgr/models/ssh_key_pair.rb', line 19

def validate
end