morpheus-cli 3.6.8 → 3.6.9

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 (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
data/lib/morpheus/cli.rb CHANGED
@@ -65,20 +65,14 @@ module Morpheus
65
65
  Dir[File.dirname(__FILE__) + "/cli/commands/standard/**/*.rb"].each {|file| load file }
66
66
 
67
67
  # shell scripting commands
68
- load 'morpheus/cli/source_command.rb'
69
- load 'morpheus/cli/echo_command.rb'
70
- load 'morpheus/cli/sleep_command.rb'
71
- load 'morpheus/cli/coloring_command.rb'
72
- load 'morpheus/cli/log_level_command.rb'
73
- load 'morpheus/cli/ssl_verification_command.rb'
74
- load 'morpheus/cli/edit_profile_command.rb'
75
- load 'morpheus/cli/edit_rc_command.rb'
76
68
 
77
69
  # all the known commands
78
70
  load 'morpheus/cli/remote.rb'
79
71
  load 'morpheus/cli/login.rb'
80
72
  load 'morpheus/cli/logout.rb'
81
73
  load 'morpheus/cli/whoami.rb'
74
+ # load 'morpheus/cli/auth_command.rb'
75
+ load 'morpheus/cli/access_token_command.rb'
82
76
  load 'morpheus/cli/user_settings_command.rb'
83
77
  load 'morpheus/cli/dashboard_command.rb'
84
78
  load 'morpheus/cli/power_schedules_command.rb'
@@ -103,9 +97,11 @@ module Morpheus
103
97
  load 'morpheus/cli/instance_types.rb'
104
98
  load 'morpheus/cli/security_groups.rb'
105
99
  load 'morpheus/cli/security_group_rules.rb'
100
+ load 'morpheus/cli/tenants_command.rb'
106
101
  load 'morpheus/cli/accounts.rb'
107
102
  load 'morpheus/cli/account_groups_command.rb'
108
103
  load 'morpheus/cli/users.rb'
104
+ load 'morpheus/cli/change_password_command.rb'
109
105
  load 'morpheus/cli/user_groups_command.rb'
110
106
  load 'morpheus/cli/user_sources_command.rb'
111
107
  load 'morpheus/cli/roles.rb'
@@ -120,14 +116,6 @@ module Morpheus
120
116
  load 'morpheus/cli/library_container_templates_command.rb'
121
117
  load 'morpheus/cli/library_option_types_command.rb'
122
118
  load 'morpheus/cli/library_option_lists_command.rb'
123
- load 'morpheus/cli/packages_command.rb'
124
-
125
- load 'morpheus/cli/version_command.rb'
126
- load 'morpheus/cli/alias_command.rb'
127
- # todo: combine checks, incidents, apps, and goups under monitoring?
128
- # `monitoring apps|groups` still needed,
129
- # maybe they should go under the apps and groups commands instead?
130
- # load 'morpheus/cli/monitoring_command.rb'
131
119
  load 'morpheus/cli/monitoring_incidents_command.rb'
132
120
  load 'morpheus/cli/monitoring_checks_command.rb'
133
121
  load 'morpheus/cli/monitoring_contacts_command.rb'
@@ -142,6 +130,7 @@ module Morpheus
142
130
  load 'morpheus/cli/network_domains_command.rb'
143
131
  load 'morpheus/cli/network_proxies_command.rb'
144
132
  load 'morpheus/cli/cypher_command.rb'
133
+ load 'morpheus/cli/old_cypher_command.rb'
145
134
  load 'morpheus/cli/image_builder_command.rb'
146
135
  load 'morpheus/cli/preseed_scripts_command.rb'
147
136
  load 'morpheus/cli/boot_scripts_command.rb'
@@ -150,12 +139,7 @@ module Morpheus
150
139
  load 'morpheus/cli/execution_request_command.rb'
151
140
  load 'morpheus/cli/file_copy_request_command.rb'
152
141
  load 'morpheus/cli/processes_command.rb'
153
-
154
- # nice to have commands
155
- load 'morpheus/cli/curl_command.rb'
156
- load 'morpheus/cli/set_prompt_command.rb'
157
- load 'morpheus/cli/man_command.rb' # please implement me
158
-
142
+ load 'morpheus/cli/packages_command.rb'
159
143
 
160
144
  # Your new commands go here...
161
145
 
@@ -0,0 +1,172 @@
1
+ require 'morpheus/cli/cli_command'
2
+
3
+ # This provides commands for authentication
4
+ # This also includes credential management.
5
+ class Morpheus::Cli::AccessTokenCommand
6
+ include Morpheus::Cli::CliCommand
7
+
8
+ set_command_name :'access-token'
9
+ #set_command_name :'access'
10
+ register_subcommands :get => :print_access_token
11
+ register_subcommands :details => :details
12
+ register_subcommands :refresh => :use_refresh_token
13
+
14
+ def initialize()
15
+ # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
16
+ end
17
+
18
+ # connect overridden to skip login and return an exit_code
19
+ def connect(options)
20
+ @api_client = establish_remote_appliance_connection(options.merge({:no_prompt => true, :skip_verify_access_token => true}))
21
+ # automatically get @appliance_name, @appliance_url, @wallet
22
+ if !@appliance_name
23
+ unless options[:quiet]
24
+ print yellow,"Please specify a Morpheus Appliance with -r or see the command `remote use`#{reset}\n"
25
+ end
26
+ return 1
27
+ end
28
+ if !@appliance_url
29
+ unless options[:quiet]
30
+ print red,"Unable to determine remote appliance url. Review your remote configuration.#{reset}\n"
31
+ end
32
+ return 1
33
+ end
34
+ #@wallet = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials()
35
+ if @wallet.nil? || @wallet['access_token'].nil?
36
+ unless options[:quiet]
37
+ print_error yellow,"You are not currently logged in to #{display_appliance(@appliance_name, @appliance_url)}",reset,"\n"
38
+ print_error yellow,"Use the 'login' command.",reset,"\n"
39
+ end
40
+ return 1
41
+ end
42
+ end
43
+
44
+ def handle(args)
45
+ if args.empty?
46
+ print_access_token(args)
47
+ else
48
+ handle_subcommand(args)
49
+ end
50
+ end
51
+
52
+ def details(args)
53
+ options = {}
54
+ params = {}
55
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
56
+ opts.banner = subcommand_usage()
57
+ build_common_options(opts, options, [:remote, :quiet])
58
+ opts.footer = "Print your current authentication credentials.\n" +
59
+ "This contains tokens that should be kept secret, be careful."
60
+ end
61
+ optparse.parse!(args)
62
+ if args.count != 0
63
+ raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
64
+ end
65
+ connect_result = connect(options)
66
+ return connect_result if (connect_result.is_a?(Numeric) && connect_result != 0)
67
+
68
+ # could fetch and show whoami info as well eh?
69
+ # extra api call though..
70
+
71
+ #print_h1 "Morpheus Credentials", [display_appliance(@appliance_name, @appliance_url)], options
72
+ print_h1 "Morpheus Credentials", options
73
+ description_cols = {
74
+ "Username" => lambda {|wallet| wallet['username'] },
75
+ "Remote" => lambda {|wallet| "#{display_appliance(@appliance_name, @appliance_url)}" },
76
+ "Access Token" => lambda {|wallet| wallet['access_token'] },
77
+ "Refresh Token" => lambda {|wallet| wallet['refresh_token'] },
78
+ "Login Date" => lambda {|wallet| format_local_dt(wallet['login_date']) },
79
+ "Expire Date" => lambda {|wallet| wallet['expire_date'] ? format_local_dt(wallet['expire_date']) : "" },
80
+ }
81
+ print cyan
82
+ puts as_description_list(@wallet, description_cols)
83
+ print reset
84
+ return 0
85
+ end
86
+
87
+ def print_access_token(args)
88
+ options = {}
89
+ params = {}
90
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
91
+ opts.banner = subcommand_usage()
92
+ build_common_options(opts, options, [:remote, :quiet])
93
+ opts.footer = "Print your current access token.\n" +
94
+ "This token should be kept secret. Be careful."
95
+ end
96
+ optparse.parse!(args)
97
+ if args.count != 0
98
+ raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
99
+ end
100
+ connect_result = connect(options)
101
+ return connect_result if (connect_result.is_a?(Numeric) && connect_result != 0)
102
+ unless options[:quiet]
103
+ print cyan
104
+ puts @wallet['access_token']
105
+ print reset
106
+ end
107
+ return @wallet['access_token'] ? 0 : 1
108
+ end
109
+
110
+ def use_refresh_token(args)
111
+ options = {}
112
+ params = {}
113
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
114
+ opts.banner = subcommand_usage()
115
+ build_common_options(opts, options, [:auto_confirm, :remote, :dry_run, :json, :quiet])
116
+ opts.footer = "Use your refresh token.\n" +
117
+ "This will replace your current access and refresh tokens with a new values.\n" +
118
+ "Your current access token will be invalidated\n" +
119
+ "All other users or applications with access to your token will need to update to the new token."
120
+ end
121
+ optparse.parse!(args)
122
+ if args.count != 0
123
+ raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
124
+ end
125
+
126
+ connect(options)
127
+
128
+ if options[:dry_run]
129
+ auth_interface = Morpheus::AuthInterface.new(@appliance_url)
130
+ print_dry_run auth_interface.dry.use_refresh_token(@wallet['refresh_token'])
131
+ return 0
132
+ end
133
+ unless options[:quiet]
134
+ access_token = @wallet['access_token'].to_s
135
+ visible_part = access_token[0..7]
136
+ if visible_part
137
+ masked_access_token = visible_part + access_token[8..-1].gsub(/[^-]/, '*')
138
+ else
139
+ masked_access_token = access_token.gsub(/[^-]/, '*')
140
+ end
141
+ print cyan,"#{bold}WARNING!#{reset}#{cyan} You are about to invalidate your current access token '#{masked_access_token}'.",reset,"\n"
142
+ print cyan, "You will need to update everywhere this token is used.",reset, "\n"
143
+ end
144
+
145
+ unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to refresh your access token?")
146
+ return 9, "aborted command"
147
+ end
148
+
149
+ # ok, let's use our refresh token
150
+ # this regenerates the current access token.
151
+ refresh_result = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).use_refresh_token(options)
152
+ new_wallet = refresh_result
153
+ if options[:json]
154
+ puts as_json(refresh_result, options)
155
+ return new_wallet ? 0 : 1
156
+ end
157
+ if new_wallet
158
+ unless options[:quiet]
159
+ print_green_success "Access token refreshed: #{new_wallet['access_token']}"
160
+ #print_green_success "Access token refreshed"
161
+ details([])
162
+ end
163
+ return 0
164
+ else
165
+ print_red_alert "Failed to use refresh token."
166
+ return 1
167
+ end
168
+ end
169
+
170
+ protected
171
+
172
+ end
@@ -10,6 +10,10 @@ require 'json'
10
10
  class Morpheus::Cli::Accounts
11
11
  include Morpheus::Cli::CliCommand
12
12
  include Morpheus::Cli::AccountsHelper
13
+
14
+ # deprecated and replaced with tenants, remove soon
15
+ set_command_hidden
16
+
13
17
  register_subcommands :list, :count, :get, :add, :update, :remove
14
18
  alias_subcommand :details, :get
15
19
  set_default_subcommand :list
@@ -29,6 +33,7 @@ class Morpheus::Cli::Accounts
29
33
  end
30
34
 
31
35
  def handle(args)
36
+ print_error "#{yellow}DEPRECATION WARNING: `morpheus accounts` has been replaced with `morpheus tenants`. Please use `tenants` instead.#{reset}\n"
32
37
  handle_subcommand(args)
33
38
  end
34
39
 
@@ -5,14 +5,17 @@ require 'optparse'
5
5
  require 'filesize'
6
6
  require 'table_print'
7
7
  require 'morpheus/cli/cli_command'
8
+ require 'morpheus/cli/mixins/accounts_helper'
8
9
  require 'morpheus/cli/mixins/provisioning_helper'
9
10
  require 'morpheus/cli/mixins/processes_helper'
10
11
 
11
12
  class Morpheus::Cli::Apps
12
13
  include Morpheus::Cli::CliCommand
14
+ include Morpheus::Cli::AccountsHelper
13
15
  include Morpheus::Cli::ProvisioningHelper
14
16
  include Morpheus::Cli::ProcessesHelper
15
-
17
+ set_command_name :apps
18
+ set_command_description "View and manage apps."
16
19
  register_subcommands :list, :get, :add, :update, :remove, :add_instance, :remove_instance, :logs, :firewall_disable, :firewall_enable, :security_groups, :apply_security_groups, :history
17
20
  register_subcommands :stop, :start, :restart
18
21
  #register_subcommands :validate # add --validate instead
@@ -25,6 +28,8 @@ class Morpheus::Cli::Apps
25
28
 
26
29
  def connect(opts)
27
30
  @api_client = establish_remote_appliance_connection(opts)
31
+ @accounts_interface = @api_client.accounts
32
+ @users_interface = @api_client.users
28
33
  @apps_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).apps
29
34
  @blueprints_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).blueprints
30
35
  @instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
@@ -44,6 +49,9 @@ class Morpheus::Cli::Apps
44
49
  options = {}
45
50
  optparse = Morpheus::Cli::OptionParser.new do |opts|
46
51
  opts.banner = subcommand_usage()
52
+ opts.on( '--created-by USER', "Created By User Username or ID" ) do |val|
53
+ options[:created_by] = val
54
+ end
47
55
  build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
48
56
  opts.footer = "List apps."
49
57
  end
@@ -57,7 +65,13 @@ class Morpheus::Cli::Apps
57
65
  begin
58
66
  params = {}
59
67
  params.merge!(parse_list_options(options))
60
-
68
+ account = nil
69
+ if options[:created_by]
70
+ created_by_ids = find_all_user_ids(account ? account['id'] : nil, options[:created_by])
71
+ return if created_by_ids.nil?
72
+ params['createdBy'] = created_by_ids
73
+ end
74
+ @apps_interface.setopts(options)
61
75
  if options[:dry_run]
62
76
  print_dry_run @apps_interface.dry.get(params)
63
77
  return
@@ -65,19 +79,25 @@ class Morpheus::Cli::Apps
65
79
 
66
80
  json_response = @apps_interface.get(params)
67
81
  if options[:json]
68
- print JSON.pretty_generate(json_response)
69
- print "\n"
70
- return
82
+ puts as_json(json_response, options, "apps")
83
+ return 0
84
+ elsif options[:yaml]
85
+ puts as_yaml(json_response, options, "apps")
86
+ return 0
87
+ elsif options[:csv]
88
+ puts records_as_csv(json_response['apps'], options)
89
+ return 0
71
90
  end
91
+
72
92
  apps = json_response['apps']
73
93
  title = "Morpheus Apps"
74
94
  subtitles = []
75
95
  subtitles += parse_list_subtitles(options)
76
- print_h1 title, subtitles
96
+ print_h1 title, subtitles, options
77
97
  if apps.empty?
78
98
  print cyan,"No apps found.",reset,"\n"
79
99
  else
80
- print_apps_table(apps)
100
+ print_apps_table(apps, options)
81
101
  print_results_pagination(json_response)
82
102
  end
83
103
  print reset,"\n"
@@ -320,7 +340,8 @@ class Morpheus::Cli::Apps
320
340
 
321
341
  #instance_prompt_options[:name_required] = true
322
342
  instance_prompt_options[:instance_type_code] = instance_type_code
323
-
343
+ # todo: an effort to render more useful help eg. -O Web.0.instance.name
344
+ instance_prompt_options[:extra_field_context] = "#{tier_name}.#{instance_index}"
324
345
  # this provisioning helper method handles all (most) of the parsing and prompting
325
346
  instance_config_payload = prompt_new_instance(instance_prompt_options)
326
347
 
@@ -358,7 +379,8 @@ class Morpheus::Cli::Apps
358
379
  end
359
380
  end
360
381
 
361
-
382
+ @apps_interface.setopts(options)
383
+
362
384
  # Validate Only
363
385
  if options[:validate_only] == true
364
386
  # Validate Only Dry run
@@ -410,15 +432,9 @@ class Morpheus::Cli::Apps
410
432
  end
411
433
  end
412
434
 
413
- # Dry Run?
435
+ @apps_interface.setopts(options)
414
436
  if options[:dry_run]
415
- if options[:json]
416
- puts as_json(payload, options)
417
- elsif options[:yaml]
418
- puts as_yaml(payload, options)
419
- else
420
- print_dry_run @apps_interface.dry.create(payload)
421
- end
437
+ print_dry_run @apps_interface.dry.create(payload)
422
438
  return 0
423
439
  end
424
440
 
@@ -489,6 +505,7 @@ class Morpheus::Cli::Apps
489
505
  def _get(arg, options={})
490
506
  begin
491
507
  app = find_app_by_name_or_id(arg)
508
+ @apps_interface.setopts(options)
492
509
  if options[:dry_run]
493
510
  print_dry_run @apps_interface.dry.get(app['id'])
494
511
  return
@@ -499,7 +516,8 @@ class Morpheus::Cli::Apps
499
516
  return 0 if render_result
500
517
 
501
518
  app = json_response['app']
502
- print_h1 "App Details"
519
+ app_tiers = app['appTiers']
520
+ print_h1 "App Details", [], options
503
521
  print cyan
504
522
  description_cols = {
505
523
  "ID" => 'id',
@@ -508,6 +526,35 @@ class Morpheus::Cli::Apps
508
526
  "Blueprint" => lambda {|it| it['blueprint'] ? it['blueprint']['name'] : '' },
509
527
  "Group" => lambda {|it| it['group'] ? it['group']['name'] : it['siteId'] },
510
528
  "Account" => lambda {|it| it['account'] ? it['account']['name'] : '' },
529
+ "Tiers" => lambda {|it|
530
+ # it['instanceCount']
531
+ tiers = []
532
+ app_tiers = it['appTiers'] || []
533
+ app_tiers.each do |app_tier|
534
+ tiers << app_tier['tier']
535
+ end
536
+ "#{tiers.collect {|it| it.is_a?(Hash) ? it['name'] : it }.join(',')}"
537
+ },
538
+ "Instances" => lambda {|it|
539
+ # it['instanceCount']
540
+ instances = []
541
+ app_tiers = it['appTiers'] || []
542
+ app_tiers.each do |app_tier|
543
+ instances += (app_tier['appInstances'] || []).collect {|it| it['instance']}.flatten().compact
544
+ end
545
+ #"(#{instances.count})"
546
+ "(#{instances.count}) #{instances.collect {|it| it['name'] }.join(',')}"
547
+ },
548
+ "Containers" => lambda {|it|
549
+ #it['containerCount']
550
+ containers = []
551
+ app_tiers = it['appTiers'] || []
552
+ app_tiers.each do |app_tier|
553
+ containers += (app_tier['appInstances'] || []).collect {|it| it['instance']['containers']}.flatten().compact
554
+ end
555
+ #"(#{containers.count})"
556
+ "(#{containers.count}) #{containers.collect {|it| it }.join(',')}"
557
+ },
511
558
  "Status" => lambda {|it| format_app_status(it) }
512
559
  }
513
560
  if app['blueprint'].nil?
@@ -520,16 +567,16 @@ class Morpheus::Cli::Apps
520
567
 
521
568
  stats = app['stats']
522
569
  if app['instanceCount'].to_i > 0
523
- print_h2 "App Usage"
570
+ print_h2 "App Usage", options
524
571
  print_stats_usage(stats, {include: [:memory, :storage]})
525
572
  end
526
573
 
527
- app_tiers = app['appTiers']
528
574
  if app_tiers.empty?
529
575
  puts yellow, "This app is empty", reset
530
576
  else
531
577
  app_tiers.each do |app_tier|
532
- print_h2 "Tier: #{app_tier['tier']['name']}"
578
+ # print_h2 "Tier: #{app_tier['tier']['name']}", options
579
+ print_h2 "#{app_tier['tier']['name']}", options
533
580
  print cyan
534
581
  instances = (app_tier['appInstances'] || []).collect {|it| it['instance']}
535
582
  if instances.empty?
@@ -557,7 +604,7 @@ class Morpheus::Cli::Apps
557
604
  end
558
605
  instances_rows = instances_rows.sort {|x,y| x[:id] <=> y[:id] } #oldest to newest..
559
606
  print cyan
560
- print as_pretty_table(instances_rows, [:id, :name, :cloud, :type, :environment, :nodes, :connection, :status])
607
+ print as_pretty_table(instances_rows, [:id, :name, :cloud, :type, :environment, :nodes, :connection, :status], {border_style: options[:border_style]})
561
608
  print reset
562
609
  print "\n"
563
610
  end
@@ -653,7 +700,7 @@ class Morpheus::Cli::Apps
653
700
  payload['group'] = payload['app']['group']
654
701
  end
655
702
  end
656
-
703
+ @apps_interface.setopts(options)
657
704
  if options[:dry_run]
658
705
  print_dry_run @apps_interface.dry.update(app["id"], payload)
659
706
  return
@@ -722,7 +769,7 @@ class Morpheus::Cli::Apps
722
769
  v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'tier', 'fieldLabel' => 'Tier', 'type' => 'text', 'required' => true, 'description' => 'Enter the name of the tier'}], options[:options])
723
770
  payload[:tierName] = v_prompt['tier']
724
771
  end
725
-
772
+ @apps_interface.setopts(options)
726
773
  if options[:dry_run]
727
774
  print_dry_run @apps_interface.dry.add_instance(app['id'], payload)
728
775
  return
@@ -754,7 +801,7 @@ class Morpheus::Cli::Apps
754
801
  opts.on('--preserve-volumes [on|off]', ['on','off'], "Preserve Volumes. Default is off. Applies to certain types only.") do |val|
755
802
  query_params[:preserveVolumes] = val.nil? ? 'on' : val
756
803
  end
757
- opts.on( '-B', '--keep-backups', "Preserve copy of backups" ) do
804
+ opts.on( '--keep-backups', '--keep-backups', "Preserve copy of backups" ) do
758
805
  query_params[:keepBackups] = 'on'
759
806
  end
760
807
  opts.on('--releaseEIPs [on|off]', ['on','off'], "Release EIPs. Default is on. Applies to Amazon only.") do |val|
@@ -784,6 +831,7 @@ class Morpheus::Cli::Apps
784
831
  if query_params[:preserveVolumes].nil?
785
832
  query_params[:removeVolumes] = 'on'
786
833
  end
834
+ @apps_interface.setopts(options)
787
835
  if options[:dry_run]
788
836
  print_dry_run @apps_interface.dry.destroy(app['id'], query_params)
789
837
  return
@@ -834,7 +882,7 @@ class Morpheus::Cli::Apps
834
882
  instance = find_instance_by_name_or_id(v_prompt['instance'])
835
883
  end
836
884
  payload[:instanceId] = instance['id']
837
-
885
+ @apps_interface.setopts(options)
838
886
  if options[:dry_run]
839
887
  print_dry_run @apps_interface.dry.remove_instance(app['id'], payload)
840
888
  return
@@ -886,6 +934,7 @@ class Morpheus::Cli::Apps
886
934
  params[k] = options[k] unless options[k].nil?
887
935
  end
888
936
  params[:query] = params.delete(:phrase) unless params[:phrase].nil?
937
+ @apps_interface.setopts(options)
889
938
  if options[:dry_run]
890
939
  print_dry_run @logs_interface.dry.container_logs(containers, params)
891
940
  return
@@ -901,7 +950,7 @@ class Morpheus::Cli::Apps
901
950
  subtitles << "Search: #{params[:query]}".strip
902
951
  end
903
952
  # todo: startMs, endMs, sorts insteaad of sort..etc
904
- print_h1 title, subtitles
953
+ print_h1 title, subtitles, options
905
954
  logs['data'].reverse.each do |log_entry|
906
955
  log_level = ''
907
956
  case log_entry['level']
@@ -956,7 +1005,7 @@ class Morpheus::Cli::Apps
956
1005
  return 1 if app.nil?
957
1006
  tier_records = extract_app_tiers(app)
958
1007
  if options[:dry_run]
959
- print_h1 "Dry Run"
1008
+ print_h1 "Dry Run", [], options
960
1009
  end
961
1010
  tier_records.each do |tier_record|
962
1011
  tier_record[:instances].each do |instance|
@@ -1000,7 +1049,7 @@ class Morpheus::Cli::Apps
1000
1049
  return 1 if app.nil?
1001
1050
  tier_records = extract_app_tiers(app)
1002
1051
  if options[:dry_run]
1003
- print_h1 "Dry Run"
1052
+ print_h1 "Dry Run", [], options
1004
1053
  end
1005
1054
  tier_records.each do |tier_record|
1006
1055
  tier_record[:instances].each do |instance|
@@ -1044,7 +1093,7 @@ class Morpheus::Cli::Apps
1044
1093
  return 1 if app.nil?
1045
1094
  tier_records = extract_app_tiers(app)
1046
1095
  if options[:dry_run]
1047
- print_h1 "Dry Run"
1096
+ print_h1 "Dry Run", [], options
1048
1097
  end
1049
1098
  tier_records.each do |tier_record|
1050
1099
  tier_record[:instances].each do |instance|
@@ -1075,6 +1124,7 @@ class Morpheus::Cli::Apps
1075
1124
 
1076
1125
  begin
1077
1126
  app = find_app_by_name_or_id(args[0])
1127
+ @apps_interface.setopts(options)
1078
1128
  if options[:dry_run]
1079
1129
  print_dry_run @apps_interface.dry.firewall_disable(app['id'])
1080
1130
  return
@@ -1103,6 +1153,7 @@ class Morpheus::Cli::Apps
1103
1153
 
1104
1154
  begin
1105
1155
  app = find_app_by_name_or_id(args[0])
1156
+ @apps_interface.setopts(options)
1106
1157
  if options[:dry_run]
1107
1158
  print_dry_run @apps_interface.dry.firewall_enable(app['id'])
1108
1159
  return
@@ -1131,13 +1182,14 @@ class Morpheus::Cli::Apps
1131
1182
 
1132
1183
  begin
1133
1184
  app = find_app_by_name_or_id(args[0])
1185
+ @apps_interface.setopts(options)
1134
1186
  if options[:dry_run]
1135
1187
  print_dry_run @apps_interface.dry.security_groups(app['id'])
1136
1188
  return
1137
1189
  end
1138
1190
  json_response = @apps_interface.security_groups(app['id'])
1139
1191
  securityGroups = json_response['securityGroups']
1140
- print_h1 "Morpheus Security Groups for App: #{app['name']}"
1192
+ print_h1 "Morpheus Security Groups for App: #{app['name']}", options
1141
1193
  print cyan
1142
1194
  print_description_list({"Firewall Enabled" => lambda {|it| format_boolean it['firewallEnabled'] } }, json_response)
1143
1195
  if securityGroups.empty?
@@ -1158,18 +1210,19 @@ class Morpheus::Cli::Apps
1158
1210
 
1159
1211
  def apply_security_groups(args)
1160
1212
  options = {}
1213
+ params = {}
1161
1214
  clear_or_secgroups_specified = false
1162
1215
  optparse = Morpheus::Cli::OptionParser.new do |opts|
1163
1216
  opts.banner = subcommand_usage("[app] [--clear] [-s]")
1164
1217
  opts.on( '-c', '--clear', "Clear all security groups" ) do
1165
- options[:securityGroupIds] = []
1218
+ params[:securityGroupIds] = []
1166
1219
  clear_or_secgroups_specified = true
1167
1220
  end
1168
1221
  opts.on( '-s', '--secgroups SECGROUPS', "Apply the specified comma separated security group ids" ) do |secgroups|
1169
- options[:securityGroupIds] = secgroups.split(",")
1222
+ params[:securityGroupIds] = secgroups.split(",")
1170
1223
  clear_or_secgroups_specified = true
1171
1224
  end
1172
- opts.on( '-h', '--help', "Prints this help" ) do
1225
+ opts.on( '-h', '--help', "Print this help" ) do
1173
1226
  puts opts
1174
1227
  exit
1175
1228
  end
@@ -1191,11 +1244,13 @@ class Morpheus::Cli::Apps
1191
1244
 
1192
1245
  begin
1193
1246
  app = find_app_by_name_or_id(args[0])
1247
+ payload = params
1248
+ @apps_interface.setopts(options)
1194
1249
  if options[:dry_run]
1195
- print_dry_run @apps_interface.dry.apply_security_groups(app['id'], options)
1250
+ print_dry_run @apps_interface.dry.apply_security_groups(app['id'], payload)
1196
1251
  return
1197
1252
  end
1198
- @apps_interface.apply_security_groups(app['id'], options)
1253
+ @apps_interface.apply_security_groups(app['id'], payloaad)
1199
1254
  security_groups([args[0]])
1200
1255
  rescue RestClient::Exception => e
1201
1256
  print_rest_exception(e, options)
@@ -1247,6 +1302,7 @@ class Morpheus::Cli::Apps
1247
1302
  params['instanceIds'] = instance_ids
1248
1303
  params.merge!(parse_list_options(options))
1249
1304
  # params[:query] = params.delete(:phrase) unless params[:phrase].nil?
1305
+ @processes_interface.setopts(options)
1250
1306
  if options[:dry_run]
1251
1307
  print_dry_run @processes_interface.dry.list(params)
1252
1308
  return
@@ -1269,7 +1325,7 @@ class Morpheus::Cli::Apps
1269
1325
  subtitles << "Search: #{params[:query]}".strip
1270
1326
  end
1271
1327
  subtitles += parse_list_subtitles(options)
1272
- print_h1 title, subtitles
1328
+ print_h1 title, subtitles, options
1273
1329
  if json_response['processes'].empty?
1274
1330
  print "#{cyan}No process history found.#{reset}\n\n"
1275
1331
  else