morpheus-cli 5.4.0 → 5.4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/account_users_interface.rb +68 -0
  4. data/lib/morpheus/api/api_client.rb +55 -10
  5. data/lib/morpheus/api/audit_interface.rb +9 -0
  6. data/lib/morpheus/api/catalog_item_types_interface.rb +20 -0
  7. data/lib/morpheus/api/instances_interface.rb +49 -0
  8. data/lib/morpheus/api/load_balancer_monitors_interface.rb +9 -0
  9. data/lib/morpheus/api/load_balancer_pools_interface.rb +4 -4
  10. data/lib/morpheus/api/load_balancer_profiles_interface.rb +4 -5
  11. data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +13 -4
  12. data/lib/morpheus/api/load_balancers_interface.rb +5 -0
  13. data/lib/morpheus/api/network_routers_interface.rb +9 -0
  14. data/lib/morpheus/api/network_static_routes_interface.rb +36 -0
  15. data/lib/morpheus/api/ping_interface.rb +2 -0
  16. data/lib/morpheus/api/read_interface.rb +4 -3
  17. data/lib/morpheus/api/rest_interface.rb +3 -3
  18. data/lib/morpheus/api/secondary_read_interface.rb +1 -1
  19. data/lib/morpheus/api/secondary_rest_interface.rb +19 -19
  20. data/lib/morpheus/api/setup_interface.rb +4 -0
  21. data/lib/morpheus/api/snapshots_interface.rb +19 -0
  22. data/lib/morpheus/api/storage_server_types_interface.rb +14 -0
  23. data/lib/morpheus/api/storage_servers_interface.rb +9 -0
  24. data/lib/morpheus/api/storage_volume_types_interface.rb +9 -0
  25. data/lib/morpheus/api/storage_volumes_interface.rb +9 -0
  26. data/lib/morpheus/api/users_interface.rb +16 -63
  27. data/lib/morpheus/cli/cli_command.rb +253 -5
  28. data/lib/morpheus/cli/cli_registry.rb +1 -1
  29. data/lib/morpheus/cli/commands/alias_command.rb +1 -1
  30. data/lib/morpheus/cli/commands/apps.rb +14 -78
  31. data/lib/morpheus/cli/commands/audit.rb +188 -0
  32. data/lib/morpheus/cli/commands/blueprints_command.rb +1 -1
  33. data/lib/morpheus/cli/commands/catalog_item_types_command.rb +88 -0
  34. data/lib/morpheus/cli/commands/change_password_command.rb +4 -4
  35. data/lib/morpheus/cli/commands/clusters.rb +96 -58
  36. data/lib/morpheus/cli/commands/hosts.rb +27 -15
  37. data/lib/morpheus/cli/commands/image_builder_command.rb +4 -8
  38. data/lib/morpheus/cli/commands/instances.rb +359 -3
  39. data/lib/morpheus/cli/commands/integrations_command.rb +1 -12
  40. data/lib/morpheus/cli/commands/library_instance_types_command.rb +3 -0
  41. data/lib/morpheus/cli/commands/load_balancer_monitors.rb +70 -0
  42. data/lib/morpheus/cli/commands/load_balancer_pools.rb +29 -50
  43. data/lib/morpheus/cli/commands/load_balancer_profiles.rb +64 -0
  44. data/lib/morpheus/cli/commands/load_balancer_types.rb +9 -4
  45. data/lib/morpheus/cli/commands/load_balancer_virtual_servers.rb +69 -58
  46. data/lib/morpheus/cli/commands/load_balancers.rb +109 -6
  47. data/lib/morpheus/cli/commands/network_firewalls_command.rb +22 -5
  48. data/lib/morpheus/cli/commands/network_routers_command.rb +96 -45
  49. data/lib/morpheus/cli/commands/network_static_routes_command.rb +451 -0
  50. data/lib/morpheus/cli/commands/network_transport_zones_command.rb +4 -4
  51. data/lib/morpheus/cli/commands/networks_command.rb +2 -2
  52. data/lib/morpheus/cli/commands/open_command.rb +30 -0
  53. data/lib/morpheus/cli/commands/options.rb +98 -0
  54. data/lib/morpheus/cli/commands/ping.rb +3 -5
  55. data/lib/morpheus/cli/commands/policies_command.rb +2 -2
  56. data/lib/morpheus/cli/commands/prices_command.rb +7 -7
  57. data/lib/morpheus/cli/commands/provisioning_settings_command.rb +1 -0
  58. data/lib/morpheus/cli/commands/remote.rb +20 -12
  59. data/lib/morpheus/cli/commands/roles.rb +1 -1
  60. data/lib/morpheus/cli/commands/security_groups.rb +2 -2
  61. data/lib/morpheus/cli/commands/service_plans_command.rb +1 -1
  62. data/lib/morpheus/cli/commands/setup.rb +1 -1
  63. data/lib/morpheus/cli/commands/shell.rb +2 -2
  64. data/lib/morpheus/cli/commands/snapshots.rb +139 -0
  65. data/lib/morpheus/cli/commands/storage_server_types.rb +50 -0
  66. data/lib/morpheus/cli/commands/storage_servers.rb +122 -0
  67. data/lib/morpheus/cli/commands/storage_volume_types.rb +50 -0
  68. data/lib/morpheus/cli/commands/storage_volumes.rb +103 -0
  69. data/lib/morpheus/cli/commands/tasks.rb +5 -5
  70. data/lib/morpheus/cli/commands/tenants_command.rb +1 -1
  71. data/lib/morpheus/cli/commands/user_groups_command.rb +1 -1
  72. data/lib/morpheus/cli/commands/user_settings_command.rb +3 -2
  73. data/lib/morpheus/cli/commands/user_sources_command.rb +1 -1
  74. data/lib/morpheus/cli/commands/users.rb +28 -28
  75. data/lib/morpheus/cli/commands/view.rb +102 -0
  76. data/lib/morpheus/cli/commands/virtual_images.rb +4 -1
  77. data/lib/morpheus/cli/mixins/accounts_helper.rb +5 -5
  78. data/lib/morpheus/cli/mixins/load_balancers_helper.rb +24 -4
  79. data/lib/morpheus/cli/mixins/print_helper.rb +50 -18
  80. data/lib/morpheus/cli/mixins/processes_helper.rb +1 -2
  81. data/lib/morpheus/cli/mixins/provisioning_helper.rb +96 -6
  82. data/lib/morpheus/cli/mixins/rest_command.rb +148 -74
  83. data/lib/morpheus/cli/mixins/secondary_rest_command.rb +174 -82
  84. data/lib/morpheus/cli/mixins/storage_servers_helper.rb +156 -0
  85. data/lib/morpheus/cli/mixins/storage_volumes_helper.rb +119 -0
  86. data/lib/morpheus/cli/option_types.rb +95 -28
  87. data/lib/morpheus/cli/version.rb +1 -1
  88. data/lib/morpheus/cli.rb +1 -0
  89. data/lib/morpheus/ext/string.rb +29 -6
  90. data/lib/morpheus/routes.rb +238 -0
  91. data/lib/morpheus/util.rb +6 -1
  92. metadata +26 -2
@@ -86,6 +86,22 @@ module Morpheus::Cli::RestCommand
86
86
 
87
87
  alias :set_rest_arg :rest_arg=
88
88
 
89
+ # rest_has_name indicates a resource has a name and can be retrieved by name or id
90
+ # true by default, set to false for lookups by only id
91
+ def rest_has_name
92
+ @rest_has_name != nil ? @rest_has_name : default_rest_has_name
93
+ end
94
+
95
+ def default_rest_has_name
96
+ true
97
+ end
98
+
99
+ def rest_has_name=(v)
100
+ @rest_has_name = !!v
101
+ end
102
+
103
+ alias :set_rest_has_name :rest_has_name=
104
+
89
105
  # rest_label is the capitalized resource label eg. "Neat Thing"
90
106
  def rest_label
91
107
  @rest_label || default_rest_label
@@ -297,6 +313,10 @@ module Morpheus::Cli::RestCommand
297
313
  self.class.rest_arg
298
314
  end
299
315
 
316
+ def rest_has_name
317
+ self.class.rest_has_name
318
+ end
319
+
300
320
  def rest_label
301
321
  self.class.rest_label
302
322
  end
@@ -316,23 +336,37 @@ module Morpheus::Cli::RestCommand
316
336
  end
317
337
 
318
338
  def rest_object_key
319
- self.send("#{rest_key}_object_key")
339
+ send("#{rest_key}_object_key")
320
340
  end
321
341
 
322
342
  def rest_list_key
323
- self.send("#{rest_key}_list_key")
343
+ send("#{rest_key}_list_key")
324
344
  end
325
345
 
326
- def rest_column_definitions
327
- self.send("#{rest_key}_column_definitions")
346
+ def rest_column_definitions(options)
347
+ send("#{rest_key}_column_definitions", options)
328
348
  end
329
349
 
330
- def rest_list_column_definitions
331
- self.send("#{rest_key}_list_column_definitions")
350
+ def rest_list_column_definitions(options)
351
+ send("#{rest_key}_list_column_definitions", options)
332
352
  end
333
353
 
334
- def rest_find_by_name_or_id(name)
335
- return self.send("find_#{rest_key}_by_name_or_id", name)
354
+ def rest_find_by_name_or_id(val)
355
+ # use explicitly defined finders
356
+ # else default to new generic CliCommand method to find anything by type (singular underscore)
357
+ if rest_has_name
358
+ if respond_to?("find_#{rest_key}_by_name_or_id", true)
359
+ send("find_#{rest_key}_by_name_or_id", val)
360
+ else
361
+ find_by_name_or_id(rest_key, val)
362
+ end
363
+ else
364
+ if respond_to?("find_#{rest_key}_by_id", true)
365
+ send("find_#{rest_key}_by_id", val)
366
+ else
367
+ find_by_id(rest_key, val)
368
+ end
369
+ end
336
370
  end
337
371
 
338
372
  def rest_has_type
@@ -353,6 +387,10 @@ module Morpheus::Cli::RestCommand
353
387
  self.class.rest_type_arg
354
388
  end
355
389
 
390
+ def rest_has_name
391
+ self.class.rest_type_arg
392
+ end
393
+
356
394
  def rest_type_label
357
395
  self.class.rest_type_label
358
396
  end
@@ -370,23 +408,29 @@ module Morpheus::Cli::RestCommand
370
408
  end
371
409
 
372
410
  def rest_type_object_key
373
- self.send("#{rest_type_key}_object_key")
411
+ send("#{rest_type_key}_object_key")
374
412
  end
375
413
 
376
414
  def rest_type_list_key
377
- self.send("#{rest_type_key}_list_key")
415
+ send("#{rest_type_key}_list_key")
378
416
  end
379
417
 
380
- def rest_type_column_definitions
381
- self.send("#{rest_type_key}_column_definitions")
418
+ def rest_type_column_definitions(options)
419
+ send("#{rest_type_key}_column_definitions", options)
382
420
  end
383
421
 
384
- def rest_type_list_column_definitions
385
- self.send("#{rest_type_key}_list_column_definitions")
422
+ def rest_type_list_column_definitions(options)
423
+ send("#{rest_type_key}_list_column_definitions", options)
386
424
  end
387
425
 
388
- def rest_type_find_by_name_or_id(name)
389
- return self.send("find_#{rest_type_key}_by_name_or_id", name)
426
+ def rest_type_find_by_name_or_id(val)
427
+ # use explicately defined finders
428
+ # else default to new generic CliCommand method to find anything by type (singular underscore)
429
+ if respond_to?("find_#{rest_type_key}_by_name_or_id", true)
430
+ send("find_#{rest_type_key}_by_name_or_id", val)
431
+ else
432
+ find_by_name_or_id(rest_type_key, val)
433
+ end
390
434
  end
391
435
 
392
436
  def registered_interfaces
@@ -417,18 +461,15 @@ module Morpheus::Cli::RestCommand
417
461
  options = {}
418
462
  optparse = Morpheus::Cli::OptionParser.new do |opts|
419
463
  opts.banner = subcommand_usage("[search]")
420
- build_standard_list_options(opts, options)
421
- opts.footer = <<-EOT
464
+ build_list_options(opts, options, params)
465
+ opts.footer = <<-EOT
422
466
  List #{rest_label_plural.downcase}.
423
467
  [search] is optional. This is a search phrase to filter the results.
424
468
  EOT
425
469
  end
426
470
  optparse.parse!(args)
427
471
  connect(options)
428
- if args.count > 0
429
- options[:phrase] = args.join(" ")
430
- end
431
- params.merge!(parse_list_options(options))
472
+ parse_list_options!(args, options, params)
432
473
  rest_interface.setopts(options)
433
474
  if options[:dry_run]
434
475
  print_dry_run rest_interface.dry.list(params)
@@ -441,7 +482,7 @@ EOT
441
482
  if records.nil? || records.empty?
442
483
  print cyan,"No #{rest_label_plural.downcase} found.",reset,"\n"
443
484
  else
444
- print as_pretty_table(records, rest_list_column_definitions.upcase_keys!, options)
485
+ print as_pretty_table(records, rest_list_column_definitions(options).upcase_keys!, options)
445
486
  print_results_pagination(json_response) if json_response['meta']
446
487
  end
447
488
  print reset,"\n"
@@ -454,27 +495,25 @@ EOT
454
495
  options = {}
455
496
  optparse = Morpheus::Cli::OptionParser.new do |opts|
456
497
  opts.banner = subcommand_usage("[#{rest_arg}]")
457
- build_standard_get_options(opts, options)
498
+ build_get_options(opts, options, params)
458
499
  opts.footer = <<-EOT
459
500
  Get details about #{a_or_an(rest_label)} #{rest_label.downcase}.
460
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
501
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
461
502
  EOT
462
503
  end
463
504
  optparse.parse!(args)
464
505
  verify_args!(args:args, optparse:optparse, min:1)
465
506
  connect(options)
466
- params.merge!(parse_query_options(options))
467
- id_list = parse_id_list(args)
468
- return run_command_for_each_arg(id_list) do |arg|
469
- _get(arg, params, options)
470
- end
507
+ parse_get_options!(args, options, params)
508
+ id = args.join(" ")
509
+ _get(id, params, options)
471
510
  end
472
511
 
473
512
  def _get(id, params, options)
474
- if id !~ /\A\d{1,}\Z/
513
+ if id !~ /\A\d{1,}\Z/ && rest_has_name
475
514
  record = rest_find_by_name_or_id(id)
476
515
  if record.nil?
477
- raise_command_error "#{rest_label} not found for name '#{id}'"
516
+ return 1, "#{rest_label} not found for '#{id}'"
478
517
  end
479
518
  id = record['id']
480
519
  end
@@ -493,8 +532,14 @@ EOT
493
532
  record = json_response[rest_object_key]
494
533
  print_h1 rest_label, [], options
495
534
  print cyan
496
- print_description_list(rest_column_definitions, record, options)
497
- # show config settings...
535
+ print_description_list(rest_column_definitions(options), record, options)
536
+ # # could always show config eh? or maybe only with --config if that is nicer.
537
+ # # config = record['config'].is_a?(Hash) && !record['config'].empty?
538
+ # if config && !config.empty?
539
+ # print_h2 "Configuration"
540
+ # print_description_list(config.keys, config)
541
+ # end
542
+ # Option Types
498
543
  if record['optionTypes'] && record['optionTypes'].size > 0
499
544
  print_h2 "Option Types", options
500
545
  print format_option_types_table(record['optionTypes'], options, rest_object_key)
@@ -507,45 +552,49 @@ EOT
507
552
  record_type = nil
508
553
  record_type_id = nil
509
554
  options = {}
555
+ option_types = respond_to?("add_#{rest_key}_option_types", true) ? send("add_#{rest_key}_option_types") : []
556
+ advanced_option_types = respond_to?("add_#{rest_key}_advanced_option_types", true) ? send("add_#{rest_key}_advanced_option_types") : []
557
+ type_option_type = option_types.find {|it| it['fieldName'] == 'type'}
510
558
  optparse = Morpheus::Cli::OptionParser.new do |opts|
511
559
  opts.banner = subcommand_usage("[#{rest_arg}]")
512
- if rest_has_type
560
+ if rest_has_type && type_option_type.nil?
513
561
  opts.on( '-t', "--#{rest_type_arg} TYPE", "#{rest_type_label}" ) do |val|
514
562
  record_type_id = val
515
563
  end
516
564
  end
517
- if self.class.method_defined?("add_#{rest_key}_option_types")
518
- build_option_type_options(opts, options, self.send("add_#{rest_key}_option_types"))
519
- end
520
- if self.class.method_defined?("add_#{rest_key}_advanced_option_types")
521
- build_option_type_options(opts, options, self.send("add_#{rest_key}_advanced_option_types"))
522
- end
565
+ build_option_type_options(opts, options, option_types)
566
+ build_option_type_options(opts, options, advanced_option_types)
523
567
  build_standard_add_options(opts, options)
524
568
  opts.footer = <<-EOT
525
569
  Create a new #{rest_label.downcase}.
526
570
  [#{rest_arg}] is required. This is the name of the new #{rest_label.downcase}.
527
571
  EOT
572
+ opts.footer += send "add_#{rest_key}_footer_addn" if respond_to?("add_#{rest_key}_footer_addn", true)
528
573
  end
529
574
  optparse.parse!(args)
530
575
  # todo: make supporting args[0] optional and more flexible
531
576
  # for now args[0] is assumed to be the 'name'
532
577
  record_name = nil
533
- if args[0] # && rest_has_name
534
- record_name = args[0]
578
+ if rest_has_name
579
+ if args.count > 0
580
+ record_name = args.join(" ")
581
+ end
582
+ verify_args!(args:args, optparse:optparse, min:0, max: 1)
583
+ else
584
+ verify_args!(args:args, optparse:optparse, count: 0)
535
585
  end
536
- verify_args!(args:args, optparse:optparse, min:0, max: 1)
537
586
  connect(options)
538
587
  # load or prompt for type
539
- if rest_has_type
588
+ if rest_has_type && type_option_type.nil?
540
589
  if record_type_id.nil?
541
590
  #raise_command_error "#{rest_type_label} is required.\n#{optparse}"
542
- type_list = rest_type_interface.list({max:10000})[rest_type_list_key]
543
- type_dropdown_options = type_list.collect {|it| {'name' => it['name'], 'value' => it['code']} }
591
+ type_list = rest_type_interface.list({max:10000, creatable:true})[rest_type_list_key]
592
+ type_dropdown_options = respond_to?("#{rest_key}_type_list_to_options", true) ? send("#{rest_key}_type_list_to_options", type_list) : type_list.collect {|it| {'name' => it['name'], 'value' => it['code']} }
544
593
  record_type_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'fieldLabel' => rest_type_label, 'type' => 'select', 'selectOptions' => type_dropdown_options, 'required' => true}], options[:options], @api_client)['type']
545
594
  end
546
595
  record_type = rest_type_find_by_name_or_id(record_type_id)
547
596
  if record_type.nil?
548
- raise_command_error "#{rest_type_label} not found for '#{record_type_id}'.\n#{optparse}"
597
+ return 1, "#{rest_type_label} not found for '#{record_type_id}"
549
598
  end
550
599
  end
551
600
  passed_options = parse_passed_options(options)
@@ -568,15 +617,32 @@ EOT
568
617
  options[:params]['type'] = record_type['code']
569
618
  end
570
619
  record_payload.deep_merge!(passed_options)
571
- if self.class.method_defined?("add_#{rest_key}_option_types")
572
- add_option_types = self.send("add_#{rest_key}_option_types")
573
- v_prompt = Morpheus::Cli::OptionTypes.prompt(add_option_types, options[:options], @api_client, options[:params])
620
+ if option_types && !option_types.empty?
621
+ v_prompt = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
574
622
  v_prompt.deep_compact!
575
623
  v_prompt.booleanize! # 'on' => true
576
624
  record_payload.deep_merge!(v_prompt)
577
625
  end
578
626
  # options by type
579
- my_option_types = record_type ? record_type['optionTypes'] : nil
627
+ if rest_has_type && record_type.nil?
628
+ type_value = record_payload['type'].is_a?(Hash) ? record_payload['type']['id'] : record_payload['type']
629
+ if type_value
630
+ record_type = rest_type_find_by_name_or_id(type_value)
631
+ if record_type.nil?
632
+ return 1, "#{rest_type_label} not found for '#{type_value}"
633
+ end
634
+ end
635
+ # reload the type by id to get all the details ie. optionTypes
636
+ if record_type && record_type['optionTypes'].nil?
637
+ record_type = rest_type_find_by_name_or_id(record_type['id'])
638
+ end
639
+ end
640
+ my_option_types = nil
641
+ if respond_to?("load_option_types_for_#{rest_key}", true)
642
+ my_option_types = send("load_option_types_for_#{rest_key}", record_type, nil)
643
+ else
644
+ my_option_types = record_type ? record_type['optionTypes'] : nil
645
+ end
580
646
  if my_option_types && !my_option_types.empty?
581
647
  # remove redundant fieldContext
582
648
  my_option_types.each do |option_type|
@@ -584,15 +650,15 @@ EOT
584
650
  option_type['fieldContext'] = nil
585
651
  end
586
652
  end
587
- v_prompt = Morpheus::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, options[:params])
653
+ api_params = (options[:params] || {}).merge(record_payload)
654
+ v_prompt = Morpheus::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, api_params)
588
655
  v_prompt.deep_compact!
589
656
  v_prompt.booleanize! # 'on' => true
590
657
  record_payload.deep_merge!(v_prompt)
591
658
  end
592
659
  # advanced options (uses no_prompt)
593
- if self.class.method_defined?("add_#{rest_key}_advanced_option_types")
594
- add_advanced_option_types = self.send("add_#{rest_key}_advanced_option_types")
595
- v_prompt = Morpheus::Cli::OptionTypes.no_prompt(add_advanced_option_types, options[:options], @api_client, options[:params])
660
+ if advanced_option_types && !advanced_option_types.empty?
661
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
596
662
  v_prompt.deep_compact!
597
663
  v_prompt.booleanize! # 'on' => true
598
664
  record_payload.deep_merge!(v_prompt)
@@ -618,19 +684,18 @@ EOT
618
684
  record_type = nil
619
685
  record_type_id = nil
620
686
  options = {}
687
+ option_types = respond_to?("update_#{rest_key}_option_types", true) ? send("update_#{rest_key}_option_types") : []
688
+ advanced_option_types = respond_to?("update_#{rest_key}_advanced_option_types", true) ? send("update_#{rest_key}_advanced_option_types") : []
621
689
  optparse = Morpheus::Cli::OptionParser.new do |opts|
622
690
  opts.banner = subcommand_usage("[#{rest_arg}] [options]")
623
- if self.class.method_defined?("update_#{rest_key}_option_types")
624
- build_option_type_options(opts, options, self.send("update_#{rest_key}_option_types"))
625
- end
626
- if self.class.method_defined?("update_#{rest_key}_advanced_option_types")
627
- build_option_type_options(opts, options, self.send("update_#{rest_key}_advanced_option_types"))
628
- end
691
+ build_option_type_options(opts, options, option_types)
692
+ build_option_type_options(opts, options, advanced_option_types)
629
693
  build_standard_update_options(opts, options)
630
694
  opts.footer = <<-EOT
631
695
  Update an existing #{rest_label.downcase}.
632
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
696
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
633
697
  EOT
698
+ opts.footer += send "update_#{rest_key}_footer_addn" if respond_to?("update_#{rest_key}_footer_addn", true)
634
699
  end
635
700
  optparse.parse!(args)
636
701
  verify_args!(args:args, optparse:optparse, count:1)
@@ -644,7 +709,11 @@ EOT
644
709
  record_type_id = record['type']['id']
645
710
  record_type = rest_type_find_by_name_or_id(record_type_id)
646
711
  if record_type.nil?
647
- raise_command_error "#{rest_type_label} not found for '#{record_type_id}'.\n#{optparse}"
712
+ return 1, "#{rest_type_label} not found for '#{record_type_id}"
713
+ end
714
+ # reload the type by id to get all the details ie. optionTypes
715
+ if record_type['optionTypes'].nil?
716
+ record_type = rest_type_find_by_name_or_id(record_type['id'])
648
717
  end
649
718
  end
650
719
  passed_options = parse_passed_options(options)
@@ -663,15 +732,20 @@ EOT
663
732
  options[:params]['type'] = record_type['code']
664
733
  end
665
734
  # update options without prompting by default
666
- if self.class.method_defined?("update_#{rest_key}_option_types")
667
- update_option_types = self.send("update_#{rest_key}_option_types")
668
- v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_option_types, options[:options], @api_client, options[:params])
735
+ if option_types && !option_types.empty?
736
+ api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
737
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(option_types, options[:options], @api_client, api_params)
669
738
  v_prompt.deep_compact!
670
739
  v_prompt.booleanize! # 'on' => true
671
740
  record_payload.deep_merge!(v_prompt)
672
741
  end
673
742
  # options by type
674
- my_option_types = record_type ? record_type['optionTypes'] : nil
743
+ my_option_types = nil
744
+ if respond_to?("load_option_types_for_#{rest_key}", true)
745
+ my_option_types = send("load_option_types_for_#{rest_key}", record_type, nil)
746
+ else
747
+ my_option_types = record_type ? record_type['optionTypes'] : nil
748
+ end
675
749
  if my_option_types && !my_option_types.empty?
676
750
  # remove redundant fieldContext
677
751
  # make them optional for updates
@@ -684,15 +758,15 @@ EOT
684
758
  option_type.delete('required')
685
759
  option_type.delete('defaultValue')
686
760
  end
687
- v_prompt = Morpheus::Cli::OptionTypes.no_prompt(my_option_types, options[:options], @api_client, options[:params])
761
+ api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
762
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(my_option_types, options[:options], @api_client, api_params)
688
763
  v_prompt.deep_compact!
689
764
  v_prompt.booleanize! # 'on' => true
690
765
  record_payload.deep_merge!(v_prompt)
691
766
  end
692
767
  # advanced options
693
- if self.class.method_defined?("update_#{rest_key}_advanced_option_types")
694
- update_advanced_option_types = self.send("update_#{rest_key}_advanced_option_types")
695
- v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_advanced_option_types, options[:options], @api_client, options[:params])
768
+ if advanced_option_types && !advanced_option_types.empty?
769
+ v_prompt = Morpheus::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
696
770
  v_prompt.deep_compact!
697
771
  v_prompt.booleanize! # 'on' => true
698
772
  record_payload.deep_merge!(v_prompt)
@@ -729,7 +803,7 @@ EOT
729
803
  build_standard_remove_options(opts, options)
730
804
  opts.footer = <<-EOT
731
805
  Delete an existing #{rest_label.downcase}.
732
- [#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
806
+ [#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
733
807
  EOT
734
808
  end
735
809
  optparse.parse!(args)
@@ -745,7 +819,7 @@ EOT
745
819
  end
746
820
  rest_interface.setopts(options)
747
821
  if options[:dry_run]
748
- print_dry_run rest_interface.dry.destroy(record['id'])
822
+ print_dry_run rest_interface.dry.destroy(record['id'], params)
749
823
  return 0, nil
750
824
  end
751
825
  json_response = rest_interface.destroy(record['id'], params)