class SshKeyPair
Public Instance Methods
Source
# File lib/cloudstack-cli/commands/ssh_key_pair.rb 34 def create(name) 35 resolve_account 36 resolve_project 37 options[:name] = name 38 pair = client.create_ssh_key_pair(options) 39 say "Name : #{pair['name']}" 40 say "Fingerprint : #{pair['fingerprint']}" 41 say "Privatekey:" 42 say pair['privatekey'] 43 end
Source
# File lib/cloudstack-cli/commands/ssh_key_pair.rb 74 def delete(name) 75 resolve_account 76 resolve_project 77 options[:name] = name 78 if options[:force] || yes?("Delete ssh key pair #{name}?", :yellow) 79 if client.delete_ssh_key_pair(options)['success'] == "true" 80 say("OK", :green) 81 else 82 say("Failed", :red) 83 exit 1 84 end 85 end 86 end
Source
# File lib/cloudstack-cli/commands/ssh_key_pair.rb 9 def list 10 resolve_account 11 resolve_project 12 pairs = client.list_ssh_key_pairs(options) 13 if pairs.size < 1 14 say "No ssh key pairs found." 15 else 16 case options[:format].to_sym 17 when :yaml 18 puts({ssh_key_pairs: pairs}.to_yaml) 19 when :json 20 puts JSON.pretty_generate(ssh_key_pairs: pairs) 21 else 22 table = [["Name", "Fingerprint"]] 23 pairs.each do |pair| 24 table << [pair['name'], pair['fingerprint']] 25 end 26 print_table table 27 end 28 end 29 end
Source
# File lib/cloudstack-cli/commands/ssh_key_pair.rb 49 def register(name) 50 resolve_account 51 resolve_project 52 options[:name] = name 53 if File.exist?(options[:public_key]) 54 public_key = IO.read(options[:public_key]) 55 options[:public_key] = public_key 56 else 57 say("Can't open public key #{options[:public_key]}", :red) 58 exit 1 59 end 60 pair = client.register_ssh_key_pair(options) 61 say "Name : #{pair['name']}" 62 say "Fingerprint : #{pair['fingerprint']}" 63 say "Privatekey : #{pair['privatekey']}" 64 puts 65 rescue => e 66 say "Failed to register key: #{e.message}", :red 67 exit 1 68 end
Source
# File lib/cloudstack-cli/commands/ssh_key_pair.rb 93 def reset_vm_keys 94 resolve_account 95 resolve_project 96 97 unless virtual_machine = client.list_virtual_machines({name: options[:virtual_machine], list_all: true}.merge options).first 98 puts "No virtual machine found." 99 else 100 unless virtual_machine['state'].downcase == "stopped" 101 say "ERROR: Virtual machine must be in stopped state.", :red 102 exit 1 103 end 104 unless options[:force] || yes?("Reset ssh key for VM #{options[:virtual_machine]}? (y/N)", :yellow) 105 exit 106 end 107 client.reset_ssh_key_for_virtual_machine(options.merge(id: virtual_machine['id'])) 108 say "OK", :green 109 end 110 end