40
41
42
43
44
45
46
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/chef/knife/cosmic_keypair_create.rb', line 40
def run
validate_base_options
Chef::Log.debug("Validate keypair name")
keypairname = locate_config_value(:name) || @name_args.first
unless /^[a-zA-Z0-9][a-zA-Z0-9\-\_]*$/.match(keypairname) then
ui.error "Invalid keypairname. Please specify a short name for the keypair"
exit 1
end
ui.info("#{ui.color("Creating SSH Keypair: #{keypairname}", :magenta)}") unless locate_config_value(:noheader)
params = {
'command' => 'createSSHKeyPair',
'name' => keypairname,
}
json = connection.send_request(params)
unless json then
ui.error("Unable to create SSH Keypair")
exit 1
end
fingerprint = json['keypair']['fingerprint']
privatekey = json['keypair']['privatekey']
ui.info("Fingerprint: #{fingerprint}") unless locate_config_value(:noheader)
ui.info(privatekey)
puts "\n" unless locate_config_value(:noheader)
end
|