morpheus-cli 4.1.8 → 4.1.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 (72) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/api_client.rb +24 -0
  4. data/lib/morpheus/api/{old_cypher_interface.rb → budgets_interface.rb} +10 -11
  5. data/lib/morpheus/api/cloud_datastores_interface.rb +7 -0
  6. data/lib/morpheus/api/cloud_resource_pools_interface.rb +2 -2
  7. data/lib/morpheus/api/cypher_interface.rb +18 -12
  8. data/lib/morpheus/api/health_interface.rb +72 -0
  9. data/lib/morpheus/api/instances_interface.rb +1 -1
  10. data/lib/morpheus/api/library_instance_types_interface.rb +7 -0
  11. data/lib/morpheus/api/log_settings_interface.rb +6 -0
  12. data/lib/morpheus/api/network_security_servers_interface.rb +30 -0
  13. data/lib/morpheus/api/price_sets_interface.rb +42 -0
  14. data/lib/morpheus/api/prices_interface.rb +68 -0
  15. data/lib/morpheus/api/provisioning_settings_interface.rb +29 -0
  16. data/lib/morpheus/api/servers_interface.rb +1 -1
  17. data/lib/morpheus/api/service_plans_interface.rb +34 -11
  18. data/lib/morpheus/api/task_sets_interface.rb +8 -0
  19. data/lib/morpheus/api/tasks_interface.rb +8 -0
  20. data/lib/morpheus/cli.rb +6 -3
  21. data/lib/morpheus/cli/appliance_settings_command.rb +13 -5
  22. data/lib/morpheus/cli/approvals_command.rb +1 -1
  23. data/lib/morpheus/cli/apps.rb +88 -28
  24. data/lib/morpheus/cli/backup_settings_command.rb +1 -1
  25. data/lib/morpheus/cli/blueprints_command.rb +2 -0
  26. data/lib/morpheus/cli/budgets_command.rb +672 -0
  27. data/lib/morpheus/cli/cli_command.rb +13 -2
  28. data/lib/morpheus/cli/cli_registry.rb +1 -0
  29. data/lib/morpheus/cli/clusters.rb +40 -274
  30. data/lib/morpheus/cli/commands/standard/benchmark_command.rb +114 -66
  31. data/lib/morpheus/cli/commands/standard/coloring_command.rb +12 -0
  32. data/lib/morpheus/cli/commands/standard/curl_command.rb +31 -6
  33. data/lib/morpheus/cli/commands/standard/echo_command.rb +8 -3
  34. data/lib/morpheus/cli/commands/standard/set_prompt_command.rb +1 -1
  35. data/lib/morpheus/cli/containers_command.rb +37 -24
  36. data/lib/morpheus/cli/cypher_command.rb +191 -150
  37. data/lib/morpheus/cli/health_command.rb +903 -0
  38. data/lib/morpheus/cli/hosts.rb +43 -32
  39. data/lib/morpheus/cli/instances.rb +119 -68
  40. data/lib/morpheus/cli/jobs_command.rb +1 -1
  41. data/lib/morpheus/cli/library_instance_types_command.rb +61 -11
  42. data/lib/morpheus/cli/library_option_types_command.rb +2 -2
  43. data/lib/morpheus/cli/log_settings_command.rb +46 -3
  44. data/lib/morpheus/cli/logs_command.rb +24 -17
  45. data/lib/morpheus/cli/mixins/accounts_helper.rb +2 -0
  46. data/lib/morpheus/cli/mixins/logs_helper.rb +73 -19
  47. data/lib/morpheus/cli/mixins/print_helper.rb +29 -1
  48. data/lib/morpheus/cli/mixins/provisioning_helper.rb +554 -96
  49. data/lib/morpheus/cli/mixins/whoami_helper.rb +13 -1
  50. data/lib/morpheus/cli/networks_command.rb +3 -0
  51. data/lib/morpheus/cli/option_types.rb +83 -53
  52. data/lib/morpheus/cli/price_sets_command.rb +543 -0
  53. data/lib/morpheus/cli/prices_command.rb +669 -0
  54. data/lib/morpheus/cli/processes_command.rb +0 -2
  55. data/lib/morpheus/cli/provisioning_settings_command.rb +237 -0
  56. data/lib/morpheus/cli/remote.rb +9 -4
  57. data/lib/morpheus/cli/reports_command.rb +10 -4
  58. data/lib/morpheus/cli/roles.rb +93 -38
  59. data/lib/morpheus/cli/security_groups.rb +10 -0
  60. data/lib/morpheus/cli/service_plans_command.rb +736 -0
  61. data/lib/morpheus/cli/tasks.rb +220 -8
  62. data/lib/morpheus/cli/tenants_command.rb +3 -16
  63. data/lib/morpheus/cli/users.rb +2 -25
  64. data/lib/morpheus/cli/version.rb +1 -1
  65. data/lib/morpheus/cli/whitelabel_settings_command.rb +18 -18
  66. data/lib/morpheus/cli/whoami.rb +28 -10
  67. data/lib/morpheus/cli/workflows.rb +488 -36
  68. data/lib/morpheus/formatters.rb +22 -0
  69. data/morpheus-cli.gemspec +1 -0
  70. metadata +28 -5
  71. data/lib/morpheus/cli/accounts.rb +0 -335
  72. data/lib/morpheus/cli/old_cypher_command.rb +0 -412
@@ -1,412 +0,0 @@
1
- require 'json'
2
- require 'morpheus/cli/cli_command'
3
-
4
- class Morpheus::Cli::OldCypherCommand
5
- include Morpheus::Cli::CliCommand
6
-
7
- # being deprecated in favor of VaultCypherCommand
8
- set_command_name :'old-cypher'
9
- set_command_hidden
10
-
11
- register_subcommands :list, :get, :add, :remove, :decrypt
12
-
13
- def initialize()
14
- # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
15
- end
16
-
17
- def connect(opts)
18
- @api_client = establish_remote_appliance_connection(opts)
19
- @cypher_interface = @api_client.old_cypher
20
- end
21
-
22
- def handle(args)
23
- handle_subcommand(args)
24
- end
25
-
26
- def list(args)
27
- options = {}
28
- params = {}
29
- optparse = Morpheus::Cli::OptionParser.new do |opts|
30
- opts.banner = subcommand_usage()
31
- build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
32
- opts.footer = "List cypher items."
33
- end
34
- optparse.parse!(args)
35
- connect(options)
36
- begin
37
- params.merge!(parse_list_options(options))
38
- if options[:dry_run]
39
- print_dry_run @cypher_interface.dry.list(params)
40
- return 0
41
- end
42
- json_response = @cypher_interface.list(params)
43
- cypher_items = json_response["cyphers"]
44
- if options[:json]
45
- puts as_json(json_response, options, "cyphers")
46
- return 0
47
- elsif options[:yaml]
48
- puts as_yaml(json_response, options, "cyphers")
49
- return 0
50
- elsif options[:csv]
51
- puts records_as_csv(cypher_items, options)
52
- return 0
53
- end
54
- title = "Morpheus Cypher List"
55
- subtitles = []
56
- subtitles += parse_list_subtitles(options)
57
- print_h1 title, subtitles
58
- if cypher_items.empty?
59
- print cyan,"No cypher items found.",reset,"\n"
60
- else
61
- cypher_columns = {
62
- "ID" => 'id',
63
- "KEY" => lambda {|it| it["itemKey"] || it["key"] },
64
- "LEASE REMAINING" => lambda {|it| it['expireDate'] ? format_local_dt(it['expireDate']) : "" },
65
- "DATE CREATED" => lambda {|it| format_local_dt(it["dateCreated"]) },
66
- "LAST ACCESSED" => lambda {|it| format_local_dt(it["lastAccessed"]) }
67
- }
68
- if options[:include_fields]
69
- cypher_columns = options[:include_fields]
70
- end
71
- print cyan
72
- print as_pretty_table(cypher_items, cypher_columns, options)
73
- print reset
74
- print_results_pagination(json_response)
75
- end
76
- print reset,"\n"
77
- return 0
78
- rescue RestClient::Exception => e
79
- print_rest_exception(e, options)
80
- exit 1
81
- end
82
- end
83
-
84
- def get(args)
85
- options = {}
86
- do_decrypt = false
87
- optparse = Morpheus::Cli::OptionParser.new do |opts|
88
- opts.banner = subcommand_usage("[id]")
89
- opts.on(nil, '--decrypt', 'Display the decrypted value') do
90
- do_decrypt = true
91
- end
92
- build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
93
- opts.footer = "Get details about a cypher." + "\n" +
94
- "[id] is required. This is the id or key of a cypher."
95
- end
96
- optparse.parse!(args)
97
- if args.count != 1
98
- print_error Morpheus::Terminal.angry_prompt
99
- puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
100
- return 1
101
- end
102
- connect(options)
103
- begin
104
- if options[:dry_run]
105
- if args[0].to_s =~ /\A\d{1,}\Z/
106
- print_dry_run @cypher_interface.dry.get(args[0].to_i)
107
- else
108
- print_dry_run @cypher_interface.dry.list({name:args[0]})
109
- end
110
- return
111
- end
112
- cypher_item = find_cypher_by_name_or_id(args[0])
113
- return 1 if cypher_item.nil?
114
- json_response = {'cypher' => cypher_item} # skip redundant request
115
- decrypt_json_response = nil
116
- if do_decrypt
117
- decrypt_json_response = @cypher_interface.decrypt(cypher_item["id"])
118
- end
119
- # json_response = @cypher_interface.get(cypher_item['id'])
120
- cypher_item = json_response['cypher']
121
- if options[:json]
122
- puts as_json(json_response, options, "cypher")
123
- return 0
124
- elsif options[:yaml]
125
- puts as_yaml(json_response, options, "cypher")
126
- return 0
127
- elsif options[:csv]
128
- puts records_as_csv([cypher_item], options)
129
- return 0
130
- end
131
- print_h1 "Cypher Details"
132
- print cyan
133
- description_cols = {
134
- "ID" => 'id',
135
- # what here
136
- "Key" => lambda {|it| it["itemKey"] },
137
- #"Value" => lambda {|it| it["value"] || "************" },
138
- "Lease Remaining" => lambda {|it| format_local_dt(it["expireDate"]) },
139
- "Date Created" => lambda {|it| format_local_dt(it["dateCreated"]) },
140
- "Last Accessed" => lambda {|it| format_local_dt(it["lastAccessed"]) }
141
- }
142
- print_description_list(description_cols, cypher_item)
143
- if decrypt_json_response
144
- print_h2 "Decrypted Value"
145
- print cyan
146
- puts decrypt_json_response["cypher"] ? decrypt_json_response["cypher"]["itemValue"] : ""
147
- end
148
- print reset, "\n"
149
-
150
- return 0
151
- rescue RestClient::Exception => e
152
- print_rest_exception(e, options)
153
- return 1
154
- end
155
- end
156
-
157
- def decrypt(args)
158
- params = {}
159
- options = {}
160
- optparse = Morpheus::Cli::OptionParser.new do |opts|
161
- opts.banner = subcommand_usage("[id]")
162
- build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
163
- opts.footer = "Decrypt the value of a cypher." + "\n" +
164
- "[id] is required. This is the id or key of a cypher."
165
- end
166
- optparse.parse!(args)
167
- if args.count != 1
168
- print_error Morpheus::Terminal.angry_prompt
169
- puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
170
- return 1
171
- end
172
- connect(options)
173
- begin
174
- cypher_item = find_cypher_by_name_or_id(args[0])
175
- return 1 if cypher_item.nil?
176
- if options[:dry_run]
177
- print_dry_run @cypher_interface.dry.decrypt(cypher_item["id"], params)
178
- return
179
- end
180
-
181
- cypher_item = find_cypher_by_name_or_id(args[0])
182
- return 1 if cypher_item.nil?
183
-
184
- json_response = @cypher_interface.decrypt(cypher_item["id"], params)
185
- if options[:json]
186
- puts as_json(json_response, options, "cypher")
187
- return 0
188
- elsif options[:yaml]
189
- puts as_yaml(json_response, options, "cypher")
190
- return 0
191
- elsif options[:csv]
192
- puts records_as_csv([json_response["crypt"]], options)
193
- return 0
194
- end
195
- print_h1 "Cypher Decrypt"
196
- print cyan
197
- print_description_list({
198
- "ID" => 'id',
199
- "Key" => lambda {|it| it["itemKey"] },
200
- "Value" => lambda {|it| it["itemValue"] }
201
- }, json_response["cypher"])
202
- print reset, "\n"
203
- return 0
204
- rescue RestClient::Exception => e
205
- print_rest_exception(e, options)
206
- return 1
207
- end
208
- end
209
-
210
- def add(args)
211
- options = {}
212
- params = {}
213
-
214
- optparse = Morpheus::Cli::OptionParser.new do |opts|
215
- opts.banner = subcommand_usage()
216
- opts.on('--key VALUE', String, "Key for this cypher") do |val|
217
- params['itemKey'] = val
218
- end
219
- build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
220
- opts.footer = "Create a new cypher."
221
- end
222
- optparse.parse!(args)
223
- if args.count > 1
224
- print_error Morpheus::Terminal.angry_prompt
225
- puts_error "wrong number of arguments, expected 0-1 and got #{args.count}\n#{optparse}"
226
- return 1
227
- end
228
- connect(options)
229
- begin
230
- payload = nil
231
- if options[:payload]
232
- payload = options[:payload]
233
- else
234
- # merge -O options into normally parsed options
235
- params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options] && options[:options].keys.size > 0
236
-
237
- # support [key] as first argument
238
- if args[0]
239
- params['itemKey'] = args[0]
240
- end
241
- # Key
242
- if !params['itemKey']
243
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'itemKey', 'fieldLabel' => 'Key', 'type' => 'text', 'required' => true, 'description' => cypher_key_help}], options)
244
- params['itemKey'] = v_prompt['itemKey']
245
- end
246
-
247
- # Value
248
- value_is_required = false
249
- cypher_mount_type = params['itemKey'].split("/").first
250
- if ["secret", "password"].include?(cypher_mount_type)
251
- value_is_required = true
252
- end
253
-
254
- if !params['itemValue']
255
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'itemValue', 'fieldLabel' => 'Value', 'type' => 'text', 'required' => value_is_required, 'description' => "Value for this cypher"}], options)
256
- params['itemValue'] = v_prompt['itemValue']
257
- end
258
-
259
- # Lease
260
- if !params['leaseTimeout']
261
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'leaseTimeout', 'fieldLabel' => 'Lease', 'type' => 'text', 'required' => false, 'description' => cypher_lease_help}], options)
262
- params['leaseTimeout'] = v_prompt['leaseTimeout']
263
- end
264
- if !params['leaseTimeout'].to_s.empty?
265
- params['leaseTimeout'] = params['leaseTimeout'].to_i
266
- end
267
-
268
- # construct payload
269
- payload = {
270
- 'cypher' => params
271
- }
272
- end
273
-
274
- if options[:dry_run]
275
- print_dry_run @cypher_interface.dry.create(payload)
276
- return
277
- end
278
- json_response = @cypher_interface.create(payload)
279
- if options[:json]
280
- print JSON.pretty_generate(json_response)
281
- print "\n"
282
- elsif !options[:quiet]
283
- print_green_success "Added cypher"
284
- # list([])
285
- cypher_item = json_response['cypher']
286
- get([cypher_item['id']])
287
- end
288
- return 0
289
- rescue RestClient::Exception => e
290
- print_rest_exception(e, options)
291
- exit 1
292
- end
293
- end
294
-
295
- # def update(args)
296
- # end
297
-
298
- # def decrypt(args)
299
- # end
300
-
301
- def remove(args)
302
- options = {}
303
- optparse = Morpheus::Cli::OptionParser.new do |opts|
304
- opts.banner = subcommand_usage("[id]")
305
- build_common_options(opts, options, [:account, :auto_confirm, :json, :dry_run, :quiet, :remote])
306
- opts.footer = "Delete a cypher." + "\n" +
307
- "[id] is required. This is the id or key of a cypher."
308
- end
309
- optparse.parse!(args)
310
-
311
- if args.count != 1
312
- print_error Morpheus::Terminal.angry_prompt
313
- puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
314
- return 1
315
- end
316
-
317
- connect(options)
318
- begin
319
- cypher_item = find_cypher_by_name_or_id(args[0])
320
- return 1 if cypher_item.nil?
321
- unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the cypher #{cypher_item['itemKey']}?")
322
- return 9, "aborted command"
323
- end
324
- if options[:dry_run]
325
- print_dry_run @cypher_interface.dry.destroy(cypher_item["id"])
326
- return
327
- end
328
- json_response = @cypher_interface.destroy(cypher_item["id"])
329
- if options[:json]
330
- print JSON.pretty_generate(json_response)
331
- print "\n"
332
- elsif !options[:quiet]
333
- print_green_success "Deleted cypher #{cypher_item['itemKey']}"
334
- # list([])
335
- end
336
- return 0
337
- rescue RestClient::Exception => e
338
- print_rest_exception(e, options)
339
- return 1
340
- end
341
- end
342
-
343
- private
344
-
345
- def find_cypher_by_name_or_id(val)
346
- if val.to_s =~ /\A\d{1,}\Z/
347
- return find_cypher_by_id(val)
348
- else
349
- return find_cypher_by_name(val)
350
- end
351
- end
352
-
353
- def find_cypher_by_id(id)
354
- begin
355
-
356
- json_response = @cypher_interface.get(id.to_i)
357
- return json_response['cypher']
358
- rescue RestClient::Exception => e
359
- if e.response && e.response.code == 404
360
- print_red_alert "Cypher not found by id #{id}"
361
- return nil
362
- else
363
- raise e
364
- end
365
- end
366
- end
367
-
368
- def find_cypher_by_name(name)
369
- # api supports name as alias for itemKey
370
- json_response = @cypher_interface.list({name: name.to_s})
371
-
372
- cypher_items = json_response['cyphers']
373
- if cypher_items.empty?
374
- print_red_alert "Cypher not found by name #{name}"
375
- return nil
376
- elsif cypher_items.size > 1
377
- print_red_alert "#{cypher_items.size} cyphers found by name #{name}"
378
- rows = cypher_items.collect do |cypher_item|
379
- {id: cypher_item['id'], name: cypher_item['name']}
380
- end
381
- print red
382
- print as_pretty_table(rows, [:id, :name])
383
- print reset,"\n"
384
- return nil
385
- else
386
- return cypher_items[0]
387
- end
388
- end
389
-
390
- def cypher_key_help
391
- """
392
- Keys can have different behaviors depending on the specified mountpoint.
393
- Available Mountpoints:
394
- password - Generates a secure password of specified character length in the key pattern (or 15) with symbols, numbers, upper case, and lower case letters (i.e. password/15/mypass generates a 15 character password).
395
- tfvars - This is a module to store a tfvars file for terraform.
396
- secret - This is the standard secret module that stores a key/value in encrypted form.
397
- uuid - Returns a new UUID by key name when requested and stores the generated UUID by key name for a given lease timeout period.
398
- key - Generates a Base 64 encoded AES Key of specified bit length in the key pattern (i.e. key/128/mykey generates a 128-bit key)"""
399
- end
400
-
401
- def cypher_lease_help
402
- """
403
- Lease time in MS (defaults to 32 days)
404
- Quick MS Time Reference:
405
- Day: 86400000
406
- Week: 604800000
407
- Month (30 days): 2592000000
408
- Year: 31536000000"""
409
- end
410
-
411
- end
412
-