morpheus-cli 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/morpheus/api/api_client.rb +4 -0
- data/lib/morpheus/api/app_templates_interface.rb +74 -0
- data/lib/morpheus/api/instance_types_interface.rb +9 -0
- data/lib/morpheus/api/instances_interface.rb +16 -0
- data/lib/morpheus/api/roles_interface.rb +37 -1
- data/lib/morpheus/cli.rb +4 -1
- data/lib/morpheus/cli/accounts.rb +82 -58
- data/lib/morpheus/cli/app_templates.rb +908 -0
- data/lib/morpheus/cli/apps.rb +226 -187
- data/lib/morpheus/cli/cli_command.rb +57 -30
- data/lib/morpheus/cli/clouds.rb +50 -65
- data/lib/morpheus/cli/deployments.rb +18 -33
- data/lib/morpheus/cli/deploys.rb +1 -3
- data/lib/morpheus/cli/groups.rb +54 -38
- data/lib/morpheus/cli/hosts.rb +86 -80
- data/lib/morpheus/cli/instance_types.rb +42 -29
- data/lib/morpheus/cli/instances.rb +192 -69
- data/lib/morpheus/cli/key_pairs.rb +70 -87
- data/lib/morpheus/cli/license.rb +7 -9
- data/lib/morpheus/cli/load_balancers.rb +23 -53
- data/lib/morpheus/cli/mixins/accounts_helper.rb +7 -8
- data/lib/morpheus/cli/mixins/print_helper.rb +67 -0
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +461 -0
- data/lib/morpheus/cli/option_types.rb +71 -18
- data/lib/morpheus/cli/roles.rb +725 -34
- data/lib/morpheus/cli/security_group_rules.rb +50 -70
- data/lib/morpheus/cli/security_groups.rb +61 -48
- data/lib/morpheus/cli/shell.rb +123 -14
- data/lib/morpheus/cli/tasks.rb +24 -59
- data/lib/morpheus/cli/users.rb +86 -71
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +21 -51
- data/lib/morpheus/cli/workflows.rb +14 -29
- data/lib/morpheus/ext/nil_class.rb +5 -0
- data/lib/morpheus/formatters.rb +1 -0
- metadata +7 -3
- data/lib/morpheus/cli/error_handler.rb +0 -44
@@ -1,14 +1,11 @@
|
|
1
|
-
# require 'yaml'
|
2
1
|
require 'io/console'
|
3
|
-
require 'rest_client'
|
4
|
-
require 'term/ansicolor'
|
5
2
|
require 'optparse'
|
6
3
|
require 'filesize'
|
7
4
|
require 'morpheus/cli/cli_command'
|
8
5
|
|
9
6
|
class Morpheus::Cli::InstanceTypes
|
10
7
|
include Morpheus::Cli::CliCommand
|
11
|
-
|
8
|
+
|
12
9
|
def initialize()
|
13
10
|
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
14
11
|
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
|
@@ -20,7 +17,7 @@ class Morpheus::Cli::InstanceTypes
|
|
20
17
|
|
21
18
|
def handle(args)
|
22
19
|
if @access_token.empty?
|
23
|
-
|
20
|
+
print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
|
24
21
|
return 1
|
25
22
|
end
|
26
23
|
if args.empty?
|
@@ -40,46 +37,62 @@ class Morpheus::Cli::InstanceTypes
|
|
40
37
|
|
41
38
|
|
42
39
|
def details(args)
|
40
|
+
options = {}
|
41
|
+
optparse = OptionParser.new do|opts|
|
42
|
+
opts.banner = "Usage: morpheus instance-type details [name]"
|
43
|
+
build_common_options(opts, options, [:json])
|
44
|
+
end
|
45
|
+
optparse.parse(args)
|
43
46
|
if args.count < 1
|
44
|
-
puts "\
|
47
|
+
puts "\n#{optparse.banner}\n\n"
|
45
48
|
return
|
46
49
|
end
|
50
|
+
name = args[0]
|
47
51
|
begin
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
return
|
52
|
+
json_response = @instance_types_interface.get({name: name})
|
53
|
+
|
54
|
+
if options[:json]
|
55
|
+
print JSON.pretty_generate(json_response), "\n" and return
|
52
56
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
print cyan, "Storage: \t#{Filesize.from("#{stats['usedStorage']} B").pretty} / #{Filesize.from("#{stats['maxStorage']} B").pretty}\n\n",reset
|
59
|
-
puts instance
|
60
|
-
rescue RestClient::Exception => e
|
61
|
-
if e.response.code == 400
|
62
|
-
error = JSON.parse(e.response.to_s)
|
63
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
57
|
+
|
58
|
+
instance_type = json_response['instanceTypes'][0]
|
59
|
+
|
60
|
+
if instance_type.nil?
|
61
|
+
puts yellow,"No instance type found by name #{name}.",reset
|
64
62
|
else
|
65
|
-
|
63
|
+
print "\n" ,cyan, bold, "Instance Type Details\n","==================", reset, "\n\n"
|
64
|
+
versions = instance_type['versions'].join(', ')
|
65
|
+
print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
|
66
|
+
instance_type['instanceTypeLayouts'].each do |layout|
|
67
|
+
print green, " - #{layout['name']}\n",reset
|
68
|
+
end
|
69
|
+
print reset,"\n\n"
|
66
70
|
end
|
67
|
-
|
71
|
+
|
72
|
+
rescue RestClient::Exception => e
|
73
|
+
print_rest_exception(e, options)
|
74
|
+
exit 1
|
68
75
|
end
|
69
76
|
end
|
70
77
|
|
71
78
|
def list(args)
|
72
79
|
options = {}
|
73
80
|
optparse = OptionParser.new do|opts|
|
74
|
-
opts
|
75
|
-
options[:group] = group
|
76
|
-
end
|
81
|
+
build_common_options(opts, options, [:list, :json])
|
77
82
|
end
|
78
83
|
optparse.parse(args)
|
79
84
|
begin
|
80
85
|
params = {}
|
86
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
87
|
+
params[k] = options[k] unless options[k].nil?
|
88
|
+
end
|
81
89
|
|
82
90
|
json_response = @instance_types_interface.get(params)
|
91
|
+
|
92
|
+
if options[:json]
|
93
|
+
print JSON.pretty_generate(json_response), "\n" and return
|
94
|
+
end
|
95
|
+
|
83
96
|
instance_types = json_response['instanceTypes']
|
84
97
|
print "\n" ,cyan, bold, "Morpheus Instance Types\n","==================", reset, "\n\n"
|
85
98
|
if instance_types.empty?
|
@@ -95,9 +108,9 @@ class Morpheus::Cli::InstanceTypes
|
|
95
108
|
end
|
96
109
|
print reset,"\n\n"
|
97
110
|
|
98
|
-
rescue => e
|
99
|
-
|
100
|
-
|
111
|
+
rescue RestClient::Exception => e
|
112
|
+
print_rest_exception(e, options)
|
113
|
+
exit 1
|
101
114
|
end
|
102
115
|
end
|
103
116
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
# require 'yaml'
|
2
1
|
require 'io/console'
|
3
2
|
require 'rest_client'
|
4
|
-
require 'term/ansicolor'
|
5
3
|
require 'optparse'
|
6
4
|
require 'filesize'
|
7
5
|
require 'table_print'
|
8
6
|
require 'morpheus/cli/cli_command'
|
7
|
+
require 'morpheus/cli/mixins/provisioning_helper'
|
9
8
|
|
10
9
|
class Morpheus::Cli::Instances
|
11
10
|
include Morpheus::Cli::CliCommand
|
12
|
-
|
11
|
+
include Morpheus::Cli::ProvisioningHelper
|
12
|
+
|
13
13
|
def initialize()
|
14
14
|
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
15
15
|
|
@@ -34,15 +34,16 @@ class Morpheus::Cli::Instances
|
|
34
34
|
@options_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).options
|
35
35
|
@active_groups = ::Morpheus::Cli::Groups.load_group_file
|
36
36
|
if @access_token.empty?
|
37
|
-
|
37
|
+
print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
|
38
38
|
exit 1
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
|
43
43
|
def handle(args)
|
44
|
+
usage = "Usage: morpheus instances [list,add,remove,stop,start,restart,backup,run-workflow,stop-service,start-service,restart-service,resize,upgrade,clone,envs,setenv,delenv] [name]"
|
44
45
|
if args.empty?
|
45
|
-
puts "\
|
46
|
+
puts "\n#{usage}\n\n"
|
46
47
|
return
|
47
48
|
end
|
48
49
|
|
@@ -65,6 +66,8 @@ class Morpheus::Cli::Instances
|
|
65
66
|
start_service(args[1..-1])
|
66
67
|
when 'restart-service'
|
67
68
|
restart_service(args[1..-1])
|
69
|
+
when 'resize'
|
70
|
+
resize(args[1..-1])
|
68
71
|
when 'run-workflow'
|
69
72
|
run_workflow(args[1..-1])
|
70
73
|
when 'stats'
|
@@ -90,7 +93,7 @@ class Morpheus::Cli::Instances
|
|
90
93
|
when 'backup'
|
91
94
|
backup(args[1..-1])
|
92
95
|
else
|
93
|
-
puts "\
|
96
|
+
puts "\n#{usage}\n\n"
|
94
97
|
exit 127
|
95
98
|
end
|
96
99
|
end
|
@@ -105,7 +108,7 @@ class Morpheus::Cli::Instances
|
|
105
108
|
opts.on( '-c', '--cloud CLOUD', "Cloud" ) do |val|
|
106
109
|
options[:cloud] = val
|
107
110
|
end
|
108
|
-
|
111
|
+
build_common_options(opts, options, [:options, :json, :remote])
|
109
112
|
|
110
113
|
end
|
111
114
|
|
@@ -171,6 +174,32 @@ class Morpheus::Cli::Instances
|
|
171
174
|
|
172
175
|
payload[:instance][:layout] = {id: layout['id']}
|
173
176
|
|
177
|
+
|
178
|
+
begin
|
179
|
+
service_plan_options_json = @instance_types_interface.service_plan_options(plan_prompt['servicePlan'], {cloudId: cloud, zoneId: cloud, layoutId: layout_id})
|
180
|
+
|
181
|
+
# puts ""
|
182
|
+
# print JSON.pretty_generate(service_plan_options_json)
|
183
|
+
|
184
|
+
plan_options = service_plan_options_json['plan']
|
185
|
+
volumes = prompt_instance_volumes(plan_options, options, @api_client, {})
|
186
|
+
|
187
|
+
# puts "VOLUMES:"
|
188
|
+
# print JSON.pretty_generate(volumes)
|
189
|
+
|
190
|
+
if !volumes.empty?
|
191
|
+
payload[:volumes] = volumes
|
192
|
+
end
|
193
|
+
|
194
|
+
# puts "\nexiting early...\n"
|
195
|
+
# exit 1
|
196
|
+
|
197
|
+
rescue RestClient::Exception => e
|
198
|
+
print_red_alert "Unable to load options for selected plan."
|
199
|
+
print_rest_exception(e, options)
|
200
|
+
exit 1
|
201
|
+
end
|
202
|
+
|
174
203
|
type_payload = {}
|
175
204
|
if !layout['optionTypes'].nil? && !layout['optionTypes'].empty?
|
176
205
|
type_payload = Morpheus::Cli::OptionTypes.prompt(layout['optionTypes'],options[:options],@api_client,{groupId: groupId, cloudId: cloud, zoneId: cloud, instanceTypeId: instance_type['id'], version: version_prompt['version']})
|
@@ -183,7 +212,7 @@ class Morpheus::Cli::Instances
|
|
183
212
|
|
184
213
|
provision_payload = {}
|
185
214
|
if !layout['provisionType'].nil? && !layout['provisionType']['optionTypes'].nil? && !layout['provisionType']['optionTypes'].empty?
|
186
|
-
puts "Checking for option Types"
|
215
|
+
#puts "Checking for option Types"
|
187
216
|
provision_payload = Morpheus::Cli::OptionTypes.prompt(layout['provisionType']['optionTypes'],options[:options],@api_client,{groupId: groupId, cloudId: cloud, zoneId: cloud, instanceTypeId: instance_type['id'], version: version_prompt['version']})
|
188
217
|
end
|
189
218
|
|
@@ -194,20 +223,29 @@ class Morpheus::Cli::Instances
|
|
194
223
|
payload[:server] = provision_payload['server']
|
195
224
|
end
|
196
225
|
|
226
|
+
# avoid 500 error
|
227
|
+
payload[:servicePlanOptions] = {}
|
228
|
+
|
197
229
|
begin
|
198
|
-
@instances_interface.create(payload)
|
230
|
+
json_response = @instances_interface.create(payload)
|
231
|
+
if options[:json]
|
232
|
+
print JSON.pretty_generate(json_response)
|
233
|
+
print "\n"
|
234
|
+
else
|
235
|
+
print_green_success "Provisioning instance #{instance_name}"
|
236
|
+
list([])
|
237
|
+
end
|
199
238
|
rescue RestClient::Exception => e
|
200
|
-
|
239
|
+
print_rest_exception(e, options)
|
201
240
|
exit 1
|
202
241
|
end
|
203
|
-
list([])
|
204
242
|
end
|
205
243
|
|
206
244
|
def stats(args)
|
207
245
|
options = {}
|
208
246
|
optparse = OptionParser.new do|opts|
|
209
247
|
opts.banner = "Usage: morpheus instances stats [name]"
|
210
|
-
|
248
|
+
build_common_options(opts, options, [:json, :remote])
|
211
249
|
end
|
212
250
|
if args.count < 1
|
213
251
|
puts "\n#{optparse.banner}\n\n"
|
@@ -237,7 +275,7 @@ class Morpheus::Cli::Instances
|
|
237
275
|
print reset, "\n"
|
238
276
|
end
|
239
277
|
rescue RestClient::Exception => e
|
240
|
-
|
278
|
+
print_rest_exception(e, options)
|
241
279
|
exit 1
|
242
280
|
end
|
243
281
|
end
|
@@ -246,10 +284,10 @@ class Morpheus::Cli::Instances
|
|
246
284
|
options = {}
|
247
285
|
optparse = OptionParser.new do|opts|
|
248
286
|
opts.banner = "Usage: morpheus instances logs [name]"
|
249
|
-
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
250
287
|
opts.on( '-n', '--node NODE_ID', "Scope logs to specific Container or VM" ) do |node_id|
|
251
288
|
options[:node_id] = node_id.to_i
|
252
289
|
end
|
290
|
+
build_common_options(opts, options, [:list, :json, :remote])
|
253
291
|
end
|
254
292
|
if args.count < 1
|
255
293
|
puts "\n#{optparse.banner}\n\n"
|
@@ -286,7 +324,7 @@ class Morpheus::Cli::Instances
|
|
286
324
|
print reset,"\n"
|
287
325
|
end
|
288
326
|
rescue RestClient::Exception => e
|
289
|
-
|
327
|
+
print_rest_exception(e, options)
|
290
328
|
exit 1
|
291
329
|
end
|
292
330
|
end
|
@@ -295,7 +333,7 @@ class Morpheus::Cli::Instances
|
|
295
333
|
options = {}
|
296
334
|
optparse = OptionParser.new do|opts|
|
297
335
|
opts.banner = "Usage: morpheus instances details [name]"
|
298
|
-
|
336
|
+
build_common_options(opts, options, [:json, :remote])
|
299
337
|
end
|
300
338
|
if args.count < 1
|
301
339
|
puts "\n#{optparse.banner}\n\n"
|
@@ -317,7 +355,7 @@ class Morpheus::Cli::Instances
|
|
317
355
|
print cyan, "Storage: \t#{Filesize.from("#{stats['usedStorage']} B").pretty} / #{Filesize.from("#{stats['maxStorage']} B").pretty}\n\n",reset
|
318
356
|
puts instance
|
319
357
|
rescue RestClient::Exception => e
|
320
|
-
|
358
|
+
print_rest_exception(e, options)
|
321
359
|
exit 1
|
322
360
|
end
|
323
361
|
end
|
@@ -326,7 +364,7 @@ class Morpheus::Cli::Instances
|
|
326
364
|
options = {}
|
327
365
|
optparse = OptionParser.new do|opts|
|
328
366
|
opts.banner = "Usage: morpheus instances envs [name]"
|
329
|
-
|
367
|
+
build_common_options(opts, options, [:json, :remote])
|
330
368
|
end
|
331
369
|
if args.count < 1
|
332
370
|
puts "\n#{optparse.banner}\n\n"
|
@@ -349,7 +387,7 @@ class Morpheus::Cli::Instances
|
|
349
387
|
print reset, "\n"
|
350
388
|
|
351
389
|
rescue RestClient::Exception => e
|
352
|
-
|
390
|
+
print_rest_exception(e, options)
|
353
391
|
exit 1
|
354
392
|
end
|
355
393
|
end
|
@@ -365,7 +403,7 @@ class Morpheus::Cli::Instances
|
|
365
403
|
opts.on( '-M', "Masked" ) do |masked|
|
366
404
|
options[:masked] = masked
|
367
405
|
end
|
368
|
-
|
406
|
+
build_common_options(opts, options, [:json, :remote])
|
369
407
|
end
|
370
408
|
if args.count < 3
|
371
409
|
puts "\n#{optparse.banner}\n\n"
|
@@ -380,7 +418,7 @@ class Morpheus::Cli::Instances
|
|
380
418
|
@instances_interface.create_env(instance['id'], [evar])
|
381
419
|
envs([args[0]])
|
382
420
|
rescue RestClient::Exception => e
|
383
|
-
|
421
|
+
print_rest_exception(e, options)
|
384
422
|
exit 1
|
385
423
|
end
|
386
424
|
end
|
@@ -389,7 +427,7 @@ class Morpheus::Cli::Instances
|
|
389
427
|
options = {}
|
390
428
|
optparse = OptionParser.new do|opts|
|
391
429
|
opts.banner = "Usage: morpheus instances setenv INSTANCE NAME"
|
392
|
-
|
430
|
+
build_common_options(opts, options, [:json, :remote])
|
393
431
|
end
|
394
432
|
if args.count < 2
|
395
433
|
puts "\n#{optparse.banner}\n\n"
|
@@ -402,7 +440,7 @@ class Morpheus::Cli::Instances
|
|
402
440
|
@instances_interface.del_env(instance['id'], args[1])
|
403
441
|
envs([args[0]])
|
404
442
|
rescue RestClient::Exception => e
|
405
|
-
|
443
|
+
print_rest_exception(e, options)
|
406
444
|
exit 1
|
407
445
|
end
|
408
446
|
end
|
@@ -411,7 +449,7 @@ class Morpheus::Cli::Instances
|
|
411
449
|
options = {}
|
412
450
|
optparse = OptionParser.new do|opts|
|
413
451
|
opts.banner = "Usage: morpheus instances stop [name]"
|
414
|
-
|
452
|
+
build_common_options(opts, options, [:auto_confirm, :json, :remote])
|
415
453
|
end
|
416
454
|
if args.count < 1
|
417
455
|
puts "\n#{optparse.banner}\n\n"
|
@@ -421,7 +459,7 @@ class Morpheus::Cli::Instances
|
|
421
459
|
connect(options)
|
422
460
|
begin
|
423
461
|
instance = find_instance_by_name(args[0])
|
424
|
-
|
462
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to stop this instance?", options)
|
425
463
|
exit 1
|
426
464
|
end
|
427
465
|
json_response = @instances_interface.stop(instance['id'])
|
@@ -431,7 +469,7 @@ class Morpheus::Cli::Instances
|
|
431
469
|
end
|
432
470
|
return
|
433
471
|
rescue RestClient::Exception => e
|
434
|
-
|
472
|
+
print_rest_exception(e, options)
|
435
473
|
exit 1
|
436
474
|
end
|
437
475
|
end
|
@@ -440,7 +478,7 @@ class Morpheus::Cli::Instances
|
|
440
478
|
options = {}
|
441
479
|
optparse = OptionParser.new do|opts|
|
442
480
|
opts.banner = "Usage: morpheus instances start [name]"
|
443
|
-
|
481
|
+
build_common_options(opts, options, [:json, :remote])
|
444
482
|
end
|
445
483
|
if args.count < 1
|
446
484
|
puts "\n#{optparse.banner}\n\n"
|
@@ -457,7 +495,7 @@ class Morpheus::Cli::Instances
|
|
457
495
|
end
|
458
496
|
return
|
459
497
|
rescue RestClient::Exception => e
|
460
|
-
|
498
|
+
print_rest_exception(e, options)
|
461
499
|
exit 1
|
462
500
|
end
|
463
501
|
end
|
@@ -466,7 +504,7 @@ class Morpheus::Cli::Instances
|
|
466
504
|
options = {}
|
467
505
|
optparse = OptionParser.new do|opts|
|
468
506
|
opts.banner = "Usage: morpheus instances restart [name]"
|
469
|
-
|
507
|
+
build_common_options(opts, options, [:auto_confirm, :json, :remote])
|
470
508
|
end
|
471
509
|
if args.count < 1
|
472
510
|
puts "\n#{optparse.banner}\n\n"
|
@@ -476,7 +514,7 @@ class Morpheus::Cli::Instances
|
|
476
514
|
connect(options)
|
477
515
|
begin
|
478
516
|
instance = find_instance_by_name(args[0])
|
479
|
-
|
517
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to restart this instance?", options)
|
480
518
|
exit 1
|
481
519
|
end
|
482
520
|
json_response = @instances_interface.restart(instance['id'])
|
@@ -486,7 +524,7 @@ class Morpheus::Cli::Instances
|
|
486
524
|
end
|
487
525
|
return
|
488
526
|
rescue RestClient::Exception => e
|
489
|
-
|
527
|
+
print_rest_exception(e, options)
|
490
528
|
exit 1
|
491
529
|
end
|
492
530
|
end
|
@@ -495,7 +533,7 @@ class Morpheus::Cli::Instances
|
|
495
533
|
options = {}
|
496
534
|
optparse = OptionParser.new do|opts|
|
497
535
|
opts.banner = "Usage: morpheus instances stop-service [name]"
|
498
|
-
|
536
|
+
build_common_options(opts, options, [:auto_confirm, :json, :remote])
|
499
537
|
end
|
500
538
|
if args.count < 1
|
501
539
|
puts "\n#{optparse.banner}\n\n"
|
@@ -505,7 +543,7 @@ class Morpheus::Cli::Instances
|
|
505
543
|
connect(options)
|
506
544
|
begin
|
507
545
|
instance = find_instance_by_name(args[0])
|
508
|
-
|
546
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to stop this instance?", options)
|
509
547
|
exit 1
|
510
548
|
end
|
511
549
|
json_response = @instances_interface.stop(instance['id'],false)
|
@@ -517,7 +555,7 @@ class Morpheus::Cli::Instances
|
|
517
555
|
end
|
518
556
|
return
|
519
557
|
rescue RestClient::Exception => e
|
520
|
-
|
558
|
+
print_rest_exception(e, options)
|
521
559
|
exit 1
|
522
560
|
end
|
523
561
|
end
|
@@ -526,7 +564,7 @@ class Morpheus::Cli::Instances
|
|
526
564
|
options = {}
|
527
565
|
optparse = OptionParser.new do|opts|
|
528
566
|
opts.banner = "Usage: morpheus instances start-service [name]"
|
529
|
-
|
567
|
+
build_common_options(opts, options, [:json, :remote])
|
530
568
|
end
|
531
569
|
if args.count < 1
|
532
570
|
puts "\n#{optparse.banner}\n\n"
|
@@ -545,7 +583,7 @@ class Morpheus::Cli::Instances
|
|
545
583
|
end
|
546
584
|
return
|
547
585
|
rescue RestClient::Exception => e
|
548
|
-
|
586
|
+
print_rest_exception(e, options)
|
549
587
|
exit 1
|
550
588
|
end
|
551
589
|
end
|
@@ -554,7 +592,7 @@ class Morpheus::Cli::Instances
|
|
554
592
|
options = {}
|
555
593
|
optparse = OptionParser.new do|opts|
|
556
594
|
opts.banner = "Usage: morpheus instances restart-service [name]"
|
557
|
-
|
595
|
+
build_common_options(opts, options, [:auto_confirm, :json, :remote])
|
558
596
|
end
|
559
597
|
if args.count < 1
|
560
598
|
puts "\n#{optparse.banner}\n\n"
|
@@ -564,7 +602,7 @@ class Morpheus::Cli::Instances
|
|
564
602
|
connect(options)
|
565
603
|
begin
|
566
604
|
instance = find_instance_by_name(args[0])
|
567
|
-
|
605
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to restart this instance?", options)
|
568
606
|
exit 1
|
569
607
|
end
|
570
608
|
json_response = @instances_interface.restart(instance['id'],false)
|
@@ -576,7 +614,95 @@ class Morpheus::Cli::Instances
|
|
576
614
|
end
|
577
615
|
return
|
578
616
|
rescue RestClient::Exception => e
|
579
|
-
|
617
|
+
print_rest_exception(e, options)
|
618
|
+
exit 1
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
622
|
+
def resize(args)
|
623
|
+
options = {}
|
624
|
+
optparse = OptionParser.new do|opts|
|
625
|
+
opts.banner = "Usage: morpheus instances resize [name]"
|
626
|
+
build_common_options(opts, options, [:options, :json, :remote])
|
627
|
+
end
|
628
|
+
if args.count < 1
|
629
|
+
puts "\n#{optparse.banner}\n\n"
|
630
|
+
exit 1
|
631
|
+
end
|
632
|
+
optparse.parse(args)
|
633
|
+
connect(options)
|
634
|
+
begin
|
635
|
+
instance = find_instance_by_name(args[0])
|
636
|
+
|
637
|
+
group_id = instance['group']['id']
|
638
|
+
cloud_id = instance['cloud']['id']
|
639
|
+
layout_id = instance['layout']['id']
|
640
|
+
|
641
|
+
plan_id = instance['plan']['id']
|
642
|
+
payload = {}
|
643
|
+
|
644
|
+
# avoid 500 error
|
645
|
+
payload[:servicePlanOptions] = {}
|
646
|
+
|
647
|
+
puts "\nDue to limitations by most Guest Operating Systems, Disk sizes can only be expanded and not reduced.\nIf a smaller plan is selected, memory and CPU (if relevant) will be reduced but storage will not.\n\n"
|
648
|
+
|
649
|
+
|
650
|
+
#plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'servicePlan', 'type' => 'select', 'fieldLabel' => 'Plan', 'optionSource' => 'instanceServicePlans', 'required' => true, 'description' => 'Choose the appropriately sized plan for this instance'}],options[:options],@api_client,{groupId: groupId, zoneId: cloud, instanceTypeId: instance_type['id'], layoutId: layout_id, version: version_prompt['version']})
|
651
|
+
available_plans_result = @options_interface.options_for_source('instanceServicePlans',{groupId: group_id, zoneId: cloud_id, instanceTypeId: instance['instanceType']['id'], layoutId: layout_id, version: instance['instanceVersion']})
|
652
|
+
available_plans = available_plans_result['data']
|
653
|
+
available_plans.each do |plan|
|
654
|
+
if plan['value'] && plan['value'].to_i == plan_id.to_i
|
655
|
+
plan['name'] = "#{plan['name']} (current)"
|
656
|
+
end
|
657
|
+
end
|
658
|
+
|
659
|
+
plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'servicePlan', 'type' => 'select', 'fieldLabel' => 'New Plan', 'selectOptions' => available_plans, 'required' => true, 'description' => 'Choose the new plan for this instance'}],options[:options] )
|
660
|
+
new_plan_id = plan_prompt['servicePlan']
|
661
|
+
payload[:servicePlanId] = new_plan_id
|
662
|
+
|
663
|
+
volumes_response = @instances_interface.volumes(instance['id'])
|
664
|
+
current_volumes = volumes_response['volumes'].sort {|x,y| x['displayOrder'] <=> y['displayOrder'] }
|
665
|
+
|
666
|
+
begin
|
667
|
+
service_plan_options_json = @instance_types_interface.service_plan_options(new_plan_id, {cloudId: cloud_id, zoneId: cloud_id, layoutId: layout_id})
|
668
|
+
|
669
|
+
# puts ""
|
670
|
+
# print JSON.pretty_generate(service_plan_options_json)
|
671
|
+
|
672
|
+
plan_options = service_plan_options_json['plan']
|
673
|
+
volumes = prompt_resize_instance_volumes(current_volumes, plan_options, options, @api_client, {})
|
674
|
+
|
675
|
+
# puts "VOLUMES:"
|
676
|
+
# print JSON.pretty_generate(volumes)
|
677
|
+
|
678
|
+
if !volumes.empty?
|
679
|
+
payload[:volumes] = volumes
|
680
|
+
end
|
681
|
+
|
682
|
+
# puts "\nexiting early...\n"
|
683
|
+
# exit 1
|
684
|
+
|
685
|
+
rescue RestClient::Exception => e
|
686
|
+
print_red_alert "Unable to load options for selected plan."
|
687
|
+
print_rest_exception(e, options)
|
688
|
+
exit 1
|
689
|
+
end
|
690
|
+
|
691
|
+
# only amazon supports this option
|
692
|
+
# for now, always do this
|
693
|
+
payload[:deleteOriginalVolumes] = true
|
694
|
+
|
695
|
+
json_response = @instances_interface.resize(instance['id'], payload)
|
696
|
+
if options[:json]
|
697
|
+
print JSON.pretty_generate(json_response)
|
698
|
+
print "\n"
|
699
|
+
else
|
700
|
+
print_green_success "Resizing instance #{instance['name']}"
|
701
|
+
list([])
|
702
|
+
end
|
703
|
+
|
704
|
+
rescue RestClient::Exception => e
|
705
|
+
print_rest_exception(e, options)
|
580
706
|
exit 1
|
581
707
|
end
|
582
708
|
end
|
@@ -585,9 +711,12 @@ class Morpheus::Cli::Instances
|
|
585
711
|
options = {}
|
586
712
|
optparse = OptionParser.new do|opts|
|
587
713
|
opts.banner = "Usage: morpheus instances backup [name]"
|
588
|
-
|
714
|
+
build_common_options(opts, options, [:json, :remote])
|
715
|
+
end
|
716
|
+
if args.count < 1
|
717
|
+
puts "\n#{optparse.banner}\n\n"
|
718
|
+
exit 1
|
589
719
|
end
|
590
|
-
puts "\n#{optparse.banner}\n\n" and exit 1 if args.count < 1
|
591
720
|
optparse.parse(args)
|
592
721
|
connect(options)
|
593
722
|
begin
|
@@ -601,7 +730,7 @@ class Morpheus::Cli::Instances
|
|
601
730
|
end
|
602
731
|
return
|
603
732
|
rescue RestClient::Exception => e
|
604
|
-
|
733
|
+
print_rest_exception(e, options)
|
605
734
|
exit 1
|
606
735
|
end
|
607
736
|
end
|
@@ -612,7 +741,7 @@ class Morpheus::Cli::Instances
|
|
612
741
|
opts.on( '-g', '--group GROUP', "Group Name" ) do |group|
|
613
742
|
options[:group] = group
|
614
743
|
end
|
615
|
-
|
744
|
+
build_common_options(opts, options, [:list, :json, :remote])
|
616
745
|
end
|
617
746
|
optparse.parse(args)
|
618
747
|
connect(options)
|
@@ -624,14 +753,8 @@ class Morpheus::Cli::Instances
|
|
624
753
|
params['site'] = group
|
625
754
|
end
|
626
755
|
end
|
627
|
-
|
628
|
-
params[
|
629
|
-
end
|
630
|
-
if !options[:offset].nil?
|
631
|
-
params['offset'] = options[:offset]
|
632
|
-
end
|
633
|
-
if !options[:phrase].nil?
|
634
|
-
params['phrase'] = options[:phrase]
|
756
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
757
|
+
params[k] = options[k] unless options[k].nil?
|
635
758
|
end
|
636
759
|
|
637
760
|
json_response = @instances_interface.get(params)
|
@@ -661,15 +784,15 @@ class Morpheus::Cli::Instances
|
|
661
784
|
if !instance['connectionInfo'].nil? && instance['connectionInfo'].empty? == false
|
662
785
|
connection_string = "#{instance['connectionInfo'][0]['ip']}:#{instance['connectionInfo'][0]['port']}"
|
663
786
|
end
|
664
|
-
{id: instance['id'], name: instance['name'], connection: connection_string, environment: instance['instanceContext'], nodes: instance['containers'].count, status: status_string, type: instance['instanceType']['name'], group: !instance['group'].nil? ? instance['group']['name'] : nil}
|
787
|
+
{id: instance['id'], name: instance['name'], connection: connection_string, environment: instance['instanceContext'], nodes: instance['containers'].count, status: status_string, type: instance['instanceType']['name'], group: !instance['group'].nil? ? instance['group']['name'] : nil, cloud: !instance['cloud'].nil? ? instance['cloud']['name'] : nil}
|
665
788
|
end
|
666
|
-
tp instance_table, :id, :name
|
789
|
+
tp instance_table, :id, :name, :group, :cloud, :type, :environment, :nodes, :connection, :status
|
667
790
|
end
|
668
791
|
print reset,"\n\n"
|
669
792
|
end
|
670
793
|
|
671
794
|
rescue RestClient::Exception => e
|
672
|
-
|
795
|
+
print_rest_exception(e, options)
|
673
796
|
exit 1
|
674
797
|
end
|
675
798
|
end
|
@@ -685,7 +808,7 @@ class Morpheus::Cli::Instances
|
|
685
808
|
opts.on( '-B', '--keep-backups', "Preserve copy of backups" ) do
|
686
809
|
query_params[:keepBackups] = 'on'
|
687
810
|
end
|
688
|
-
|
811
|
+
build_common_options(opts, options, [:auto_confirm, :json, :remote])
|
689
812
|
|
690
813
|
end
|
691
814
|
if args.count < 1
|
@@ -696,13 +819,13 @@ class Morpheus::Cli::Instances
|
|
696
819
|
connect(options)
|
697
820
|
begin
|
698
821
|
instance = find_instance_by_name(args[0])
|
699
|
-
|
822
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to remove this instance?", options)
|
700
823
|
exit 1
|
701
824
|
end
|
702
825
|
@instances_interface.destroy(instance['id'],query_params)
|
703
826
|
list([])
|
704
827
|
rescue RestClient::Exception => e
|
705
|
-
|
828
|
+
print_rest_exception(e, options)
|
706
829
|
exit 1
|
707
830
|
end
|
708
831
|
end
|
@@ -711,7 +834,7 @@ class Morpheus::Cli::Instances
|
|
711
834
|
options = {}
|
712
835
|
optparse = OptionParser.new do|opts|
|
713
836
|
opts.banner = "Usage: morpheus instances firewall-disable [name]"
|
714
|
-
|
837
|
+
build_common_options(opts, options, [:json, :remote])
|
715
838
|
end
|
716
839
|
if args.count < 1
|
717
840
|
puts "\n#{optparse.banner}\n\n"
|
@@ -724,7 +847,7 @@ class Morpheus::Cli::Instances
|
|
724
847
|
@instances_interface.firewall_disable(instance['id'])
|
725
848
|
security_groups([args[0]])
|
726
849
|
rescue RestClient::Exception => e
|
727
|
-
|
850
|
+
print_rest_exception(e, options)
|
728
851
|
exit 1
|
729
852
|
end
|
730
853
|
end
|
@@ -733,7 +856,7 @@ class Morpheus::Cli::Instances
|
|
733
856
|
options = {}
|
734
857
|
optparse = OptionParser.new do|opts|
|
735
858
|
opts.banner = "Usage: morpheus instances firewall-enable [name]"
|
736
|
-
|
859
|
+
build_common_options(opts, options, [:json, :remote])
|
737
860
|
end
|
738
861
|
if args.count < 1
|
739
862
|
puts "\n#{optparse.banner}\n\n"
|
@@ -750,7 +873,7 @@ class Morpheus::Cli::Instances
|
|
750
873
|
@instances_interface.firewall_enable(instance_results['instances'][0]['id'])
|
751
874
|
security_groups([args[0]])
|
752
875
|
rescue RestClient::Exception => e
|
753
|
-
|
876
|
+
print_rest_exception(e, options)
|
754
877
|
exit 1
|
755
878
|
end
|
756
879
|
end
|
@@ -759,7 +882,7 @@ class Morpheus::Cli::Instances
|
|
759
882
|
options = {}
|
760
883
|
optparse = OptionParser.new do|opts|
|
761
884
|
opts.banner = "Usage: morpheus instances security-groups [name]"
|
762
|
-
|
885
|
+
build_common_options(opts, options, [:json, :remote])
|
763
886
|
end
|
764
887
|
if args.count < 1
|
765
888
|
puts "\n#{optparse.banner}\n\n"
|
@@ -785,7 +908,7 @@ class Morpheus::Cli::Instances
|
|
785
908
|
print reset,"\n\n"
|
786
909
|
|
787
910
|
rescue RestClient::Exception => e
|
788
|
-
|
911
|
+
print_rest_exception(e, options)
|
789
912
|
exit 1
|
790
913
|
end
|
791
914
|
end
|
@@ -803,7 +926,7 @@ class Morpheus::Cli::Instances
|
|
803
926
|
options[:securityGroupIds] = secgroups.split(",")
|
804
927
|
clear_or_secgroups_specified = true
|
805
928
|
end
|
806
|
-
|
929
|
+
build_common_options(opts, options, [:json, :remote])
|
807
930
|
end
|
808
931
|
if args.count < 1
|
809
932
|
puts "\n#{optparse.banner}\n\n"
|
@@ -822,7 +945,7 @@ class Morpheus::Cli::Instances
|
|
822
945
|
@instances_interface.apply_security_groups(instance['id'], options)
|
823
946
|
security_groups([args[0]])
|
824
947
|
rescue RestClient::Exception => e
|
825
|
-
|
948
|
+
print_rest_exception(e, options)
|
826
949
|
exit 1
|
827
950
|
end
|
828
951
|
end
|
@@ -833,7 +956,7 @@ class Morpheus::Cli::Instances
|
|
833
956
|
|
834
957
|
optparse = OptionParser.new do|opts|
|
835
958
|
opts.banner = "Usage: morpheus instances run-workflow [INSTANCE] [name] [options]"
|
836
|
-
|
959
|
+
build_common_options(opts, options, [:options, :json, :remote])
|
837
960
|
end
|
838
961
|
if args.count < 2
|
839
962
|
puts "\n#{optparse}\n\n"
|
@@ -877,7 +1000,7 @@ class Morpheus::Cli::Instances
|
|
877
1000
|
puts "Running workflow..."
|
878
1001
|
end
|
879
1002
|
rescue RestClient::Exception => e
|
880
|
-
|
1003
|
+
print_rest_exception(e, options)
|
881
1004
|
exit 1
|
882
1005
|
end
|
883
1006
|
end
|
@@ -887,7 +1010,7 @@ private
|
|
887
1010
|
def find_instance_by_name(name)
|
888
1011
|
instance_results = @instances_interface.get({name: name})
|
889
1012
|
if instance_results['instances'].empty?
|
890
|
-
|
1013
|
+
print_red_alert "Instance not found by name #{name}"
|
891
1014
|
exit 1
|
892
1015
|
end
|
893
1016
|
return instance_results['instances'][0]
|
@@ -897,7 +1020,7 @@ private
|
|
897
1020
|
if !task_set_results['taskSets'].nil? && !task_set_results['taskSets'].empty?
|
898
1021
|
return task_set_results['taskSets'][0]
|
899
1022
|
else
|
900
|
-
|
1023
|
+
print_red_alert "Workflow not found by name #{name}"
|
901
1024
|
exit 1
|
902
1025
|
end
|
903
1026
|
end
|