morpheus-cli 4.2.16 → 4.2.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/README.md +8 -6
  4. data/lib/morpheus/api/api_client.rb +32 -14
  5. data/lib/morpheus/api/auth_interface.rb +4 -2
  6. data/lib/morpheus/api/backup_jobs_interface.rb +9 -0
  7. data/lib/morpheus/api/backups_interface.rb +16 -0
  8. data/lib/morpheus/api/deploy_interface.rb +25 -56
  9. data/lib/morpheus/api/deployments_interface.rb +44 -55
  10. data/lib/morpheus/api/doc_interface.rb +57 -0
  11. data/lib/morpheus/api/instances_interface.rb +5 -0
  12. data/lib/morpheus/api/rest_interface.rb +40 -0
  13. data/lib/morpheus/api/user_sources_interface.rb +0 -15
  14. data/lib/morpheus/api/users_interface.rb +2 -3
  15. data/lib/morpheus/benchmarking.rb +2 -2
  16. data/lib/morpheus/cli.rb +4 -1
  17. data/lib/morpheus/cli/access_token_command.rb +27 -10
  18. data/lib/morpheus/cli/apps.rb +21 -15
  19. data/lib/morpheus/cli/backup_jobs_command.rb +276 -0
  20. data/lib/morpheus/cli/backups_command.rb +271 -0
  21. data/lib/morpheus/cli/blueprints_command.rb +27 -61
  22. data/lib/morpheus/cli/boot_scripts_command.rb +1 -1
  23. data/lib/morpheus/cli/budgets_command.rb +4 -4
  24. data/lib/morpheus/cli/cli_command.rb +99 -41
  25. data/lib/morpheus/cli/cloud_resource_pools_command.rb +16 -0
  26. data/lib/morpheus/cli/clouds.rb +7 -10
  27. data/lib/morpheus/cli/clusters.rb +0 -18
  28. data/lib/morpheus/cli/commands/standard/benchmark_command.rb +7 -7
  29. data/lib/morpheus/cli/commands/standard/man_command.rb +1 -1
  30. data/lib/morpheus/cli/credentials.rb +13 -9
  31. data/lib/morpheus/cli/deploy.rb +374 -0
  32. data/lib/morpheus/cli/deployments.rb +521 -197
  33. data/lib/morpheus/cli/deploys.rb +271 -126
  34. data/lib/morpheus/cli/doc.rb +182 -0
  35. data/lib/morpheus/cli/error_handler.rb +23 -8
  36. data/lib/morpheus/cli/errors.rb +3 -2
  37. data/lib/morpheus/cli/image_builder_command.rb +2 -2
  38. data/lib/morpheus/cli/instances.rb +136 -17
  39. data/lib/morpheus/cli/invoices_command.rb +59 -47
  40. data/lib/morpheus/cli/jobs_command.rb +2 -2
  41. data/lib/morpheus/cli/library_instance_types_command.rb +17 -3
  42. data/lib/morpheus/cli/library_layouts_command.rb +1 -1
  43. data/lib/morpheus/cli/login.rb +9 -3
  44. data/lib/morpheus/cli/mixins/accounts_helper.rb +158 -100
  45. data/lib/morpheus/cli/mixins/backups_helper.rb +115 -0
  46. data/lib/morpheus/cli/mixins/deployments_helper.rb +135 -0
  47. data/lib/morpheus/cli/mixins/option_source_helper.rb +1 -1
  48. data/lib/morpheus/cli/mixins/print_helper.rb +110 -74
  49. data/lib/morpheus/cli/mixins/provisioning_helper.rb +2 -2
  50. data/lib/morpheus/cli/mixins/whoami_helper.rb +19 -6
  51. data/lib/morpheus/cli/network_routers_command.rb +1 -1
  52. data/lib/morpheus/cli/option_parser.rb +48 -5
  53. data/lib/morpheus/cli/option_types.rb +1 -1
  54. data/lib/morpheus/cli/projects_command.rb +7 -7
  55. data/lib/morpheus/cli/provisioning_licenses_command.rb +2 -2
  56. data/lib/morpheus/cli/remote.rb +3 -2
  57. data/lib/morpheus/cli/roles.rb +49 -92
  58. data/lib/morpheus/cli/security_groups.rb +7 -1
  59. data/lib/morpheus/cli/service_plans_command.rb +10 -10
  60. data/lib/morpheus/cli/setup.rb +1 -1
  61. data/lib/morpheus/cli/shell.rb +7 -6
  62. data/lib/morpheus/cli/subnets_command.rb +1 -1
  63. data/lib/morpheus/cli/tasks.rb +24 -10
  64. data/lib/morpheus/cli/tenants_command.rb +133 -163
  65. data/lib/morpheus/cli/user_groups_command.rb +20 -65
  66. data/lib/morpheus/cli/user_settings_command.rb +115 -13
  67. data/lib/morpheus/cli/user_sources_command.rb +57 -24
  68. data/lib/morpheus/cli/users.rb +210 -186
  69. data/lib/morpheus/cli/version.rb +1 -1
  70. data/lib/morpheus/cli/whitelabel_settings_command.rb +29 -5
  71. data/lib/morpheus/cli/whoami.rb +113 -6
  72. data/lib/morpheus/cli/workflows.rb +11 -8
  73. data/lib/morpheus/ext/hash.rb +21 -0
  74. data/lib/morpheus/terminal.rb +1 -0
  75. metadata +12 -3
  76. data/lib/morpheus/cli/auth_command.rb +0 -105
@@ -279,7 +279,7 @@ class Morpheus::Cli::BootScriptsCommand
279
279
  options = {}
280
280
  optparse = Morpheus::Cli::OptionParser.new do |opts|
281
281
  opts.banner = subcommand_usage("[boot-script]")
282
- build_common_options(opts, options, [:account, :auto_confirm, :json, :dry_run, :remote])
282
+ build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
283
283
  end
284
284
  optparse.parse!(args)
285
285
 
@@ -570,16 +570,16 @@ class Morpheus::Cli::BudgetsCommand
570
570
  {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 1},
571
571
  # {'fieldName' => 'enabled', 'fieldLabel' => 'Enabled', 'type' => 'checkbox', 'defaultValue' => true},
572
572
  {'fieldName' => 'scope', 'fieldLabel' => 'Scope', 'code' => 'budget.scope', 'type' => 'select', 'selectOptions' => [{'name'=>'Account','value'=>'account'},{'name'=>'Tenant','value'=>'tenant'},{'name'=>'Cloud','value'=>'cloud'},{'name'=>'Group','value'=>'group'},{'name'=>'User','value'=>'user'}], 'defaultValue' => 'account', 'required' => true, 'displayOrder' => 3},
573
- {'fieldName' => 'tenant', 'fieldLabel' => 'Tenant', 'type' => 'select', 'optionSource' => lambda {
573
+ {'fieldName' => 'tenant', 'fieldLabel' => 'Tenant', 'type' => 'select', 'optionSource' => lambda {|api_client, api_params|
574
574
  @options_interface.options_for_source("tenants", {})['data']
575
575
  }, 'required' => true, 'dependsOnCode' => 'budget.scope:tenant', 'displayOrder' => 4},
576
- {'fieldName' => 'user', 'fieldLabel' => 'User', 'type' => 'select', 'optionSource' => lambda {
576
+ {'fieldName' => 'user', 'fieldLabel' => 'User', 'type' => 'select', 'optionSource' => lambda {|api_client, api_params|
577
577
  @options_interface.options_for_source("users", {})['data']
578
578
  }, 'required' => true, 'dependsOnCode' => 'budget.scope:user', 'displayOrder' => 5},
579
- {'fieldName' => 'group', 'fieldLabel' => 'Group', 'type' => 'select', 'optionSource' => lambda {
579
+ {'fieldName' => 'group', 'fieldLabel' => 'Group', 'type' => 'select', 'optionSource' => lambda {|api_client, api_params|
580
580
  @options_interface.options_for_source("groups", {})['data']
581
581
  }, 'required' => true, 'dependsOnCode' => 'budget.scope:group', 'displayOrder' => 6},
582
- {'fieldName' => 'cloud', 'fieldLabel' => 'Cloud', 'type' => 'select', 'optionSource' => lambda {
582
+ {'fieldName' => 'cloud', 'fieldLabel' => 'Cloud', 'type' => 'select', 'optionSource' => lambda {|api_client, api_params|
583
583
  @options_interface.options_for_source("clouds", {})['data']
584
584
  }, 'required' => true, 'dependsOnCode' => 'budget.scope:cloud', 'displayOrder' => 7},
585
585
  {'fieldName' => 'year', 'fieldLabel' => 'Period', 'type' => 'text', 'required' => true, 'defaultValue' => Time.now.year, 'description' => "The period (year) the budget applies to. Default is the current year.", 'displayOrder' => 8},
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'json'
3
+ require 'fileutils'
3
4
  require 'morpheus/logging'
4
5
  require 'morpheus/benchmarking'
5
6
  require 'morpheus/cli/option_parser'
@@ -232,11 +233,11 @@ module Morpheus
232
233
  ## the standard options for a command that makes api requests (most of them)
233
234
 
234
235
  def build_standard_get_options(opts, options, includes=[], excludes=[])
235
- build_common_options(opts, options, [:query, :json, :yaml, :csv, :fields, :quiet, :dry_run, :remote] + includes, excludes)
236
+ build_common_options(opts, options, includes + [:query, :json, :yaml, :csv, :fields, :quiet, :dry_run, :remote], excludes)
236
237
  end
237
238
 
238
239
  def build_standard_post_options(opts, options, includes=[], excludes=[])
239
- build_common_options(opts, options, [:options, :payload, :json, :quiet, :dry_run, :remote] + includes, excludes)
240
+ build_common_options(opts, options, includes + [:options, :payload, :json, :quiet, :dry_run, :remote], excludes)
240
241
  end
241
242
 
242
243
  def build_standard_put_options(opts, options, includes=[], excludes=[])
@@ -244,7 +245,7 @@ module Morpheus
244
245
  end
245
246
 
246
247
  def build_standard_delete_options(opts, options, includes=[], excludes=[])
247
- build_common_options(opts, options, [:auto_confirm, :query, :json, :quiet, :dry_run, :remote] + includes, excludes)
248
+ build_common_options(opts, options, includes + [:auto_confirm, :query, :json, :quiet, :dry_run, :remote], excludes)
248
249
  end
249
250
 
250
251
  # list is GET that supports phrase,max,offset,sort,direction
@@ -285,13 +286,24 @@ module Morpheus
285
286
  while (option_key = option_keys.shift) do
286
287
  case option_key.to_sym
287
288
 
288
- when :account
289
- opts.on('-a','--account ACCOUNT', "Account Name or ID") do |val|
289
+ when :tenant, :account
290
+ # todo: let's deprecate this in favor of :tenant --tenant to keep -a reserved for --all perhaps?
291
+ opts.on('--tenant TENANT', String, "Tenant (Account) Name or ID") do |val|
290
292
  options[:account] = val
291
293
  end
292
- opts.on('-A','--account-id ID', "Account ID") do |val|
294
+ opts.on('--tenant-id ID', String, "Tenant (Account) ID") do |val|
293
295
  options[:account_id] = val
294
296
  end
297
+ # todo: let's deprecate this in favor of :tenant --tenant to keep -a reserved for --all perhaps?
298
+ opts.on('-a','--account ACCOUNT', "Alias for --tenant") do |val|
299
+ options[:account] = val
300
+ end
301
+ opts.on('-A','--account-id ID', "Tenant (Account) ID") do |val|
302
+ options[:account_id] = val
303
+ end
304
+ opts.add_hidden_option('--tenant-id') if opts.is_a?(Morpheus::Cli::OptionParser)
305
+ opts.add_hidden_option('-a, --account') if opts.is_a?(Morpheus::Cli::OptionParser)
306
+ opts.add_hidden_option('-A, --account-id') if opts.is_a?(Morpheus::Cli::OptionParser)
295
307
 
296
308
  when :options
297
309
  options[:options] ||= {}
@@ -459,7 +471,7 @@ module Morpheus
459
471
  end
460
472
 
461
473
  # arbitrary query parameters in the format -Q "category=web&phrase=nginx"
462
- # opts.on( '-Q', '--query PARAMS', "Query parameters. PARAMS format is 'phrase=foobar&category=web'" ) do |val|
474
+ # opts.on( '-Q', '--query PARAMS', "Query parameters. PARAMS format is 'foo=bar&category=web'" ) do |val|
463
475
  # options[:query_filters_raw] = val
464
476
  # options[:query_filters] = {}
465
477
  # # todo: smarter parsing
@@ -477,7 +489,7 @@ module Morpheus
477
489
 
478
490
  when :query, :query_filters
479
491
  # arbitrary query parameters in the format -Q "category=web&phrase=nginx"
480
- opts.on( '-Q', '--query PARAMS', "Query parameters. PARAMS format is 'phrase=foobar&category=web'" ) do |val|
492
+ opts.on( '-Q', '--query PARAMS', "Query parameters. PARAMS format is 'foo=bar&category=web'" ) do |val|
481
493
  options[:query_filters_raw] = val
482
494
  options[:query_filters] = {}
483
495
  # todo: smarter parsing
@@ -512,6 +524,12 @@ module Morpheus
512
524
  end
513
525
  end
514
526
 
527
+ when :find_by_name
528
+ opts.on('--find-by-name', "Always treat the identifier argument as a name, never an ID. Useful for specifying names that look like numbers. eg. '1234'" ) do
529
+ options[:find_by_name] = true
530
+ end
531
+ # opts.add_hidden_option('--find-by-name') if opts.is_a?(Morpheus::Cli::OptionParser)
532
+
515
533
  when :remote
516
534
  opts.on( '-r', '--remote REMOTE', "Remote name. The current remote is used by default." ) do |val|
517
535
  options[:remote] = val
@@ -603,9 +621,17 @@ module Morpheus
603
621
  opts.add_hidden_option('json-raw') if opts.is_a?(Morpheus::Cli::OptionParser)
604
622
 
605
623
  when :yaml
606
- opts.on(nil, '--yaml', "YAML Output") do
607
- options[:yaml] = true
608
- options[:format] = :yaml
624
+ # -y for --yes and for --yaml
625
+ if includes.include?(:auto_confirm)
626
+ opts.on(nil, '--yaml', "YAML Output") do
627
+ options[:yaml] = true
628
+ options[:format] = :yaml
629
+ end
630
+ else
631
+ opts.on('-y', '--yaml', "YAML Output") do
632
+ options[:yaml] = true
633
+ options[:format] = :yaml
634
+ end
609
635
  end
610
636
  opts.on(nil, '--yml', "alias for --yaml") do
611
637
  options[:yaml] = true
@@ -783,7 +809,11 @@ module Morpheus
783
809
  end
784
810
  opts.add_hidden_option('--no-debug') if opts.is_a?(Morpheus::Cli::OptionParser)
785
811
 
786
-
812
+ opts.on('--hidden-help', "Print help that includes all the hidden options, like this one." ) do
813
+ puts opts.full_help_message({show_hidden_options:true})
814
+ exit # return 0 maybe?
815
+ end
816
+ opts.add_hidden_option('--hidden-help') if opts.is_a?(Morpheus::Cli::OptionParser)
787
817
  opts.on('-h', '--help', "Print this help" ) do
788
818
  puts opts
789
819
  exit # return 0 maybe?
@@ -1011,7 +1041,7 @@ module Morpheus
1011
1041
  # raise_command_error "Please specify a remote appliance with -r or see the command `remote use`"
1012
1042
  # end
1013
1043
 
1014
- Morpheus::Logging::DarkPrinter.puts "establishing connection to remote #{display_appliance(@appliance_name, @appliance_url)}" if Morpheus::Logging.debug?
1044
+ Morpheus::Logging::DarkPrinter.puts "establishing connection to remote #{display_appliance(@appliance_name, @appliance_url)}" if Morpheus::Logging.debug? # && !options[:quiet]
1015
1045
 
1016
1046
  if options[:no_authorization]
1017
1047
  # maybe handle this here..
@@ -1082,7 +1112,7 @@ module Morpheus
1082
1112
  else
1083
1113
  if opts[:min]
1084
1114
  if args.count < opts[:min]
1085
- raise_args_error("not many arguments, expected #{opts[:min] || '0'}-#{opts[:max] || 'N'} and got #{args.count == 0 ? '0' : args.count.to_s + ': '}#{args.join(', ')}", args, opts[:optparse])
1115
+ raise_args_error("not enough arguments, expected #{opts[:min] || '0'}-#{opts[:max] || 'N'} and got #{args.count == 0 ? '0' : args.count.to_s + ': '}#{args.join(', ')}", args, opts[:optparse])
1086
1116
  end
1087
1117
  end
1088
1118
  if opts[:max]
@@ -1173,22 +1203,32 @@ module Morpheus
1173
1203
  payload
1174
1204
  end
1175
1205
 
1176
- def render_response(json_response, options, object_key=nil, &block)
1177
- render_result = render_with_format(json_response, options, object_key)
1178
- if render_result
1179
- return 0, nil
1180
- else
1181
- if block_given?
1182
- return yield
1206
+ def validate_outfile(outfile, options)
1207
+ full_filename = File.expand_path(outfile)
1208
+ outdir = File.dirname(full_filename)
1209
+ if Dir.exists?(full_filename)
1210
+ print_red_alert "[local-file] is invalid. It is the name of an existing directory: #{outfile}"
1211
+ return false
1212
+ end
1213
+ if !Dir.exists?(outdir)
1214
+ if options[:mkdir]
1215
+ print cyan,"Creating local directory #{outdir}",reset,"\n"
1216
+ FileUtils.mkdir_p(outdir)
1183
1217
  else
1184
- return 0, nil
1218
+ print_red_alert "[local-file] is invalid. Directory not found: #{outdir}"
1219
+ return false
1185
1220
  end
1186
1221
  end
1222
+ if File.exists?(full_filename) && !options[:overwrite]
1223
+ print_red_alert "[local-file] is invalid. File already exists: #{outfile}\nUse -f to overwrite the existing file."
1224
+ return false
1225
+ end
1226
+ return true
1187
1227
  end
1188
1228
 
1189
1229
  # basic rendering for options :json, :yml, :csv, :quiet, and :outfile
1190
1230
  # returns the string rendered, or nil if nothing was rendered.
1191
- def render_with_format(json_response, options, object_key=nil, &block)
1231
+ def render_response(json_response, options, object_key=nil, &block)
1192
1232
  output = nil
1193
1233
  if options[:json]
1194
1234
  output = as_json(json_response, options, object_key)
@@ -1201,32 +1241,50 @@ module Morpheus
1201
1241
  else
1202
1242
  output = records_as_csv([row], options)
1203
1243
  end
1204
- elsif options[:quiet]
1205
- # note: returning non nil means the calling function knows to return rght away.. kinda weird..
1206
- # but means we need less if options[:quiet] blocks in every action.
1207
- return ""
1208
1244
  end
1209
- if output
1210
- if options[:outfile]
1245
+ if options[:outfile]
1246
+ full_outfile = File.expand_path(options[:outfile])
1247
+ if output
1211
1248
  print_to_file(output, options[:outfile], options[:overwrite])
1249
+ print "#{cyan}Wrote output to file #{options[:outfile]} (#{File.size(full_outfile)} B)\n" unless options[:quiet]
1212
1250
  else
1213
- puts output
1251
+ # uhhh ok lets try this
1252
+ Morpheus::Logging::DarkPrinter.puts "using experimental feature: --out without a common format like json, yml or csv" if Morpheus::Logging.debug?
1253
+ result = with_stdout_to_file(options[:outfile], options[:overwrite], 'w+', &block)
1254
+ if result && result != 0
1255
+ return result
1256
+ end
1257
+ print "#{cyan}Wrote output to file #{options[:outfile]} (#{File.size(full_outfile)} B)\n" unless options[:quiet]
1258
+ return 0, nil
1214
1259
  end
1215
1260
  else
1216
- if block_given?
1217
- # invoke the user given block to render (print output)
1218
- # hope it returned something well formed, there's a parse method for that..
1219
- cmd_render_result = yield
1220
- # could try to support writing output to options[:outfile] here too..
1221
- # output is already printed inside block though
1222
- # if cmd_render_result
1223
- # return output
1224
- # end
1225
- end
1261
+ # --quiet means do not render, still want to print to outfile though
1262
+ if options[:quiet]
1263
+ return 0, nil
1264
+ end
1265
+ # render ouput generated above
1266
+ if output
1267
+ puts output
1268
+ return 0, nil
1269
+ else
1270
+ # no render happened, so calling the block if given
1271
+ if block_given?
1272
+ result = yield
1273
+ if result
1274
+ return result
1275
+ else
1276
+ return 0, nil
1277
+ end
1278
+ else
1279
+ # nil means nothing was rendered, some methods still using render_with_format() are relying on this
1280
+ return nil
1281
+ end
1282
+ end
1226
1283
  end
1227
- return output
1228
1284
  end
1229
1285
 
1286
+ alias :render_with_format :render_response
1287
+
1230
1288
  module ClassMethods
1231
1289
 
1232
1290
  def set_command_name(cmd_name)
@@ -326,6 +326,9 @@ class Morpheus::Cli::CloudResourcePoolsCommand
326
326
  opts.on('--active [on|off]', String, "Can be used to disable a resource pool") do |val|
327
327
  options['active'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
328
328
  end
329
+ opts.on('--default-pool [on|off]', String, "Set resource pool as the default") do |val|
330
+ options['defaultPool'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
331
+ end
329
332
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
330
333
  opts.footer = "Update a resource pool." + "\n" +
331
334
  "[cloud] is required. This is the name or id of the cloud."
@@ -437,6 +440,11 @@ class Morpheus::Cli::CloudResourcePoolsCommand
437
440
  else
438
441
  payload['resourcePool']['active'] = true
439
442
  end
443
+
444
+ # Default
445
+ if options['defaultPool'] != nil
446
+ payload['resourcePool']['defaultPool'] = options['defaultPool']
447
+ end
440
448
 
441
449
  # Visibility
442
450
  if options['visibility'] != nil
@@ -552,6 +560,9 @@ class Morpheus::Cli::CloudResourcePoolsCommand
552
560
  opts.on('--active [on|off]', String, "Can be used to disable a resource pool") do |val|
553
561
  options['active'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
554
562
  end
563
+ opts.on('--default-pool [on|off]', String, "Set resource pool as the default") do |val|
564
+ options['defaultPool'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
565
+ end
555
566
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
556
567
  opts.footer = "Update a resource pool." + "\n" +
557
568
  "[cloud] is required. This is the name or id of the cloud." + "\n"
@@ -641,6 +652,11 @@ class Morpheus::Cli::CloudResourcePoolsCommand
641
652
  if options['active'] != nil
642
653
  payload['resourcePool']['active'] = options['active']
643
654
  end
655
+
656
+ # Default
657
+ if options['defaultPool'] != nil
658
+ payload['resourcePool']['defaultPool'] = options['defaultPool']
659
+ end
644
660
 
645
661
  # Visibility
646
662
  if options['visibility'] != nil
@@ -46,11 +46,15 @@ class Morpheus::Cli::Clouds
46
46
  opts.on( '-t', '--type TYPE', "Cloud Type" ) do |val|
47
47
  options[:zone_type] = val
48
48
  end
49
- build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
49
+ build_standard_list_options(opts, options)
50
50
  opts.footer = "List clouds."
51
51
  end
52
52
  optparse.parse!(args)
53
53
  connect(options)
54
+ # verify_args!(args:args, optparse:optparse, count:0)
55
+ if args.count > 0
56
+ options[:phrase] = args.join(" ")
57
+ end
54
58
  begin
55
59
  if options[:zone_type]
56
60
  cloud_type = cloud_type_for_name(options[:zone_type])
@@ -71,15 +75,7 @@ class Morpheus::Cli::Clouds
71
75
  end
72
76
 
73
77
  json_response = @clouds_interface.list(params)
74
- if options[:json]
75
- puts as_json(json_response, options, "zones")
76
- return 0
77
- elsif options[:yaml]
78
- puts as_yaml(json_response, options, "zones")
79
- return 0
80
- elsif options[:csv]
81
- puts records_as_csv(json_response['zones'], options)
82
- else
78
+ render_response(json_response, options, 'zones') do
83
79
  clouds = json_response['zones']
84
80
  title = "Morpheus Clouds"
85
81
  subtitles = []
@@ -99,6 +95,7 @@ class Morpheus::Cli::Clouds
99
95
  end
100
96
  print reset,"\n"
101
97
  end
98
+ return 0, nil
102
99
  rescue RestClient::Exception => e
103
100
  print_rest_exception(e, options)
104
101
  exit 1
@@ -609,15 +609,6 @@ class Morpheus::Cli::Clusters
609
609
  option_type_list = ((controller_type['optionTypes'].reject { |type| !type['enabled'] || type['fieldComponent'] } rescue []) + layout['optionTypes'] +
610
610
  (cluster_type['optionTypes'].reject { |type| !type['enabled'] || !type['creatable'] || type['fieldComponent'] } rescue [])).sort { |type| type['displayOrder'] }
611
611
 
612
- # remove volume options if volumes were configured
613
- if !server_payload['volumes'].empty?
614
- option_type_list = reject_volume_option_types(option_type_list)
615
- end
616
- # remove networkId option if networks were configured above
617
- if !server_payload['networkInterfaces'].empty?
618
- option_type_list = reject_networking_option_types(option_type_list)
619
- end
620
-
621
612
  server_payload.deep_merge!(Morpheus::Cli::OptionTypes.prompt(option_type_list, options[:options], @api_client, {zoneId: cloud['id'], siteId: group['id'], layoutId: layout['id']}))
622
613
 
623
614
  # Worker count
@@ -1197,15 +1188,6 @@ class Morpheus::Cli::Clusters
1197
1188
  (type['fieldContext'] == 'instance.networkDomain' && type['fieldName'] == 'id')
1198
1189
  } rescue [])
1199
1190
 
1200
- # remove volume options if volumes were configured
1201
- if !server_payload['volumes'].empty?
1202
- option_type_list = reject_volume_option_types(option_type_list)
1203
- end
1204
- # remove networkId option if networks were configured above
1205
- if !server_payload['networkInterfaces'].empty?
1206
- option_type_list = reject_networking_option_types(option_type_list)
1207
- end
1208
-
1209
1191
  server_payload.deep_merge!(Morpheus::Cli::OptionTypes.prompt(option_type_list, options[:options], @api_client, {zoneId: cloud['id'], siteId: group['id'], layoutId: layout['id']}))
1210
1192
 
1211
1193
  # Create User
@@ -363,7 +363,7 @@ EOT
363
363
  else
364
364
  out << "\texit: 0 "
365
365
  end
366
- total_time_str = "#{benchmark_record.duration.round((benchmark_record.duration > 0.002) ? 3 : 6)}s"
366
+ total_time_str = "#{benchmark_record.duration.round((benchmark_record.duration > 0.002) ? 3 : 6)} s"
367
367
  out << "\t #{total_time_str.ljust(9, ' ')}"
368
368
  else
369
369
  benchmark_records = []
@@ -384,8 +384,8 @@ EOT
384
384
  # all_durations = benchmark_records.collect {|benchmark_record| benchmark_record.duration }
385
385
  # total_duration = all_durations.inject(0.0) {|acc, i| acc + i }
386
386
  # avg_duration = total_duration / all_durations.size
387
- # total_time_str = "#{total_duration.round((total_duration > 0.002) ? 3 : 6)}s"
388
- # avg_time_str = "#{avg_duration.round((total_duration > 0.002) ? 3 : 6)}s"
387
+ # total_time_str = "#{total_duration.round((total_duration > 0.002) ? 3 : 6)} s"
388
+ # avg_time_str = "#{avg_duration.round((total_duration > 0.002) ? 3 : 6)} s"
389
389
 
390
390
  all_durations = []
391
391
  stats = {total: 0, avg: nil, min: nil, max: nil}
@@ -406,10 +406,10 @@ EOT
406
406
  stats[:avg] = stats[:total].to_f / all_durations.size
407
407
  end
408
408
 
409
- total_time_str = "#{stats[:total].round((stats[:total] > 0.002) ? 3 : 6)}s"
410
- min_time_str = stats[:min] ? "#{stats[:min].round((stats[:min] > 0.002) ? 3 : 6)}s" : ""
411
- max_time_str = stats[:max] ? "#{stats[:max].round((stats[:max] > 0.002) ? 3 : 6)}s" : ""
412
- avg_time_str = stats[:avg] ? "#{stats[:avg].round((stats[:avg] > 0.002) ? 3 : 6)}s" : ""
409
+ total_time_str = "#{stats[:total].round((stats[:total] > 0.002) ? 3 : 6)} s"
410
+ min_time_str = stats[:min] ? "#{stats[:min].round((stats[:min] > 0.002) ? 3 : 6)} s" : ""
411
+ max_time_str = stats[:max] ? "#{stats[:max].round((stats[:max] > 0.002) ? 3 : 6)} s" : ""
412
+ avg_time_str = stats[:avg] ? "#{stats[:avg].round((stats[:avg] > 0.002) ? 3 : 6)} s" : ""
413
413
 
414
414
  out = ""
415
415
  # <benchmark name or command>
@@ -176,7 +176,7 @@ morpheus v#{Morpheus::Cli::VERSION}
176
176
 
177
177
  To learn more about the Morpheus Appliance, visit https://www.morpheusdata.com/features
178
178
 
179
- To learn more about the Morpheus API, visit http://bertramdev.github.io/morpheus-apidoc/
179
+ To learn more about the Morpheus API, visit https://apidocs.morpheusdata.com
180
180
 
181
181
  ## GLOBAL OPTIONS
182
182
 
@@ -87,7 +87,7 @@ module Morpheus
87
87
  rescue ::RestClient::Exception => e
88
88
  #raise e
89
89
  print_red_alert "Token not valid."
90
- if options[:debug] || options[:debug]
90
+ if options[:debug]
91
91
  print_rest_exception(e, options)
92
92
  end
93
93
  wallet = nil
@@ -255,8 +255,7 @@ module Morpheus
255
255
  true
256
256
  end
257
257
 
258
- def use_refresh_token(options = {})
259
- #puts "use_refresh_token(#{options})"
258
+ def use_refresh_token(refresh_token_value, options = {})
260
259
 
261
260
  wallet = load_saved_credentials
262
261
 
@@ -265,22 +264,25 @@ module Morpheus
265
264
  return nil
266
265
  end
267
266
 
268
- if wallet['refresh_token'].nil?
269
- print_red_alert yellow,"No refresh token found for #{display_appliance(@appliance_name, @appliance_url)}",reset,"\n"
270
- return nil
267
+ if refresh_token_value.nil?
268
+ if wallet['refresh_token']
269
+ refresh_token_value = wallet['refresh_token']
270
+ else
271
+ print_red_alert yellow,"No refresh token found for #{display_appliance(@appliance_name, @appliance_url)}",reset,"\n"
272
+ return nil
273
+ end
271
274
  end
272
275
 
273
-
274
276
  username = wallet['username']
275
277
 
276
278
  begin
277
279
  auth_interface = Morpheus::AuthInterface.new({url:@appliance_url})
278
280
  auth_interface.setopts(options)
279
281
  if options[:dry_run]
280
- print_dry_run auth_interface.dry.use_refresh_token(wallet['refresh_token'])
282
+ print_dry_run auth_interface.dry.use_refresh_token(refresh_token_value)
281
283
  return nil
282
284
  end
283
- json_response = auth_interface.use_refresh_token(wallet['refresh_token'])
285
+ json_response = auth_interface.use_refresh_token(refresh_token_value)
284
286
  #wallet = json_response
285
287
  login_date = Time.now
286
288
  expire_date = nil
@@ -311,6 +313,8 @@ module Morpheus
311
313
  print_rest_exception(e, options)
312
314
  end
313
315
  wallet = nil
316
+ # return now or else it will log them out
317
+ return nil
314
318
  end
315
319
 
316
320
  # save wallet to credentials file