Class: Dcmgr::Cli::KeyPair
Constant Summary collapse
Instance Method Summary collapse
Instance Method Details
#add ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dcmgr/cli/keypair.rb', line 14 def add UnknownUUIDError.raise([:account_id]) if M::Account[[:account_id]].nil? private_key_path = File.([:private_key]) public_key_path = File.([:public_key]) Error.raise "Private key file doesn't exist",100 unless File.exists?(private_key_path) Error.raise "Public key file doesn't exist",100 unless File.exists?(public_key_path) fields = .dup #Get the keys from their respective files. fields[:public_key] = File.open(public_key_path) {|f| f.readline} fields[:private_key] = File.open(private_key_path) {|f| f.readlines.map.join} #Generate the fingerprint from the public key file fields[:finger_print] = %x{ssh-keygen -lf #{[:public_key]} | cut -d ' ' -f2}.chomp puts super(M::SshKeyPair,fields) end |
#del(uuid) ⇒ Object
42 43 44 |
# File 'lib/dcmgr/cli/keypair.rb', line 42 def del(uuid) super(M::SshKeyPair,uuid) end |
#modify(uuid) ⇒ Object
36 37 38 39 |
# File 'lib/dcmgr/cli/keypair.rb', line 36 def modify(uuid) UnknownUUIDError.raise([:account_id]) if [:account_id] && M::Account[[:account_id]].nil? super(M::SshKeyPair,uuid,) end |
#show(uuid = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dcmgr/cli/keypair.rb', line 47 def show(uuid=nil) if uuid keypair = M::SshKeyPair[uuid] || UnknownUUIDError.raise(uuid) puts ERB.new(<<__END, nil, '-').result(binding) Keypair UUID: <%= keypair.canonical_uuid %> Account id: <%= keypair.account_id %> Name: <%= keypair.name%> Finger print: <%= keypair.finger_print %> Public Key: <%= keypair.public_key%> __END else puts ERB.new(<<__END, nil, '-').result(binding) <%- M::SshKeyPair.each { |row| -%> <%= row.canonical_uuid %>\t<%= row.account_id %>\t<%= row.name %>\t<%= row.finger_print %> <%- } -%> __END end end |