morpheus-cli 4.2.8 → 4.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/lib/morpheus/api.rb +1 -1
- data/lib/morpheus/api/activity_interface.rb +9 -0
- data/lib/morpheus/api/api_client.rb +83 -27
- data/lib/morpheus/api/apps_interface.rb +21 -0
- data/lib/morpheus/api/dashboard_interface.rb +5 -21
- data/lib/morpheus/api/instances_interface.rb +3 -10
- data/lib/morpheus/api/invoice_line_items_interface.rb +14 -0
- data/lib/morpheus/api/invoices_interface.rb +7 -12
- data/lib/morpheus/api/library_layouts_interface.rb +8 -0
- data/lib/morpheus/api/ping_interface.rb +20 -0
- data/lib/morpheus/api/projects_interface.rb +33 -0
- data/lib/morpheus/api/setup_interface.rb +19 -36
- data/lib/morpheus/api/user_settings_interface.rb +0 -6
- data/lib/morpheus/api/whoami_interface.rb +4 -8
- data/lib/morpheus/benchmarking.rb +16 -26
- data/lib/morpheus/cli.rb +10 -5
- data/lib/morpheus/cli/access_token_command.rb +5 -8
- data/lib/morpheus/cli/activity_command.rb +146 -0
- data/lib/morpheus/cli/apps.rb +312 -121
- data/lib/morpheus/cli/archives_command.rb +1 -1
- data/lib/morpheus/cli/auth_command.rb +4 -11
- data/lib/morpheus/cli/blueprints_command.rb +196 -137
- data/lib/morpheus/cli/change_password_command.rb +1 -1
- data/lib/morpheus/cli/cli_command.rb +225 -72
- data/lib/morpheus/cli/cli_registry.rb +2 -2
- data/lib/morpheus/cli/cloud_datastores_command.rb +1 -1
- data/lib/morpheus/cli/clouds.rb +5 -20
- data/lib/morpheus/cli/clusters.rb +4 -28
- data/lib/morpheus/cli/commands/standard/alias_command.rb +2 -9
- data/lib/morpheus/cli/commands/standard/benchmark_command.rb +2 -0
- data/lib/morpheus/cli/commands/standard/curl_command.rb +2 -3
- data/lib/morpheus/cli/commands/standard/history_command.rb +3 -6
- data/lib/morpheus/cli/commands/standard/man_command.rb +10 -7
- data/lib/morpheus/cli/commands/standard/ssl_verification_command.rb +10 -9
- data/lib/morpheus/cli/containers_command.rb +3 -3
- data/lib/morpheus/cli/credentials.rb +13 -16
- data/lib/morpheus/cli/error_handler.rb +18 -12
- data/lib/morpheus/cli/errors.rb +45 -0
- data/lib/morpheus/cli/execute_schedules_command.rb +1 -1
- data/lib/morpheus/cli/execution_request_command.rb +4 -4
- data/lib/morpheus/cli/groups.rb +84 -132
- data/lib/morpheus/cli/hosts.rb +6 -16
- data/lib/morpheus/cli/instances.rb +100 -183
- data/lib/morpheus/cli/invoices_command.rb +505 -71
- data/lib/morpheus/cli/library_layouts_command.rb +254 -166
- data/lib/morpheus/cli/library_option_lists_command.rb +0 -87
- data/lib/morpheus/cli/library_option_types_command.rb +0 -96
- data/lib/morpheus/cli/license.rb +3 -0
- data/lib/morpheus/cli/login.rb +17 -37
- data/lib/morpheus/cli/logout.rb +9 -5
- data/lib/morpheus/cli/mixins/accounts_helper.rb +83 -7
- data/lib/morpheus/cli/mixins/operations_helper.rb +41 -0
- data/lib/morpheus/cli/mixins/option_source_helper.rb +255 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +18 -4
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +222 -13
- data/lib/morpheus/cli/mixins/remote_helper.rb +139 -0
- data/lib/morpheus/cli/monitoring_checks_command.rb +11 -3
- data/lib/morpheus/cli/network_groups_command.rb +8 -2
- data/lib/morpheus/cli/option_types.rb +1 -1
- data/lib/morpheus/cli/ping.rb +252 -0
- data/lib/morpheus/cli/price_sets_command.rb +16 -27
- data/lib/morpheus/cli/prices_command.rb +34 -27
- data/lib/morpheus/cli/processes_command.rb +81 -7
- data/lib/morpheus/cli/projects_command.rb +607 -0
- data/lib/morpheus/cli/recent_activity_command.rb +87 -65
- data/lib/morpheus/cli/remote.rb +965 -974
- data/lib/morpheus/cli/reports_command.rb +3 -15
- data/lib/morpheus/cli/roles.rb +8 -31
- data/lib/morpheus/cli/service_plans_command.rb +25 -31
- data/lib/morpheus/cli/setup.rb +392 -0
- data/lib/morpheus/cli/shell.rb +144 -56
- data/lib/morpheus/cli/subnets_command.rb +71 -11
- data/lib/morpheus/cli/tasks.rb +3 -3
- data/lib/morpheus/cli/user_sources_command.rb +4 -4
- data/lib/morpheus/cli/users.rb +135 -109
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/whitelabel_settings_command.rb +7 -7
- data/lib/morpheus/cli/whoami.rb +90 -129
- data/lib/morpheus/cli/wiki_command.rb +2 -14
- data/lib/morpheus/ext/rest_client.rb +36 -0
- data/lib/morpheus/formatters.rb +42 -5
- data/lib/morpheus/rest_client.rb +0 -10
- data/lib/morpheus/terminal.rb +41 -1
- data/lib/morpheus/util.rb +24 -0
- metadata +16 -3
- data/lib/morpheus/cli/command_error.rb +0 -22
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'term/ansicolor'
|
2
2
|
require 'shellwords'
|
3
3
|
require 'morpheus/logging'
|
4
|
-
require 'morpheus/cli/
|
4
|
+
require 'morpheus/cli/errors'
|
5
5
|
require 'morpheus/cli/error_handler'
|
6
6
|
require 'morpheus/cli/expression_parser'
|
7
7
|
|
@@ -81,7 +81,7 @@ module Morpheus
|
|
81
81
|
instance.get(command_name).new.handle(args)
|
82
82
|
else
|
83
83
|
# todo: need to just return error instead of raise
|
84
|
-
raise
|
84
|
+
raise CommandNotFoundError.new("'#{command_name}' is not a morpheus command.")
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -251,7 +251,7 @@ class Morpheus::Cli::CloudDatastoresCommand
|
|
251
251
|
end
|
252
252
|
opts.add_hidden_option('-c') # prefer args[0] for [cloud]
|
253
253
|
opts.on('--group-access-all [on|off]', String, "Toggle Access for all groups.") do |val|
|
254
|
-
group_access_all = val.to_s == 'on' || val.to_s == 'true'
|
254
|
+
group_access_all = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
255
255
|
end
|
256
256
|
opts.on('--group-access LIST', Array, "Group Access, comma separated list of group IDs.") do |list|
|
257
257
|
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
data/lib/morpheus/cli/clouds.rb
CHANGED
@@ -257,13 +257,10 @@ class Morpheus::Cli::Clouds
|
|
257
257
|
payload = nil
|
258
258
|
if options[:payload]
|
259
259
|
payload = options[:payload]
|
260
|
-
|
261
|
-
if options[:options]
|
262
|
-
payload['zone'] ||= {}
|
263
|
-
payload['zone'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) })
|
264
|
-
end
|
260
|
+
payload.deep_merge!({'zone' => parse_passed_options(options)})
|
265
261
|
else
|
266
262
|
cloud_payload = {name: args[0], description: params[:description]}
|
263
|
+
cloud_payload.deep_merge!(parse_passed_options(options))
|
267
264
|
# use active group by default
|
268
265
|
params[:group] ||= @active_group_id
|
269
266
|
|
@@ -462,7 +459,7 @@ class Morpheus::Cli::Clouds
|
|
462
459
|
params = {}
|
463
460
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
464
461
|
opts.banner = subcommand_usage("[name] [options]")
|
465
|
-
opts.on( '-f', '--force', "Force
|
462
|
+
opts.on( '-f', '--force', "Force refresh. Useful if the cloud is disabled." ) do
|
466
463
|
query_params[:force] = 'true'
|
467
464
|
end
|
468
465
|
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
@@ -859,23 +856,11 @@ class Morpheus::Cli::Clouds
|
|
859
856
|
|
860
857
|
link = "#{@appliance_url}/login/oauth-redirect?access_token=#{@access_token}\\&redirectUri=/infrastructure/clouds/#{cloud['id']}#!wiki"
|
861
858
|
|
862
|
-
open_command = nil
|
863
|
-
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
864
|
-
open_command = "start #{link}"
|
865
|
-
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
|
866
|
-
open_command = "open #{link}"
|
867
|
-
elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
|
868
|
-
open_command = "xdg-open #{link}"
|
869
|
-
end
|
870
|
-
|
871
859
|
if options[:dry_run]
|
872
|
-
puts
|
860
|
+
puts Morpheus::Util.open_url_command(link)
|
873
861
|
return 0
|
874
862
|
end
|
875
|
-
|
876
|
-
system(open_command)
|
877
|
-
|
878
|
-
return 0
|
863
|
+
return Morpheus::Util.open_url(link)
|
879
864
|
rescue RestClient::Exception => e
|
880
865
|
print_rest_exception(e, options)
|
881
866
|
exit 1
|
@@ -355,23 +355,11 @@ class Morpheus::Cli::Clusters
|
|
355
355
|
link << "#!#{options[:link_tab]}"
|
356
356
|
end
|
357
357
|
|
358
|
-
open_command = nil
|
359
|
-
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
360
|
-
open_command = "start #{link}"
|
361
|
-
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
|
362
|
-
open_command = "open #{link}"
|
363
|
-
elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
|
364
|
-
open_command = "xdg-open #{link}"
|
365
|
-
end
|
366
|
-
|
367
358
|
if options[:dry_run]
|
368
|
-
puts
|
359
|
+
puts Morpheus::Util.open_url_command(link)
|
369
360
|
return 0
|
370
361
|
end
|
371
|
-
|
372
|
-
system(open_command)
|
373
|
-
|
374
|
-
return 0
|
362
|
+
return Morpheus::Util.open_url(link)
|
375
363
|
rescue RestClient::Exception => e
|
376
364
|
print_rest_exception(e, options)
|
377
365
|
exit 1
|
@@ -2991,23 +2979,11 @@ class Morpheus::Cli::Clusters
|
|
2991
2979
|
|
2992
2980
|
link = "#{@appliance_url}/login/oauth-redirect?access_token=#{@access_token}\\&redirectUri=/infrastructure/clusters/#{cluster['id']}#!wiki"
|
2993
2981
|
|
2994
|
-
open_command = nil
|
2995
|
-
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
2996
|
-
open_command = "start #{link}"
|
2997
|
-
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
|
2998
|
-
open_command = "open #{link}"
|
2999
|
-
elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
|
3000
|
-
open_command = "xdg-open #{link}"
|
3001
|
-
end
|
3002
|
-
|
3003
2982
|
if options[:dry_run]
|
3004
|
-
puts
|
2983
|
+
puts Morpheus::Util.open_url_command(link)
|
3005
2984
|
return 0
|
3006
2985
|
end
|
3007
|
-
|
3008
|
-
system(open_command)
|
3009
|
-
|
3010
|
-
return 0
|
2986
|
+
return Morpheus::Util.open_url(link)
|
3011
2987
|
rescue RestClient::Exception => e
|
3012
2988
|
print_rest_exception(e, options)
|
3013
2989
|
exit 1
|
@@ -63,11 +63,7 @@ EOT
|
|
63
63
|
|
64
64
|
end
|
65
65
|
optparse.parse!(args)
|
66
|
-
|
67
|
-
print_error Morpheus::Terminal.angry_prompt
|
68
|
-
puts_error "wrong number of arguments, expected 1-N and got #{args.count}\n#{optparse}"
|
69
|
-
return 1
|
70
|
-
end
|
66
|
+
verify_args!(args:args, optparse:optparse, min: 1)
|
71
67
|
|
72
68
|
# make this super forgiving.. my name = command -j -O value=woot
|
73
69
|
# the old way, as one argument "name='command'"
|
@@ -125,10 +121,7 @@ EOT
|
|
125
121
|
opts.footer = "Export an alias, saving it to your .morpheus_profile for future use"
|
126
122
|
end
|
127
123
|
optparse.parse!(args)
|
128
|
-
|
129
|
-
puts optparse
|
130
|
-
exit 1
|
131
|
-
end
|
124
|
+
verify_args!(args:args, optparse:optparse, min: 1)
|
132
125
|
alias_names = args
|
133
126
|
alias_names.each do |arg|
|
134
127
|
if !Morpheus::Cli::CliRegistry.has_alias?(arg)
|
@@ -360,6 +360,8 @@ EOT
|
|
360
360
|
else
|
361
361
|
out << "\texit: 0 "
|
362
362
|
end
|
363
|
+
total_time_str = "#{benchmark_record.duration.round((benchmark_record.duration > 0.002) ? 3 : 6)}s"
|
364
|
+
out << "\t #{total_time_str.ljust(9, ' ')}"
|
363
365
|
else
|
364
366
|
benchmark_records = []
|
365
367
|
n.times do |iteration_index|
|
@@ -58,11 +58,10 @@ EOT
|
|
58
58
|
return false
|
59
59
|
end
|
60
60
|
|
61
|
-
@api_client = establish_remote_appliance_connection(options.merge({:no_prompt => true, :skip_verify_access_token => true}))
|
61
|
+
@api_client = establish_remote_appliance_connection(options.merge({:no_prompt => true, :skip_verify_access_token => true, :skip_login => true}))
|
62
62
|
|
63
63
|
if !@appliance_name
|
64
|
-
|
65
|
-
return false
|
64
|
+
raise_command_error "#{command_name} requires a remote to be specified, use -r [remote] or set the active remote with `remote use`"
|
66
65
|
end
|
67
66
|
|
68
67
|
# curry --insecure to curl
|
@@ -40,17 +40,14 @@ EOT
|
|
40
40
|
end
|
41
41
|
raw_cmd = "#{command_name} #{args.join(' ')}"
|
42
42
|
optparse.parse!(args)
|
43
|
-
|
44
|
-
print_error Morpheus::Terminal.angry_prompt
|
45
|
-
puts_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
46
|
-
return 1
|
47
|
-
end
|
43
|
+
verify_args!(args:args, count: 0, optparse:optparse)
|
48
44
|
if options[:do_flush]
|
49
45
|
command_count = Morpheus::Cli::Shell.instance.history_commands_count
|
50
46
|
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to flush your command history (#{format_number(command_count)} #{command_count == 1 ? 'command' : 'commands'})?")
|
51
47
|
return 9, "aborted command"
|
52
48
|
end
|
53
|
-
|
49
|
+
flush_n = options[:max] ? options[:max] : nil
|
50
|
+
Morpheus::Cli::Shell.instance.flush_history(flush_n)
|
54
51
|
return 0
|
55
52
|
else
|
56
53
|
Morpheus::Cli::Shell.instance.print_history(options)
|
@@ -51,7 +51,7 @@ The -g switch be used to regenerate the file.
|
|
51
51
|
EOT
|
52
52
|
end
|
53
53
|
optparse.parse!(args)
|
54
|
-
|
54
|
+
verify_args!(args:args, optparse:optparse, count:0)
|
55
55
|
if goto_wiki
|
56
56
|
link = "https://github.com/gomorpheus/morpheus-cli/wiki/CLI-Manual"
|
57
57
|
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
@@ -153,13 +153,15 @@ EOT
|
|
153
153
|
begin
|
154
154
|
|
155
155
|
manpage.print <<-ENDTEXT
|
156
|
+
morpheus v#{Morpheus::Cli::VERSION}
|
157
|
+
|
156
158
|
## NAME
|
157
159
|
|
158
|
-
morpheus - the command line interface for interacting with the Morpheus
|
160
|
+
morpheus - the command line interface for interacting with the Morpheus appliance
|
159
161
|
|
160
162
|
## SYNOPSIS
|
161
163
|
|
162
|
-
morpheus [command] [<args>]
|
164
|
+
morpheus [command] [<args>] [options]
|
163
165
|
|
164
166
|
## DESCRIPTION
|
165
167
|
|
@@ -168,9 +170,9 @@ EOT
|
|
168
170
|
This is a command line interface for managing a Morpheus Appliance.
|
169
171
|
All communication with the remote appliance is done via the Morpheus API.
|
170
172
|
|
171
|
-
To
|
173
|
+
To get started, see the command `remote add` command.
|
172
174
|
|
173
|
-
To
|
175
|
+
To learn more, visit https://github.com/gomorpheus/morpheus-cli/wiki/Getting-Started
|
174
176
|
|
175
177
|
To learn more about the Morpheus Appliance, visit https://www.morpheusdata.com/features
|
176
178
|
|
@@ -220,7 +222,7 @@ ENDTEXT
|
|
220
222
|
exit_code, err = terminal.execute("--help")
|
221
223
|
manpage.print "```\n"
|
222
224
|
manpage.print "\n"
|
223
|
-
# output help for every
|
225
|
+
# output help for every command (that is not hidden)
|
224
226
|
Morpheus::Cli::CliRegistry.all.keys.sort.each do |cmd|
|
225
227
|
cmd_klass = Morpheus::Cli::CliRegistry.instance.get(cmd)
|
226
228
|
cmd_instance = cmd_klass.new
|
@@ -237,7 +239,8 @@ ENDTEXT
|
|
237
239
|
raise err unless err.success?
|
238
240
|
end
|
239
241
|
manpage.print "```\n"
|
240
|
-
subcommands = cmd_klass.subcommands
|
242
|
+
# subcommands = cmd_klass.subcommands
|
243
|
+
subcommands = cmd_klass.visible_subcommands
|
241
244
|
if subcommands && subcommands.size > 0
|
242
245
|
subcommands.sort.each do |subcommand, subcommand_method|
|
243
246
|
Morpheus::Logging::DarkPrinter.puts "appending command help `morpheus #{cmd} #{subcommand} --help`" if Morpheus::Logging.debug? && !options[:quiet]
|
@@ -8,12 +8,14 @@ class Morpheus::Cli::SslVerificationCommand
|
|
8
8
|
include Morpheus::Cli::CliCommand
|
9
9
|
set_command_name :'ssl-verification'
|
10
10
|
set_command_hidden
|
11
|
-
|
11
|
+
|
12
|
+
def usage
|
12
13
|
<<-EOT
|
13
14
|
Usage: morpheus #{command_name} [on|off]
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
Set SSL Verification on or off.
|
17
|
+
Enable [on] or disable [off] SSL Verification.
|
18
|
+
If no arguments are passed, the current value is printed.
|
17
19
|
EOT
|
18
20
|
end
|
19
21
|
|
@@ -28,14 +30,13 @@ EOT
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
optparse.parse!(args)
|
33
|
+
verify_args!(args:args, optparse:optparse, max:1)
|
31
34
|
if args.count == 0
|
32
35
|
puts Morpheus::RestClient.ssl_verification_enabled? ? "on" : "off"
|
33
|
-
return
|
34
|
-
end
|
35
|
-
if args.count > 1
|
36
|
-
puts optparse
|
37
|
-
return false
|
36
|
+
return Morpheus::RestClient.ssl_verification_enabled? ? 0 : 1
|
38
37
|
end
|
38
|
+
|
39
|
+
|
39
40
|
if ["on", "enabled", "true", "1"].include?(args[0].to_s.strip.downcase)
|
40
41
|
Morpheus::RestClient.enable_ssl_verification = true
|
41
42
|
elsif ["off", "disabled", "false", "0"].include?(args[0].to_s.strip.downcase)
|
@@ -362,7 +362,7 @@ class Morpheus::Cli::ContainersCommand
|
|
362
362
|
options = {}
|
363
363
|
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
364
364
|
opts.banner = subcommand_usage("[id list]")
|
365
|
-
opts.footer = "
|
365
|
+
opts.footer = "List the actions available to specified container(s)."
|
366
366
|
build_common_options(opts, options, [:json, :dry_run, :remote])
|
367
367
|
end
|
368
368
|
optparse.parse!(args)
|
@@ -657,9 +657,9 @@ class Morpheus::Cli::ContainersCommand
|
|
657
657
|
execution_request = json_response['executionRequest']
|
658
658
|
print_green_success "Executing request #{execution_request['uniqueId']}"
|
659
659
|
if do_refresh
|
660
|
-
Morpheus::Cli::ExecutionRequestCommand.new.handle(["get", execution_request['uniqueId'], "--refresh"])
|
660
|
+
Morpheus::Cli::ExecutionRequestCommand.new.handle(["get", execution_request['uniqueId'], "--refresh"]+ (options[:remote] ? ["-r",options[:remote]] : []))
|
661
661
|
else
|
662
|
-
Morpheus::Cli::ExecutionRequestCommand.new.handle(["get", execution_request['uniqueId']])
|
662
|
+
Morpheus::Cli::ExecutionRequestCommand.new.handle(["get", execution_request['uniqueId']]+ (options[:remote] ? ["-r",options[:remote]] : []))
|
663
663
|
end
|
664
664
|
return 0
|
665
665
|
rescue RestClient::Exception => e
|
@@ -40,7 +40,15 @@ module Morpheus
|
|
40
40
|
password = nil
|
41
41
|
wallet = nil
|
42
42
|
|
43
|
-
|
43
|
+
# should not need this logic in here
|
44
|
+
if options[:remote_url]
|
45
|
+
# @appliance_name = options[:remote_url]
|
46
|
+
# name should change too though or printing may be misleading.
|
47
|
+
# @appliance_name = "remote-url"
|
48
|
+
# @appliance_url = options[:remote_url]
|
49
|
+
# do not save when using --remote-url
|
50
|
+
do_save = false
|
51
|
+
end
|
44
52
|
|
45
53
|
if options[:remote_token]
|
46
54
|
# user passed in a token to login with.
|
@@ -48,7 +56,8 @@ module Morpheus
|
|
48
56
|
# OR whoami should return other wallet info like access token or maybe just the expiration date
|
49
57
|
# for now, it just stores the access token without other wallet info
|
50
58
|
begin
|
51
|
-
|
59
|
+
# @setup_interface = Morpheus::SetupInterface.new({url:@appliance_url,access_token:@access_token})
|
60
|
+
whoami_interface = Morpheus::WhoamiInterface.new({url: @appliance_url, token: options[:remote_token]})
|
52
61
|
whoami_interface.setopts(options)
|
53
62
|
if options[:dry_run]
|
54
63
|
print_dry_run whoami_interface.dry.get()
|
@@ -84,24 +93,15 @@ module Morpheus
|
|
84
93
|
wallet = nil
|
85
94
|
end
|
86
95
|
else
|
87
|
-
|
88
96
|
# ok prompt for creds..
|
89
97
|
username = options['username'] || options[:username] || nil
|
90
98
|
password = options['password'] || options[:password] || nil
|
91
99
|
|
100
|
+
# what are these for? just use :username and :password
|
92
101
|
if options[:remote_username]
|
93
102
|
username = options[:remote_username]
|
94
103
|
password = options[:remote_password]
|
95
|
-
if do_save == true
|
96
|
-
do_save = (options[:remote_url] ? false : true)
|
97
|
-
end
|
98
|
-
else
|
99
|
-
# maybe just if check if options[:test_only] != true
|
100
|
-
# if do_save == true
|
101
|
-
# wallet = load_saved_credentials
|
102
|
-
# end
|
103
104
|
end
|
104
|
-
|
105
105
|
if wallet.nil?
|
106
106
|
unless options[:quiet] || options[:no_prompt]
|
107
107
|
# if username.empty? || password.empty?
|
@@ -126,7 +126,7 @@ module Morpheus
|
|
126
126
|
end
|
127
127
|
if password.empty?
|
128
128
|
print "Password: #{required_blue_prompt} "
|
129
|
-
#
|
129
|
+
# this should be my_terminal.stdin instead of STDIN and $stdin
|
130
130
|
password = STDIN.noecho(&:gets).chomp!
|
131
131
|
print "\n"
|
132
132
|
else
|
@@ -185,14 +185,11 @@ module Morpheus
|
|
185
185
|
end
|
186
186
|
|
187
187
|
if do_save && @appliance_name
|
188
|
-
|
189
|
-
|
190
188
|
begin
|
191
189
|
# save pertinent session info to the appliance
|
192
190
|
save_credentials(@appliance_name, wallet)
|
193
191
|
now = Time.now.to_i
|
194
192
|
appliance = ::Morpheus::Cli::Remote.load_remote(@appliance_name)
|
195
|
-
|
196
193
|
if wallet && wallet['access_token']
|
197
194
|
save_credentials(@appliance_name, wallet)
|
198
195
|
else
|
@@ -4,7 +4,7 @@ require 'json'
|
|
4
4
|
require 'rest_client'
|
5
5
|
require 'net/https'
|
6
6
|
require 'morpheus/logging'
|
7
|
-
require 'morpheus/cli/
|
7
|
+
require 'morpheus/cli/errors'
|
8
8
|
require 'morpheus/cli/expression_parser'
|
9
9
|
|
10
10
|
class Morpheus::Cli::ErrorHandler
|
@@ -31,34 +31,38 @@ class Morpheus::Cli::ErrorHandler
|
|
31
31
|
# raise err
|
32
32
|
# @stderr.puts "#{red}#{err.message}#{reset}"
|
33
33
|
puts_angry_error err.message
|
34
|
-
@stderr.puts "
|
34
|
+
@stderr.puts "Use -h to get help with this command."
|
35
35
|
do_print_stacktrace = false
|
36
36
|
# exit_code = 127
|
37
|
+
# when Morpheus::Cli::CommandArgumentsError
|
37
38
|
when Morpheus::Cli::CommandError
|
38
39
|
# @stderr.puts "#{red}#{err.message}#{reset}"
|
39
|
-
|
40
|
+
# this should probably print the whole thing as red, but just does the first line for now.
|
41
|
+
message_lines = err.message.split(/\r?\n/)
|
42
|
+
first_line = message_lines.shift
|
43
|
+
puts_angry_error first_line
|
44
|
+
@stderr.puts message_lines.join("\n") unless message_lines.empty?
|
45
|
+
@stderr.puts "Use -h to get help with this command."
|
40
46
|
do_print_stacktrace = false
|
41
47
|
if err.exit_code
|
42
48
|
exit_code = err.exit_code
|
43
49
|
end
|
44
|
-
# @stderr.puts "Try -h for help with this command."
|
45
50
|
when Morpheus::Cli::ExpressionParser::InvalidExpression
|
46
51
|
# @stderr.puts "#{red}#{err.message}#{reset}"
|
47
52
|
puts_angry_error err.message
|
48
53
|
do_print_stacktrace = false
|
49
54
|
exit_code = 99
|
50
55
|
when SocketError
|
51
|
-
@stderr.puts "#{red}Error Communicating with the
|
56
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance.#{reset}"
|
52
57
|
@stderr.puts "#{red}#{err.message}#{reset}"
|
53
58
|
when RestClient::Exceptions::Timeout
|
54
|
-
@stderr.puts "#{red}Error Communicating with the
|
59
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance.#{reset}"
|
55
60
|
@stderr.puts "#{red}#{err.message}#{reset}"
|
56
61
|
when Errno::ECONNREFUSED
|
57
|
-
@stderr.puts "#{red}Error Communicating with the
|
62
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance.#{reset}"
|
58
63
|
@stderr.puts "#{red}#{err.message}#{reset}"
|
59
|
-
# @stderr.puts "Try -h for help with this command."
|
60
64
|
when OpenSSL::SSL::SSLError
|
61
|
-
@stderr.puts "#{red}Error Communicating with the
|
65
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance.#{reset}"
|
62
66
|
@stderr.puts "#{red}#{err.message}#{reset}"
|
63
67
|
when RestClient::Exception
|
64
68
|
print_rest_exception(err, options)
|
@@ -125,7 +129,7 @@ class Morpheus::Cli::ErrorHandler
|
|
125
129
|
rescue TypeError, JSON::ParserError => ex
|
126
130
|
end
|
127
131
|
else
|
128
|
-
@stderr.print red, "Error Communicating with the
|
132
|
+
@stderr.print red, "Error Communicating with the remote appliance. #{e}", reset, "\n"
|
129
133
|
if options[:json] || options[:debug]
|
130
134
|
begin
|
131
135
|
response = JSON.parse(e.response.to_s)
|
@@ -145,7 +149,7 @@ class Morpheus::Cli::ErrorHandler
|
|
145
149
|
end
|
146
150
|
end
|
147
151
|
else
|
148
|
-
@stderr.print red, "Error Communicating with the
|
152
|
+
@stderr.print red, "Error Communicating with the remote appliance. #{e}", reset, "\n"
|
149
153
|
end
|
150
154
|
# uh, having this print method return exit_code, err to standardize return values of methods that are still calling it, at the end just by chance..
|
151
155
|
# return exit_code, err
|
@@ -204,7 +208,7 @@ class Morpheus::Cli::ErrorHandler
|
|
204
208
|
end
|
205
209
|
|
206
210
|
def print_rest_exception_request_and_response(e)
|
207
|
-
@stderr.puts "#{red}Error Communicating with the
|
211
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance. (HTTP #{e.response.code})#{reset}"
|
208
212
|
response = e.response
|
209
213
|
request = response.instance_variable_get("@request")
|
210
214
|
@stderr.print red
|
@@ -220,7 +224,9 @@ protected
|
|
220
224
|
def puts_angry_error(*msgs)
|
221
225
|
# @stderr.print "#{Term::ANSIColor.red}morpheus: #{Term::ANSIColor.reset}#{msg}\n"
|
222
226
|
@stderr.print(Morpheus::Terminal.angry_prompt)
|
227
|
+
@stderr.print(Term::ANSIColor.red)
|
223
228
|
@stderr.puts(*msgs)
|
229
|
+
@stderr.print(reset)
|
224
230
|
end
|
225
231
|
|
226
232
|
# def puts(*args)
|