morpheus-cli 0.9.9 → 0.9.10

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/morpheus/api/api_client.rb +4 -0
  3. data/lib/morpheus/api/app_templates_interface.rb +74 -0
  4. data/lib/morpheus/api/instance_types_interface.rb +9 -0
  5. data/lib/morpheus/api/instances_interface.rb +16 -0
  6. data/lib/morpheus/api/roles_interface.rb +37 -1
  7. data/lib/morpheus/cli.rb +4 -1
  8. data/lib/morpheus/cli/accounts.rb +82 -58
  9. data/lib/morpheus/cli/app_templates.rb +908 -0
  10. data/lib/morpheus/cli/apps.rb +226 -187
  11. data/lib/morpheus/cli/cli_command.rb +57 -30
  12. data/lib/morpheus/cli/clouds.rb +50 -65
  13. data/lib/morpheus/cli/deployments.rb +18 -33
  14. data/lib/morpheus/cli/deploys.rb +1 -3
  15. data/lib/morpheus/cli/groups.rb +54 -38
  16. data/lib/morpheus/cli/hosts.rb +86 -80
  17. data/lib/morpheus/cli/instance_types.rb +42 -29
  18. data/lib/morpheus/cli/instances.rb +192 -69
  19. data/lib/morpheus/cli/key_pairs.rb +70 -87
  20. data/lib/morpheus/cli/license.rb +7 -9
  21. data/lib/morpheus/cli/load_balancers.rb +23 -53
  22. data/lib/morpheus/cli/mixins/accounts_helper.rb +7 -8
  23. data/lib/morpheus/cli/mixins/print_helper.rb +67 -0
  24. data/lib/morpheus/cli/mixins/provisioning_helper.rb +461 -0
  25. data/lib/morpheus/cli/option_types.rb +71 -18
  26. data/lib/morpheus/cli/roles.rb +725 -34
  27. data/lib/morpheus/cli/security_group_rules.rb +50 -70
  28. data/lib/morpheus/cli/security_groups.rb +61 -48
  29. data/lib/morpheus/cli/shell.rb +123 -14
  30. data/lib/morpheus/cli/tasks.rb +24 -59
  31. data/lib/morpheus/cli/users.rb +86 -71
  32. data/lib/morpheus/cli/version.rb +1 -1
  33. data/lib/morpheus/cli/virtual_images.rb +21 -51
  34. data/lib/morpheus/cli/workflows.rb +14 -29
  35. data/lib/morpheus/ext/nil_class.rb +5 -0
  36. data/lib/morpheus/formatters.rb +1 -0
  37. metadata +7 -3
  38. data/lib/morpheus/cli/error_handler.rb +0 -44
@@ -1,7 +1,6 @@
1
1
  # require 'yaml'
2
2
  require 'io/console'
3
3
  require 'rest_client'
4
- require 'term/ansicolor'
5
4
  require 'optparse'
6
5
  require 'filesize'
7
6
  require 'table_print'
@@ -9,10 +8,17 @@ require 'morpheus/cli/cli_command'
9
8
 
10
9
  class Morpheus::Cli::Apps
11
10
  include Morpheus::Cli::CliCommand
12
- include Term::ANSIColor
11
+
13
12
  def initialize()
14
13
  @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
14
+ end
15
+
16
+ def connect(opts)
15
17
  @access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
18
+ if @access_token.empty?
19
+ print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
20
+ exit 1
21
+ end
16
22
  @apps_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).apps
17
23
  @instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
18
24
  @apps_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).apps
@@ -20,13 +26,8 @@ class Morpheus::Cli::Apps
20
26
  @active_groups = ::Morpheus::Cli::Groups.load_group_file
21
27
  end
22
28
 
23
-
24
29
  def handle(args)
25
- if @access_token.empty?
26
- print red,bold, "\nInvalid Credentials. Unable to acquire access token. Please verify your credentials and try again.\n\n",reset
27
- return 1
28
- end
29
-
30
+ usage = "Usage: morpheus apps [list,add,remove,stop,start,restart,resize,upgrade,clone,envs,setenv,delenv,firewall_disable,firewall_enable,security_groups,apply_security_groups] [name]"
30
31
  case args[0]
31
32
  when 'list'
32
33
  list(args[1..-1])
@@ -59,27 +60,35 @@ class Morpheus::Cli::Apps
59
60
  when 'apply_security_groups'
60
61
  apply_security_groups(args[1..-1])
61
62
  else
62
- puts "\nUsage: morpheus apps [list,add,remove,stop,start,restart,resize,upgrade,clone,envs,setenv,delenv,firewall_disable,firewall_enable,security_groups,apply_security_groups] [name]\n\n"
63
+ puts "\n#{usage}\n\n"
64
+ exit 127
63
65
  end
64
66
  end
65
67
 
66
68
  def add(args)
69
+ options = {}
70
+ optparse = OptionParser.new do|opts|
71
+ opts.banner = "Usage: morpheus apps add NAME TYPE"
72
+ build_common_options(opts, options, [])
73
+ end
74
+ optparse.parse(args)
67
75
  if args.count < 2
68
- puts "\nUsage: morpheus apps add NAME TYPE\n\n"
69
- return
76
+ puts "\n#{optparse.banner}\n\n"
77
+ exit 1
70
78
  end
79
+ connect(options)
71
80
 
72
81
  app_name = args[0]
73
82
  instance_type_code = args[1]
74
83
  instance_type = find_instance_type_by_code(instance_type_code)
75
84
  if instance_type.nil?
76
85
  print reset,"\n\n"
77
- return
86
+ exit 1
78
87
  end
79
88
 
80
89
  groupId = @active_groups[@appliance_name.to_sym]
81
90
 
82
- options = {
91
+ params = {
83
92
  :servicePlan => nil,
84
93
  :app => {
85
94
  :name => app_name,
@@ -108,9 +117,9 @@ class Morpheus::Cli::Apps
108
117
  end
109
118
  end
110
119
  layout = instance_type['appTypeLayouts'][layout_selection-1]['id']
111
- options[:app][:layout] = {id: layout}
120
+ params[:app][:layout] = {id: layout}
112
121
  print "\n"
113
- if options[:servicePlan].nil?
122
+ if params[:servicePlan].nil?
114
123
  plans = @instance_types_interface.service_plans(layout)
115
124
  puts "Select a Plan: "
116
125
  plans['servicePlans'].each_with_index do |plan, index|
@@ -125,7 +134,7 @@ class Morpheus::Cli::Apps
125
134
  break
126
135
  end
127
136
  end
128
- options[:servicePlan] = plans['servicePlans'][plan_selection-1]['id']
137
+ params[:servicePlan] = plans['servicePlans'][plan_selection-1]['id']
129
138
  print "\n"
130
139
  end
131
140
 
@@ -135,25 +144,20 @@ class Morpheus::Cli::Apps
135
144
  instance_type_config['options'].each do |opt|
136
145
  print "#{opt['label']}: "
137
146
  if(opt['name'].downcase.include?("password"))
138
- options[opt['name']] = STDIN.noecho(&:gets).chomp!
147
+ params[opt['name']] = STDIN.noecho(&:gets).chomp!
139
148
  print "\n"
140
149
  else
141
- options[opt['name']] = $stdin.gets.chomp!
150
+ params[opt['name']] = $stdin.gets.chomp!
142
151
  end
143
152
 
144
153
  end
145
154
  end
146
155
  end
147
156
  begin
148
- @apps_interface.create(options)
149
- rescue => e
150
- if e.response.code == 400
151
- error = JSON.parse(e.response.to_s)
152
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
153
- else
154
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
155
- end
156
- return nil
157
+ @apps_interface.create(params)
158
+ rescue RestClient::Exception => e
159
+ print_rest_exception(e, options)
160
+ exit 1
157
161
  end
158
162
  list([])
159
163
  end
@@ -162,13 +166,13 @@ class Morpheus::Cli::Apps
162
166
  options = {}
163
167
  optparse = OptionParser.new do|opts|
164
168
  opts.banner = "Usage: morpheus apps logs [name] [options]"
165
- Morpheus::Cli::CliCommand.genericOptions(opts,options)
169
+ build_common_options(opts, options, [:list, :json])
166
170
  end
171
+ optparse.parse(args)
167
172
  if args.count < 1
168
173
  puts "\n#{optparse.banner}\n\n"
169
- return
174
+ exit 1
170
175
  end
171
- optparse.parse(args)
172
176
  connect(options)
173
177
  begin
174
178
  app = find_app_by_name(args[0])
@@ -178,7 +182,11 @@ class Morpheus::Cli::Apps
178
182
  containers += app_instance['instance']['containers']
179
183
  end
180
184
  end
181
- logs = @logs_interface.container_logs(containers, { max: options[:max] || 100, offset: options[:offset] || 0, query: options[:phrase]})
185
+ params = {}
186
+ [:phrase, :offset, :max, :sort, :direction].each do |k|
187
+ params[k] = options[k] unless options[k].nil?
188
+ end
189
+ logs = @logs_interface.container_logs(containers, params)
182
190
  if options[:json]
183
191
  puts logs
184
192
  else
@@ -201,21 +209,28 @@ class Morpheus::Cli::Apps
201
209
  print reset,"\n"
202
210
  end
203
211
  rescue RestClient::Exception => e
204
- ::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
212
+ print_rest_exception(e, options)
205
213
  exit 1
206
214
  end
207
215
  end
208
216
 
209
217
  def stats(args)
218
+ options = {}
219
+ optparse = OptionParser.new do|opts|
220
+ opts.banner = "Usage: morpheus apps stats [name]"
221
+ build_common_options(opts, options, [:json])
222
+ end
223
+ optparse.parse(args)
210
224
  if args.count < 1
211
- puts "\nUsage: morpheus apps stats [name]\n\n"
212
- return
225
+ puts "\n#{optparse.banner}\n\n"
226
+ exit 1
213
227
  end
228
+ connect(options)
214
229
  begin
215
230
  app_results = @apps_interface.get({name: args[0]})
216
231
  if app_results['apps'].empty?
217
- puts "Instance not found by name #{args[0]}"
218
- return
232
+ print_red_alert "App not found by name #{args[0]}"
233
+ exit 1
219
234
  end
220
235
  app = app_results['apps'][0]
221
236
  app_id = app['id']
@@ -225,26 +240,28 @@ class Morpheus::Cli::Apps
225
240
  print cyan, "Storage: \t#{Filesize.from("#{stats['usedStorage']} B").pretty} / #{Filesize.from("#{stats['maxStorage']} B").pretty}\n\n",reset
226
241
  puts
227
242
  rescue RestClient::Exception => e
228
- if e.response.code == 400
229
- error = JSON.parse(e.response.to_s)
230
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
231
- else
232
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
233
- end
234
- return nil
243
+ print_rest_exception(e, options)
244
+ exit 1
235
245
  end
236
246
  end
237
247
 
238
248
  def details(args)
249
+ options = {}
250
+ optparse = OptionParser.new do|opts|
251
+ opts.banner = "Usage: morpheus apps details [name]"
252
+ build_common_options(opts, options, [:json])
253
+ end
254
+ optparse.parse(args)
239
255
  if args.count < 1
240
- puts "\nUsage: morpheus apps stats [name]\n\n"
241
- return
256
+ puts "\n#{optparse.banner}\n\n"
257
+ exit 1
242
258
  end
259
+ connect(options)
243
260
  begin
244
261
  app_results = @apps_interface.get({name: args[0]})
245
262
  if app_results['apps'].empty?
246
- puts "Instance not found by name #{args[0]}"
247
- return
263
+ print_red_alert "App not found by name #{args[0]}"
264
+ exit 1
248
265
  end
249
266
  app = app_results['apps'][0]
250
267
  app_id = app['id']
@@ -254,25 +271,27 @@ class Morpheus::Cli::Apps
254
271
  print cyan, "Storage: \t#{Filesize.from("#{stats['usedStorage']} B").pretty} / #{Filesize.from("#{stats['maxStorage']} B").pretty}\n\n",reset
255
272
  puts app
256
273
  rescue RestClient::Exception => e
257
- if e.response.code == 400
258
- error = JSON.parse(e.response.to_s)
259
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
260
- else
261
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
262
- end
263
- return nil
274
+ print_rest_exception(e, options)
275
+ exit 1
264
276
  end
265
277
  end
266
278
 
267
279
  def envs(args)
280
+ options = {}
281
+ optparse = OptionParser.new do|opts|
282
+ opts.banner = "Usage: morpheus apps envs [name]"
283
+ build_common_options(opts, options, [:json])
284
+ end
285
+ optparse.parse(args)
268
286
  if args.count < 1
269
- puts "\nUsage: morpheus apps envs [name]\n\n"
270
- return
287
+ puts "\n#{optparse.banner}\n\n"
288
+ exit 1
271
289
  end
290
+ connect(options)
272
291
  begin
273
292
  app_results = @apps_interface.get({name: args[0]})
274
293
  if app_results['apps'].empty?
275
- puts "Instance not found by name #{args[0]}"
294
+ print_red_alert "App not found by name #{args[0]}"
276
295
  return
277
296
  end
278
297
  app = app_results['apps'][0]
@@ -290,61 +309,63 @@ class Morpheus::Cli::Apps
290
309
  print reset, "\n"
291
310
 
292
311
  rescue RestClient::Exception => e
293
- if e.response.code == 400
294
- error = JSON.parse(e.response.to_s)
295
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
296
- else
297
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
298
- end
299
- return nil
312
+ print_rest_exception(e, options)
313
+ exit 1
300
314
  end
301
315
  end
302
316
 
303
317
  def setenv(args)
318
+ options = {}
319
+ evar = {name: args[1], value: args[2], export: false}
320
+ optparse = OptionParser.new do|opts|
321
+ opts.banner = "Usage: morpheus apps setenv INSTANCE NAME VALUE [-e]"
322
+ opts.on( '-e', "Exportable" ) do |exportable|
323
+ evar[:export] = exportable
324
+ end
325
+ build_common_options(opts, options, [:json])
326
+ end
327
+ optparse.parse(args)
304
328
  if args.count < 3
305
- puts "\nUsage: morpheus apps setenv INSTANCE NAME VALUE [-e]\n\n"
306
- return
329
+ puts "\n#{optparse.banner}\n\n"
330
+ exit 1
307
331
  end
332
+ connect(options)
308
333
  begin
309
334
  app_results = @apps_interface.get({name: args[0]})
310
335
  if app_results['apps'].empty?
311
- puts "Instance not found by name #{args[0]}"
312
- return
336
+ print_red_alert "App not found by name #{args[0]}"
337
+ exit 1
313
338
  end
314
339
  app = app_results['apps'][0]
315
340
  app_id = app['id']
316
- evar = {name: args[1], value: args[2], export: false}
317
341
  params = {}
318
- optparse = OptionParser.new do|opts|
319
- opts.on( '-e', "Exportable" ) do |exportable|
320
- evar[:export] = exportable
321
- end
322
- end
323
- optparse.parse(args)
324
342
 
325
343
  @apps_interface.create_env(app_id, [evar])
326
344
  envs([args[0]])
327
345
  rescue RestClient::Exception => e
328
- if e.response.code == 400
329
- error = JSON.parse(e.response.to_s)
330
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
331
- else
332
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
333
- end
334
- return nil
346
+ print_rest_exception(e, options)
347
+ exit 1
335
348
  end
336
349
  end
337
350
 
338
351
  def delenv(args)
352
+ options = {}
353
+ optparse = OptionParser.new do|opts|
354
+ opts.banner = "Usage: morpheus apps setenv INSTANCE NAME"
355
+ build_common_options(opts, options, [:json])
356
+ end
357
+ optparse.parse(args)
339
358
  if args.count < 2
340
- puts "\nUsage: morpheus apps setenv INSTANCE NAME\n\n"
341
- return
359
+ puts "\n#{optparse.banner}\n\n"
360
+ exit 1
342
361
  end
362
+ connect(options)
363
+
343
364
  begin
344
365
  app_results = @apps_interface.get({name: args[0]})
345
366
  if app_results['apps'].empty?
346
- puts "Instance not found by name #{args[0]}"
347
- return
367
+ print_red_alert "App not found by name #{args[0]}"
368
+ exit 1
348
369
  end
349
370
  app = app_results['apps'][0]
350
371
  app_id = app['id']
@@ -353,99 +374,108 @@ class Morpheus::Cli::Apps
353
374
  @apps_interface.del_env(app_id, name)
354
375
  envs([args[0]])
355
376
  rescue RestClient::Exception => e
356
- if e.response.code == 400
357
- error = JSON.parse(e.response.to_s)
358
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
359
- else
360
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
361
- end
362
- return nil
377
+ print_rest_exception(e, options)
378
+ exit 1
363
379
  end
364
380
  end
365
381
 
366
382
  def stop(args)
383
+ options = {}
384
+ optparse = OptionParser.new do|opts|
385
+ opts.banner = "Usage: morpheus apps stop [name]"
386
+ build_common_options(opts, options, [:json])
387
+ end
388
+ optparse.parse(args)
367
389
  if args.count < 1
368
- puts "\nUsage: morpheus apps stop [name]\n\n"
369
- return
390
+ puts "\n#{optparse.banner}\n\n"
391
+ exit 1
370
392
  end
393
+ connect(options)
371
394
  begin
372
395
  app_results = @apps_interface.get({name: args[0]})
373
396
  if app_results['apps'].empty?
374
- puts "Instance not found by name #{args[0]}"
375
- return
397
+ print_red_alert "App not found by name #{args[0]}"
398
+ exit 1
376
399
  end
377
400
  @apps_interface.stop(app_results['apps'][0]['id'])
378
401
  list([])
379
402
  rescue RestClient::Exception => e
380
- if e.response.code == 400
381
- error = JSON.parse(e.response.to_s)
382
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
383
- else
384
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
385
- end
386
- return nil
403
+ print_rest_exception(e, options)
404
+ exit 1
387
405
  end
388
406
  end
389
407
 
390
408
  def start(args)
409
+ options = {}
410
+ optparse = OptionParser.new do|opts|
411
+ opts.banner = "Usage: morpheus apps start [name]"
412
+ build_common_options(opts, options, [:json])
413
+ end
414
+ optparse.parse(args)
391
415
  if args.count < 1
392
- puts "\nUsage: morpheus apps start [name]\n\n"
393
- return
416
+ puts "\n#{optparse.banner}\n\n"
417
+ exit 1
394
418
  end
419
+ connect(options)
395
420
  begin
396
421
  app_results = @apps_interface.get({name: args[0]})
397
422
  if app_results['apps'].empty?
398
- puts "Instance not found by name #{args[0]}"
399
- return
423
+ print_red_alert "App not found by name #{args[0]}"
424
+ exit 1
400
425
  end
401
426
  @apps_interface.start(app_results['apps'][0]['id'])
402
427
  list([])
403
428
  rescue RestClient::Exception => e
404
- if e.response.code == 400
405
- error = JSON.parse(e.response.to_s)
406
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
407
- else
408
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
409
- end
410
- return nil
429
+ print_rest_exception(e, options)
430
+ exit 1
411
431
  end
412
432
  end
413
433
 
414
434
  def restart(args)
435
+ options = {}
436
+ optparse = OptionParser.new do|opts|
437
+ opts.banner = "Usage: morpheus apps restart [name]"
438
+ build_common_options(opts, options, [:json])
439
+ end
440
+ optparse.parse(args)
415
441
  if args.count < 1
416
- puts "\nUsage: morpheus apps restart [name]\n\n"
417
- return
442
+ puts "\n#{optparse.banner}\n\n"
443
+ exit 1
418
444
  end
445
+ connect(options)
419
446
  begin
420
447
  app_results = @apps_interface.get({name: args[0]})
421
448
  if app_results['apps'].empty?
422
- puts "Instance not found by name #{args[0]}"
423
- return
449
+ print_red_alert "App not found by name #{args[0]}"
450
+ exit 1
424
451
  end
425
452
  @apps_interface.restart(app_results['apps'][0]['id'])
426
453
  list([])
427
454
  rescue RestClient::Exception => e
428
- if e.response.code == 400
429
- error = JSON.parse(e.response.to_s)
430
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
431
- else
432
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
433
- end
434
- return nil
455
+ print_rest_exception(e, options)
456
+ exit 1
435
457
  end
436
458
  end
437
459
 
438
460
  def list(args)
439
461
  options = {}
440
462
  optparse = OptionParser.new do|opts|
463
+ opts.banner = "Usage: morpheus apps list"
441
464
  opts.on( '-g', '--group GROUP', "Group Name" ) do |group|
442
465
  options[:group] = group
443
466
  end
467
+ build_common_options(opts, options, [:json])
444
468
  end
445
469
  optparse.parse(args)
470
+
471
+ connect(options)
472
+
446
473
  begin
447
474
  params = {}
448
-
475
+ [:phrase, :offset, :max, :sort, :direction].each do |k|
476
+ params[k] = options[k] unless options[k].nil?
477
+ end
478
+ # todo: include options[:group] in params?
449
479
  json_response = @apps_interface.get(params)
450
480
  apps = json_response['apps']
451
481
  print "\n" ,cyan, bold, "Morpheus Apps\n","==================", reset, "\n\n"
@@ -465,87 +495,104 @@ class Morpheus::Cli::Apps
465
495
  end
466
496
 
467
497
  def remove(args)
498
+ options = {}
499
+ optparse = OptionParser.new do|opts|
500
+ opts.banner = "Usage: morpheus apps remove [name]"
501
+ build_common_options(opts, options, [:json])
502
+ end
503
+ optparse.parse(args)
468
504
  if args.count < 1
469
- puts "\nUsage: morpheus apps remove [name]\n\n"
470
- return
505
+ puts "\n#{optparse.banner}\n\n"
506
+ exit 1
471
507
  end
508
+ connect(options)
509
+
472
510
  begin
473
511
  app_results = @apps_interface.get({name: args[0]})
474
512
  if app_results['apps'].empty?
475
- puts "Instance not found by name #{args[0]}"
476
- return
513
+ print_red_alert "App not found by name #{args[0]}"
514
+ exit 1
477
515
  end
478
516
  @apps_interface.destroy(app_results['apps'][0]['id'])
479
517
  list([])
480
518
  rescue RestClient::Exception => e
481
- if e.response.code == 400
482
- error = JSON.parse(e.response.to_s)
483
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
484
- else
485
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
486
- end
487
- return nil
519
+ print_rest_exception(e, options)
520
+ exit 1
488
521
  end
489
522
  end
490
523
 
491
524
  def firewall_disable(args)
525
+ options = {}
526
+ optparse = OptionParser.new do|opts|
527
+ opts.banner = "Usage: morpheus apps firewall_disable [name]"
528
+ build_common_options(opts, options, [:json])
529
+ end
530
+ optparse.parse(args)
492
531
  if args.count < 1
493
- puts "\nUsage: morpheus apps firewall_disable [name]\n\n"
494
- return
532
+ puts "\n#{optparse.banner}\n\n"
533
+ exit 1
495
534
  end
535
+ connect(options)
536
+
496
537
  begin
497
538
  app_results = @apps_interface.get({name: args[0]})
498
539
  if app_results['apps'].empty?
499
- puts "App not found by name #{args[0]}"
500
- return
540
+ print_red_alert "App not found by name #{args[0]}"
541
+ exit 1
501
542
  end
502
543
  @apps_interface.firewall_disable(app_results['apps'][0]['id'])
503
544
  security_groups([args[0]])
504
545
  rescue RestClient::Exception => e
505
- if e.response.code == 400
506
- error = JSON.parse(e.response.to_s)
507
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
508
- else
509
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
510
- end
511
- return nil
546
+ print_rest_exception(e, options)
547
+ exit 1
512
548
  end
513
549
  end
514
550
 
515
551
  def firewall_enable(args)
552
+ options = {}
553
+ optparse = OptionParser.new do|opts|
554
+ opts.banner = "Usage: morpheus apps firewall_enable [name]"
555
+ build_common_options(opts, options, [:json])
556
+ end
557
+ optparse.parse(args)
516
558
  if args.count < 1
517
- puts "\nUsage: morpheus apps firewall_enable [name]\n\n"
518
- return
559
+ puts "\n#{optparse.banner}\n\n"
560
+ exit 1
519
561
  end
562
+ connect(options)
563
+
520
564
  begin
521
565
  app_results = @apps_interface.get({name: args[0]})
522
566
  if app_results['apps'].empty?
523
- puts "App not found by name #{args[0]}"
524
- return
567
+ print_red_alert "App not found by name #{args[0]}"
568
+ exit 1
525
569
  end
526
570
  @apps_interface.firewall_enable(app_results['apps'][0]['id'])
527
571
  security_groups([args[0]])
528
572
  rescue RestClient::Exception => e
529
- if e.response.code == 400
530
- error = JSON.parse(e.response.to_s)
531
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
532
- else
533
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
534
- end
535
- return nil
573
+ print_rest_exception(e, options)
574
+ exit 1
536
575
  end
537
576
  end
538
577
 
539
578
  def security_groups(args)
579
+ options = {}
580
+ optparse = OptionParser.new do|opts|
581
+ opts.banner = "Usage: morpheus apps security_groups [name]"
582
+ build_common_options(opts, options, [:json])
583
+ end
584
+ optparse.parse(args)
540
585
  if args.count < 1
541
- puts "\nUsage: morpheus apps security_groups [name]\n\n"
542
- return
586
+ puts "\n#{optparse.banner}\n\n"
587
+ exit 1
543
588
  end
589
+ connect(options)
590
+
544
591
  begin
545
592
  app_results = @apps_interface.get({name: args[0]})
546
593
  if app_results['apps'].empty?
547
- puts "Instance not found by name #{args[0]}"
548
- return
594
+ print_red_alert "App not found by name #{args[0]}"
595
+ exit 1
549
596
  end
550
597
 
551
598
  app_id = app_results['apps'][0]['id']
@@ -564,13 +611,8 @@ class Morpheus::Cli::Apps
564
611
  print reset,"\n\n"
565
612
 
566
613
  rescue RestClient::Exception => e
567
- if e.response.code == 400
568
- error = JSON.parse(e.response.to_s)
569
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
570
- else
571
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
572
- end
573
- return nil
614
+ print_rest_exception(e, options)
615
+ exit 1
574
616
  end
575
617
  end
576
618
 
@@ -578,10 +620,6 @@ class Morpheus::Cli::Apps
578
620
  usage = <<-EOF
579
621
  Usage: morpheus apps apply_security_groups [name] [options]
580
622
  EOF
581
- if args.count < 1
582
- puts usage
583
- return
584
- end
585
623
 
586
624
  options = {}
587
625
  clear_or_secgroups_specified = false
@@ -599,31 +637,32 @@ EOF
599
637
  puts opts
600
638
  exit
601
639
  end
640
+ build_common_options(opts, options, [:json])
602
641
  end
603
642
  optparse.parse(args)
604
-
643
+ if args.count < 1
644
+ puts "\n#{optparse.banner}\n\n"
645
+ exit 1
646
+ end
605
647
  if !clear_or_secgroups_specified
606
648
  puts usage
607
- exit
649
+ exit 1
608
650
  end
609
651
 
652
+ connect(options)
653
+
610
654
  begin
611
655
  app_results = @apps_interface.get({name: args[0]})
612
656
  if app_results['apps'].empty?
613
- puts "App not found by name #{args[0]}"
614
- return
657
+ print_red_alert "App not found by name #{args[0]}"
658
+ exit 1
615
659
  end
616
660
 
617
661
  @apps_interface.apply_security_groups(app_results['apps'][0]['id'], options)
618
662
  security_groups([args[0]])
619
663
  rescue RestClient::Exception => e
620
- if e.response.code == 400
621
- error = JSON.parse(e.response.to_s)
622
- ::Morpheus::Cli::ErrorHandler.new.print_errors(error)
623
- else
624
- puts "Error Communicating with the Appliance. Please try again later. #{e}"
625
- end
626
- return nil
664
+ print_rest_exception(e, options)
665
+ exit 1
627
666
  end
628
667
  end
629
668
 
@@ -632,7 +671,7 @@ private
632
671
  def find_app_by_name(name)
633
672
  app_results = @apps_interface.get({name: name})
634
673
  if app_results['apps'].empty?
635
- puts "Instance not found by name #{name}"
674
+ print_red_alert "App not found by name #{name}"
636
675
  exit 1
637
676
  end
638
677
  return app_results['apps'][0]