Class: SshKeyPair
Constant Summary
CloudstackCli::Helper::ASYNC_STATES
Instance Attribute Summary
#config
Instance Method Summary
collapse
exit_on_failure?, start
#resolve_account, #resolve_cluster, #resolve_compute_offering, #resolve_disk_offering, #resolve_domain, #resolve_host, #resolve_ip_network_list, #resolve_iso, #resolve_iso_for_vm_deployment, #resolve_networks, #resolve_project, #resolve_snapshot, #resolve_template, #resolve_virtual_machine, #resolve_zone, #vm_options_to_params
#ask_number, #bootstrap_server, #bootstrap_server_interactive, #create_port_rules, #create_server, #get_server_default_nic, #pf_rule_to_object, #print_job_status, #print_options, #run_background_jobs, #update_job_status, #update_jobs, #watch_jobs
Methods inherited from Thor
banner, basename2, old_subcommand, subcommand
Instance Method Details
#create(name) ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/cloudstack-cli/commands/ssh_key_pair.rb', line 34
def create(name)
resolve_account
resolve_project
options[:name] = name
pair = client.create_ssh_key_pair(options)
say "Name : #{pair['name']}"
say "Fingerprint : #{pair['fingerprint']}"
say "Privatekey:"
say pair['privatekey']
end
|
#delete(name) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/cloudstack-cli/commands/ssh_key_pair.rb', line 74
def delete(name)
resolve_account
resolve_project
options[:name] = name
if options[:force] || yes?("Delete ssh key pair #{name}?", :yellow)
if client.delete_ssh_key_pair(options)['success'] == "true"
say("OK", :green)
else
say("Failed", :red)
exit 1
end
end
end
|
#list ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/cloudstack-cli/commands/ssh_key_pair.rb', line 9
def list
resolve_account
resolve_project
pairs = client.list_ssh_key_pairs(options)
if pairs.size < 1
say "No ssh key pairs found."
else
case options[:format].to_sym
when :yaml
puts({ssh_key_pairs: pairs}.to_yaml)
when :json
puts JSON.pretty_generate(ssh_key_pairs: pairs)
else
table = [["Name", "Fingerprint"]]
pairs.each do |pair|
table << [pair['name'], pair['fingerprint']]
end
print_table table
end
end
end
|
#register(name) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/cloudstack-cli/commands/ssh_key_pair.rb', line 49
def register(name)
resolve_account
resolve_project
options[:name] = name
if File.exist?(options[:public_key])
public_key = IO.read(options[:public_key])
options[:public_key] = public_key
else
say("Can't open public key #{options[:public_key]}", :red)
exit 1
end
pair = client.register_ssh_key_pair(options)
say "Name : #{pair['name']}"
say "Fingerprint : #{pair['fingerprint']}"
say "Privatekey : #{pair['privatekey']}"
puts
rescue => e
say "Failed to register key: #{e.message}", :red
exit 1
end
|
#reset_vm_keys ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/cloudstack-cli/commands/ssh_key_pair.rb', line 93
def reset_vm_keys
resolve_account
resolve_project
unless virtual_machine = client.list_virtual_machines({name: options[:virtual_machine], list_all: true}.merge options).first
puts "No virtual machine found."
else
unless virtual_machine['state'].downcase == "stopped"
say "ERROR: Virtual machine must be in stopped state.", :red
exit 1
end
unless options[:force] || yes?("Reset ssh key for VM #{options[:virtual_machine]}? (y/N)", :yellow)
exit
end
client.reset_ssh_key_for_virtual_machine(options.merge(id: virtual_machine['id']))
say "OK", :green
end
end
|