morpheus-cli 3.6.8 → 3.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/lib/morpheus/api/account_groups_interface.rb +2 -2
  3. data/lib/morpheus/api/accounts_interface.rb +4 -7
  4. data/lib/morpheus/api/api_client.rb +207 -70
  5. data/lib/morpheus/api/app_templates_interface.rb +7 -28
  6. data/lib/morpheus/api/apps_interface.rb +14 -21
  7. data/lib/morpheus/api/archive_buckets_interface.rb +2 -2
  8. data/lib/morpheus/api/archive_files_interface.rb +6 -6
  9. data/lib/morpheus/api/auth_interface.rb +14 -1
  10. data/lib/morpheus/api/blueprints_interface.rb +9 -16
  11. data/lib/morpheus/api/cloud_datastores_interface.rb +1 -1
  12. data/lib/morpheus/api/cloud_policies_interface.rb +1 -1
  13. data/lib/morpheus/api/clouds_interface.rb +18 -21
  14. data/lib/morpheus/api/cypher_interface.rb +19 -28
  15. data/lib/morpheus/api/file_copy_request_interface.rb +1 -1
  16. data/lib/morpheus/api/group_policies_interface.rb +1 -1
  17. data/lib/morpheus/api/groups_interface.rb +4 -4
  18. data/lib/morpheus/api/image_builder_boot_scripts_interface.rb +1 -1
  19. data/lib/morpheus/api/image_builder_image_builds_interface.rb +2 -2
  20. data/lib/morpheus/api/image_builder_preseed_scripts_interface.rb +1 -1
  21. data/lib/morpheus/api/instances_interface.rb +17 -23
  22. data/lib/morpheus/api/logs_interface.rb +7 -10
  23. data/lib/morpheus/api/network_domains_interface.rb +1 -1
  24. data/lib/morpheus/api/network_groups_interface.rb +1 -1
  25. data/lib/morpheus/api/network_pool_servers_interface.rb +1 -1
  26. data/lib/morpheus/api/network_pools_interface.rb +1 -1
  27. data/lib/morpheus/api/network_proxies_interface.rb +1 -1
  28. data/lib/morpheus/api/network_services_interface.rb +1 -1
  29. data/lib/morpheus/api/networks_interface.rb +1 -1
  30. data/lib/morpheus/api/old_cypher_interface.rb +55 -0
  31. data/lib/morpheus/api/packages_interface.rb +1 -1
  32. data/lib/morpheus/api/policies_interface.rb +1 -1
  33. data/lib/morpheus/api/setup_interface.rb +1 -1
  34. data/lib/morpheus/api/storage_providers_interface.rb +1 -1
  35. data/lib/morpheus/api/whoami_interface.rb +1 -1
  36. data/lib/morpheus/benchmarking.rb +277 -0
  37. data/lib/morpheus/cli.rb +6 -22
  38. data/lib/morpheus/cli/access_token_command.rb +172 -0
  39. data/lib/morpheus/cli/accounts.rb +5 -0
  40. data/lib/morpheus/cli/apps.rb +93 -37
  41. data/lib/morpheus/cli/archives_command.rb +0 -2
  42. data/lib/morpheus/cli/auth_command.rb +112 -0
  43. data/lib/morpheus/cli/blueprints_command.rb +50 -13
  44. data/lib/morpheus/cli/change_password_command.rb +148 -0
  45. data/lib/morpheus/cli/cli_command.rb +173 -49
  46. data/lib/morpheus/cli/clouds.rb +15 -5
  47. data/lib/morpheus/cli/command_error.rb +7 -1
  48. data/lib/morpheus/cli/{alias_command.rb → commands/standard/alias_command.rb} +79 -51
  49. data/lib/morpheus/cli/commands/standard/benchmark_command.rb +399 -0
  50. data/lib/morpheus/cli/commands/standard/coloring_command.rb +60 -0
  51. data/lib/morpheus/cli/{curl_command.rb → commands/standard/curl_command.rb} +0 -7
  52. data/lib/morpheus/cli/commands/standard/debug_command.rb +61 -0
  53. data/lib/morpheus/cli/{echo_command.rb → commands/standard/echo_command.rb} +1 -1
  54. data/lib/morpheus/cli/{edit_profile_command.rb → commands/standard/edit_profile_command.rb} +0 -0
  55. data/lib/morpheus/cli/{edit_rc_command.rb → commands/standard/edit_rc_command.rb} +0 -0
  56. data/lib/morpheus/cli/commands/standard/get_prompt_command.rb +39 -0
  57. data/lib/morpheus/cli/commands/standard/history_command.rb +76 -0
  58. data/lib/morpheus/cli/{log_level_command.rb → commands/standard/log_level_command.rb} +1 -1
  59. data/lib/morpheus/cli/{man_command.rb → commands/standard/man_command.rb} +2 -2
  60. data/lib/morpheus/cli/commands/standard/rm_command.rb +14 -0
  61. data/lib/morpheus/cli/commands/standard/set_prompt_command.rb +54 -0
  62. data/lib/morpheus/cli/{sleep_command.rb → commands/standard/sleep_command.rb} +0 -0
  63. data/lib/morpheus/cli/{source_command.rb → commands/standard/source_command.rb} +0 -0
  64. data/lib/morpheus/cli/{ssl_verification_command.rb → commands/standard/ssl_verification_command.rb} +1 -1
  65. data/lib/morpheus/cli/commands/standard/tee_command.rb +14 -0
  66. data/lib/morpheus/cli/{version_command.rb → commands/standard/version_command.rb} +0 -0
  67. data/lib/morpheus/cli/credentials.rb +276 -87
  68. data/lib/morpheus/cli/cypher_command.rb +333 -214
  69. data/lib/morpheus/cli/error_handler.rb +12 -2
  70. data/lib/morpheus/cli/groups.rb +44 -20
  71. data/lib/morpheus/cli/hosts.rb +39 -16
  72. data/lib/morpheus/cli/instances.rb +114 -62
  73. data/lib/morpheus/cli/login.rb +74 -21
  74. data/lib/morpheus/cli/logout.rb +3 -4
  75. data/lib/morpheus/cli/mixins/accounts_helper.rb +50 -18
  76. data/lib/morpheus/cli/mixins/print_helper.rb +207 -42
  77. data/lib/morpheus/cli/old_cypher_command.rb +414 -0
  78. data/lib/morpheus/cli/option_parser.rb +6 -1
  79. data/lib/morpheus/cli/processes_command.rb +3 -0
  80. data/lib/morpheus/cli/remote.rb +11 -17
  81. data/lib/morpheus/cli/roles.rb +17 -17
  82. data/lib/morpheus/cli/security_groups.rb +47 -17
  83. data/lib/morpheus/cli/shell.rb +139 -79
  84. data/lib/morpheus/cli/tenants_command.rb +353 -0
  85. data/lib/morpheus/cli/users.rb +26 -18
  86. data/lib/morpheus/cli/version.rb +1 -1
  87. data/lib/morpheus/cli/whoami.rb +14 -10
  88. data/lib/morpheus/formatters.rb +4 -4
  89. data/lib/morpheus/logging.rb +16 -8
  90. data/lib/morpheus/terminal.rb +63 -34
  91. metadata +28 -15
  92. data/lib/morpheus/cli/coloring_command.rb +0 -45
  93. data/lib/morpheus/cli/set_prompt_command.rb +0 -51
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'json'
3
3
  require 'morpheus/logging'
4
+ require 'morpheus/benchmarking'
4
5
  require 'morpheus/cli/option_parser'
5
6
  require 'morpheus/cli/cli_registry'
6
7
  require 'morpheus/cli/mixins/print_helper'
@@ -18,6 +19,7 @@ module Morpheus
18
19
 
19
20
  def self.included(klass)
20
21
  klass.send :include, Morpheus::Cli::PrintHelper
22
+ klass.send :include, Morpheus::Benchmarking::HasBenchmarking
21
23
  klass.extend ClassMethods
22
24
  Morpheus::Cli::CliRegistry.add(klass, klass.command_name)
23
25
  end
@@ -66,6 +68,13 @@ module Morpheus
66
68
  my_terminal.stderr.puts(*msgs)
67
69
  end
68
70
 
71
+ # todo: customizable output color, other than cyan.
72
+ # def terminal_fg
73
+ # end
74
+ # def cyan
75
+ # Term::ANSIColor.black
76
+ # end
77
+
69
78
  # todo: use terminal.stdin
70
79
  # def readline(*msgs)
71
80
  # @my_terminal.stdin.readline(*msgs)
@@ -179,11 +188,16 @@ module Morpheus
179
188
  # @param options [Hash] the output Hash that is to being modified
180
189
  # @param includes [Array] which options to include eg. :options, :json, :remote
181
190
  # @return opts
182
- def build_common_options(opts, options, includes=[])
191
+ def build_common_options(opts, options, includes=[], excludes=[])
183
192
  #opts.separator ""
184
193
  # opts.separator "Common options:"
185
- includes = includes.clone
186
- while (option_key = includes.shift) do
194
+ option_keys = includes.clone
195
+ # todo: support --quiet everywhere
196
+ # turn on some options all the time..
197
+ # unless command_name == "shell"
198
+ # option_keys << :quiet unless option_keys.include?(:quiet)
199
+ # end
200
+ while (option_key = option_keys.shift) do
187
201
  case option_key.to_sym
188
202
 
189
203
  when :account
@@ -400,47 +414,56 @@ module Morpheus
400
414
  end
401
415
 
402
416
  when :remote
403
-
404
- # this is the only option now...
405
- # first, you must do `remote use [appliance]`
406
- opts.on( '-r', '--remote REMOTE', "Remote Appliance Name to use for this command. The active appliance is used by default." ) do |val|
417
+ opts.on( '-r', '--remote REMOTE', "Remote name. The current remote is used by default." ) do |val|
407
418
  options[:remote] = val
408
419
  end
420
+ opts.on( nil, '--remote-url URL', "Remote url. The current remote url is used by default." ) do |val|
421
+ options[:remote_url] = val
422
+ end
423
+ opts.on( '-T', '--token TOKEN', "Access token for authentication with --remote. Saved credentials are used by default." ) do |val|
424
+ options[:remote_token] = val
425
+ end unless excludes.include?(:remote_token)
426
+ opts.on( '-U', '--username USERNAME', "Username for authentication." ) do |val|
427
+ options[:remote_username] = val
428
+ end unless excludes.include?(:remote_username)
429
+ opts.on( '-P', '--password PASSWORD', "Password for authentication." ) do |val|
430
+ options[:remote_password] = val
431
+ end unless excludes.include?(:remote_password)
409
432
 
410
433
  # todo: also require this for talking to plain old HTTP
411
434
  opts.on('-I','--insecure', "Allow insecure HTTPS communication. i.e. bad SSL certificate.") do |val|
412
435
  options[:insecure] = true
413
436
  Morpheus::RestClient.enable_ssl_verification = false
414
437
  end
415
-
416
- opts.on( '-T', '--token ACCESS_TOKEN', "Access Token for api requests. While authenticated to a remote, the current saved credentials are used." ) do |remote|
417
- options[:remote_token] = remote
418
- end
419
-
420
- # skipping the rest of this for now..
421
-
422
- next
423
-
424
- # opts.on( '-r', '--remote REMOTE', "Remote Appliance" ) do |remote|
425
- # options[:remote] = remote
426
- # end
427
-
428
- opts.on( '-U', '--url REMOTE', "API Url" ) do |remote|
429
- options[:remote_url] = remote
430
- end
431
-
432
- opts.on( '-u', '--username USERNAME', "Username" ) do |remote|
433
- options[:remote_username] = remote
438
+
439
+ #when :header, :headers
440
+ opts.on( '-H', '--header HEADER', "Additional HTTP header to include with requests." ) do |val|
441
+ options[:headers] ||= {}
442
+ # header_list = val.to_s.split(',')
443
+ header_list = [val.to_s]
444
+ header_list.each do |h|
445
+ header_parts = val.to_s.split(":")
446
+ header_key, header_value = header_parts[0], header_parts[1..-1].join(":")
447
+ if header_parts.size() < 2
448
+ header_parts = val.to_s.split("=")
449
+ header_key, header_value = header_parts[0], header_parts[1..-1].join("=")
450
+ end
451
+ if header_parts.size() < 2
452
+ raise_command_error "Invalid HEADER value '#{val}'. HEADER should contain a key and a value. eg. -H 'X-Morpheus-Lease: $MORPHEUS_LEASE_TOKEN'"
453
+ end
454
+ options[:headers][header_key] = header_value
455
+ end
434
456
  end
457
+ # opts.add_hidden_option('-H') if opts.is_a?(Morpheus::Cli::OptionParser)
458
+ # opts.add_hidden_option('--header') if opts.is_a?(Morpheus::Cli::OptionParser)
459
+ opts.add_hidden_option('--headers') if opts.is_a?(Morpheus::Cli::OptionParser)
435
460
 
436
- opts.on( '-p', '--password PASSWORD', "Password" ) do |remote|
437
- options[:remote_password] = remote
461
+ #when :timeout
462
+ opts.on( '--timeout SECONDS', "Timeout for api requests. Default is typically 30 seconds." ) do |val|
463
+ options[:timeout] = val ? val.to_f : nil
438
464
  end
465
+ # opts.add_hidden_option('--timeout') if opts.is_a?(Morpheus::Cli::OptionParser)
439
466
 
440
- opts.on( '-T', '--token ACCESS_TOKEN', "Access Token" ) do |remote|
441
- options[:remote_token] = remote
442
- end
443
-
444
467
  when :auto_confirm
445
468
  opts.on( '-y', '--yes', "Auto Confirm" ) do
446
469
  options[:yes] = true
@@ -512,6 +535,11 @@ module Morpheus
512
535
  options[:include_fields] = val
513
536
  end
514
537
 
538
+ when :thin
539
+ opts.on( '--thin', '--thin', "Format headers and columns with thin borders." ) do |val|
540
+ options[:border_style] = :thin
541
+ end
542
+
515
543
  when :outfile
516
544
  opts.on('--out FILE', String, "Write standard output to a file instead of the terminal.") do |val|
517
545
  # could validate directory is writable..
@@ -520,9 +548,31 @@ module Morpheus
520
548
 
521
549
  when :dry_run
522
550
  opts.on('-d','--dry-run', "Dry Run, print the API request instead of executing it") do
551
+ # todo: this should print after parsing obv..
552
+ # need a hook after parse! or a standard_handle(options) { ... } paradigm
553
+ # either that or hook it up in every command somehow, maybe a hook on connect()
554
+ #puts "#{cyan}#{dark} #=> DRY RUN#{reset}"
555
+ # don't print this for --json combined with -d
556
+ # print once and dont munge json
557
+ if !options[:curl] && !options[:json]
558
+ puts "#{cyan}#{bold}#{dark}DRY RUN#{reset}"
559
+ end
523
560
  options[:dry_run] = true
524
561
  end
525
-
562
+ opts.on(nil,'--curl', "Dry Run to output API request as a curl command.") do
563
+ # print once and dont munge json
564
+ if !options[:dry_run] && !options[:json]
565
+ puts "#{cyan}#{bold}#{dark}DRY RUN#{reset}"
566
+ end
567
+ options[:dry_run] = true
568
+ options[:curl] = true
569
+ end
570
+ # hide until fully supported
571
+ opts.add_hidden_option('--curl') if opts.is_a?(Morpheus::Cli::OptionParser)
572
+ opts.on(nil,'--scrub', "Mask secrets in output, such as the Authorization header. For use with --curl") do
573
+ options[:scrub] = true
574
+ end
575
+ opts.add_hidden_option('--scrub') if opts.is_a?(Morpheus::Cli::OptionParser)
526
576
  when :quiet
527
577
  opts.on('-q','--quiet', "No Output, do not print to stdout") do
528
578
  options[:quiet] = true
@@ -535,11 +585,32 @@ module Morpheus
535
585
 
536
586
  # options that are always included
537
587
 
588
+ # always support thin, but hidden because mostly not hooked up at the moment...
589
+ unless includes.include?(:thin)
590
+ opts.on( '--thin', '--thin', "Format headers and columns with thin borders." ) do |val|
591
+ options[:border_style] = :thin
592
+ end
593
+ opts.add_hidden_option('--thin') if opts.is_a?(Morpheus::Cli::OptionParser)
594
+ end
595
+
538
596
  # disable ANSI coloring
539
597
  opts.on('-C','--nocolor', "Disable ANSI coloring") do
540
598
  Term::ANSIColor::coloring = false
541
599
  end
542
600
 
601
+
602
+ # Benchmark this command?
603
+ opts.on('-B','--benchmark', "Print benchmark time after the command is finished.") do
604
+ options[:benchmark] = true
605
+ # this is hacky, but working!
606
+ # shell handles returning to false
607
+ #Morpheus::Benchmarking.enabled = true
608
+ #my_terminal.benchmarking = true
609
+ #start_benchmark(args.join(' '))
610
+ # ok it happens outside of handle() alltogether..
611
+ # wow, simplify me plz
612
+ end
613
+
543
614
  opts.on('-V','--debug', "Print extra output for debugging.") do
544
615
  options[:debug] = true
545
616
  Morpheus::Logging.set_log_level(Morpheus::Logging::Logger::DEBUG)
@@ -553,9 +624,9 @@ module Morpheus
553
624
  # end
554
625
  end
555
626
 
556
- opts.on('-h', '--help', "Prints this help" ) do
627
+ opts.on('-h', '--help', "Print this help" ) do
557
628
  puts opts
558
- exit
629
+ exit # return 0 maybe?
559
630
  end
560
631
 
561
632
  opts
@@ -646,7 +717,7 @@ module Morpheus
646
717
  cmd_method = subcommands[subcommand_name]
647
718
  if !cmd_method
648
719
  print_error Morpheus::Terminal.angry_prompt
649
- puts_error "'#{subcommand_name}' is not a morpheus #{self.command_name} command. See '#{my_help_command}'"
720
+ puts_error "'#{subcommand_name}' is not recognized. See '#{my_help_command}'"
650
721
  return 127
651
722
  end
652
723
  self.send(cmd_method, args[1..-1])
@@ -733,26 +804,32 @@ module Morpheus
733
804
  Morpheus::Logging::DarkPrinter.puts "establishing connection to [#{@appliance_name}] #{@appliance_url}" if options[:debug]
734
805
  #puts "#{dark} #=> establishing connection to [#{@appliance_name}] #{@appliance_url}#{reset}\n" if options[:debug]
735
806
 
736
-
737
- # punt.. and just allow passing an access token instead for now..
738
- # this skips saving to the appliances file and all that..
739
- if options[:token]
740
- @access_token = options[:token]
741
- end
742
807
 
743
808
  # ok, get some credentials.
744
809
  # this prompts for username, password without options[:no_prompt]
745
- # used saved credentials please
746
- @api_credentials = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url)
810
+ # uses saved credentials by default.
811
+ # passing --remote-url or --token or --username will skip loading saved credentials and trigger prompting
747
812
  if options[:remote_token]
748
813
  @access_token = options[:remote_token]
749
814
  else
750
- @access_token = @api_credentials.load_saved_credentials()
751
- if @access_token.to_s.empty?
752
- unless options[:no_prompt]
753
- @access_token = @api_credentials.request_credentials(options)
754
- end
815
+ credentials = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url)
816
+ # @wallet = credentials.load_saved_credentials()
817
+ # @wallet = credentials.request_credentials(options)
818
+ if options[:remote_token]
819
+ @wallet = credentials.request_credentials(options, false)
820
+ elsif options[:remote_url] || options[:remote_username]
821
+ @wallet = credentials.request_credentials(options, false)
822
+ else
823
+ #@wallet = credentials.request_credentials(options)
824
+ @wallet = credentials.load_saved_credentials()
755
825
  end
826
+ @access_token = @wallet ? @wallet['access_token'] : nil
827
+ # if @access_token.to_s.empty?
828
+ # unless options[:no_prompt]
829
+ # @wallet = credentials.request_credentials(options)
830
+ # @access_token = @wallet ? @wallet['access_token'] : nil
831
+ # end
832
+ # end
756
833
  # bail if we got nothing still
757
834
  unless options[:skip_verify_access_token]
758
835
  verify_access_token!
@@ -854,8 +931,44 @@ module Morpheus
854
931
  return output
855
932
  end
856
933
 
934
+ def parse_command_result(cmd_result)
935
+ self.class.parse_command_result(cmd_result)
936
+ end
937
+
857
938
  module ClassMethods
858
939
 
940
+ # Parse exit_code and err from a command result (object of some type)
941
+ # returns [exit_code, err]
942
+ def parse_command_result(cmd_result)
943
+ exit_code, err = nil, nil
944
+ if cmd_result.is_a?(Array)
945
+ exit_code, err = cmd_result[0], cmd_result[1]
946
+ elsif cmd_result.is_a?(Hash)
947
+ exit_code, err = cmd_result[:exit_code], (cmd_result[:error] || cmd_result[:err])
948
+ end
949
+ if cmd_result == nil || cmd_result == true
950
+ exit_code = 0
951
+ elsif cmd_result == false
952
+ exit_code = 1
953
+ elsif cmd_result.is_a?(Integer)
954
+ exit_code = cmd_result
955
+ elsif cmd_result.is_a?(Float)
956
+ exit_code = cmd_result.to_i
957
+ elsif cmd_result.is_a?(String)
958
+ exit_code = cmd_result.to_i
959
+ else
960
+ if cmd_result.respond_to?(:to_i)
961
+ exit_code = cmd_result.to_i
962
+ else
963
+ # happens for aliases right now.. and execution flow probably, need to handle Array
964
+ # uncomment to track them down, proceed with exit 0 for now
965
+ #Morpheus::Logging::DarkPrinter.puts "debug: command #{command_name} produced an unexpected result: (#{cmd_result.class}) #{cmd_result}" if Morpheus::Logging.debug?
966
+ exit_code = 0
967
+ end
968
+ end
969
+ return exit_code, err
970
+ end
971
+
859
972
  def set_command_name(cmd_name)
860
973
  @command_name = cmd_name
861
974
  Morpheus::Cli::CliRegistry.add(self, self.command_name)
@@ -880,6 +993,17 @@ module Morpheus
880
993
  !!@hidden_command
881
994
  end
882
995
 
996
+ def command_description
997
+ @command_description
998
+ end
999
+
1000
+ def set_command_description(val)
1001
+ @command_description = val
1002
+ end
1003
+
1004
+ # alias :command_name= :set_command_name
1005
+ # alias :command_description= :set_command_description
1006
+
883
1007
  # construct map of command name => instance method
884
1008
  def register_subcommands(*cmds)
885
1009
  @subcommands ||= {}
@@ -60,10 +60,10 @@ class Morpheus::Cli::Clouds
60
60
  end
61
61
 
62
62
  params.merge!(parse_list_options(options))
63
-
63
+ @clouds_interface.setopts(options)
64
64
  if options[:dry_run]
65
65
  print_dry_run @clouds_interface.dry.get(params)
66
- return
66
+ return 0
67
67
  end
68
68
 
69
69
  json_response = @clouds_interface.get(params)
@@ -113,6 +113,7 @@ class Morpheus::Cli::Clouds
113
113
  begin
114
114
  params = {}
115
115
  params.merge!(parse_list_options(options))
116
+ @clouds_interface.setopts(options)
116
117
  if options[:dry_run]
117
118
  print_dry_run @clouds_interface.dry.get(params)
118
119
  return
@@ -153,6 +154,7 @@ class Morpheus::Cli::Clouds
153
154
  def _get(arg, options={})
154
155
  begin
155
156
  if options[:dry_run]
157
+ @clouds_interface.setopts(options)
156
158
  if arg.to_s =~ /\A\d{1,}\Z/
157
159
  print_dry_run @clouds_interface.dry.get(arg.to_i)
158
160
  else
@@ -166,6 +168,7 @@ class Morpheus::Cli::Clouds
166
168
  # print_dry_run @clouds_interface.dry.get(cloud['id'])
167
169
  # return
168
170
  # end
171
+ @clouds_interface.setopts(options)
169
172
  json_response = @clouds_interface.get(cloud['id'])
170
173
  cloud = json_response['zone']
171
174
  cloud_stats = cloud['stats']
@@ -323,6 +326,7 @@ class Morpheus::Cli::Clouds
323
326
  cloud_payload.deep_merge!(params)
324
327
  payload = {zone: cloud_payload}
325
328
  end
329
+ @clouds_interface.setopts(options)
326
330
  if options[:dry_run]
327
331
  print_dry_run @clouds_interface.dry.create(payload)
328
332
  return
@@ -377,7 +381,7 @@ class Morpheus::Cli::Clouds
377
381
  end
378
382
  else
379
383
  cloud_type = cloud_type_for_id(cloud['zoneTypeId'])
380
- cloud_payload = {id: cloud['id']}
384
+ cloud_payload = {}
381
385
  all_option_types = update_cloud_option_types(cloud_type)
382
386
  #params = Morpheus::Cli::OptionTypes.prompt(all_option_types, options[:options], @api_client, {zoneTypeId: cloud_type['id']})
383
387
  params = options[:options] || {}
@@ -393,7 +397,7 @@ class Morpheus::Cli::Clouds
393
397
  cloud_payload.merge!(params)
394
398
  payload = {zone: cloud_payload}
395
399
  end
396
-
400
+ @clouds_interface.setopts(options)
397
401
  if options[:dry_run]
398
402
  print_dry_run @clouds_interface.dry.update(cloud['id'], payload)
399
403
  return
@@ -433,6 +437,7 @@ class Morpheus::Cli::Clouds
433
437
  unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the cloud #{cloud['name']}?")
434
438
  exit
435
439
  end
440
+ @clouds_interface.setopts(options)
436
441
  json_response = @clouds_interface.destroy(cloud['id'], query_params)
437
442
  if options[:json]
438
443
  print JSON.pretty_generate(json_response)
@@ -462,6 +467,7 @@ class Morpheus::Cli::Clouds
462
467
  connect(options)
463
468
  begin
464
469
  cloud = find_cloud_by_name_or_id(args[0])
470
+ @clouds_interface.setopts(options)
465
471
  if options[:dry_run]
466
472
  print_dry_run @clouds_interface.dry.firewall_disable(cloud['id'])
467
473
  return
@@ -494,6 +500,7 @@ class Morpheus::Cli::Clouds
494
500
  connect(options)
495
501
  begin
496
502
  cloud = find_cloud_by_name_or_id(args[0])
503
+ @clouds_interface.setopts(options)
497
504
  if options[:dry_run]
498
505
  print_dry_run @clouds_interface.dry.firewall_enable(cloud['id'])
499
506
  return
@@ -527,6 +534,7 @@ class Morpheus::Cli::Clouds
527
534
  begin
528
535
  cloud = find_cloud_by_name_or_id(args[0])
529
536
  zone_id = cloud['id']
537
+ @clouds_interface.setopts(options)
530
538
  if options[:dry_run]
531
539
  print_dry_run @clouds_interface.dry.security_groups(zone_id)
532
540
  return
@@ -580,6 +588,7 @@ class Morpheus::Cli::Clouds
580
588
  connect(options)
581
589
  begin
582
590
  cloud = find_cloud_by_name_or_id(args[0])
591
+ @clouds_interface.setopts(options)
583
592
  if options[:dry_run]
584
593
  print_dry_run @clouds_interface.dry.apply_security_groups(cloud['id'])
585
594
  return
@@ -607,9 +616,10 @@ class Morpheus::Cli::Clouds
607
616
  optparse.parse!(args)
608
617
  connect(options)
609
618
  begin
619
+ @clouds_interface.setopts(options)
610
620
  if options[:dry_run]
611
621
  print_dry_run @clouds_interface.dry.cloud_types({})
612
- return
622
+ return 0
613
623
  end
614
624
  cloud_types = get_available_cloud_types() # @clouds_interface.dry.cloud_types({})['zoneTypes']
615
625
  if options[:json]
@@ -1,7 +1,7 @@
1
1
  # A standard error to raise in your CliCommand classes.
2
2
  class Morpheus::Cli::CommandError < StandardError
3
3
 
4
- # attr_reader :args, :options
4
+ attr_reader :args, :exit_code
5
5
 
6
6
  # def initialize(msg, args=[], options={})
7
7
  # @args = args
@@ -9,4 +9,10 @@ class Morpheus::Cli::CommandError < StandardError
9
9
  # super(msg)
10
10
  # end
11
11
 
12
+ def initialize(msg, args=[], exit_code=nil)
13
+ @args = args
14
+ @exit_code = exit_code
15
+ super(msg)
16
+ end
17
+
12
18
  end