morpheus-cli 3.5.1.1 → 3.5.1.2
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 +6 -2
- data/lib/morpheus/api/execute_schedules_interface.rb +78 -0
- data/lib/morpheus/api/{power_scheduling_interface.rb → power_schedules_interface.rb} +10 -10
- data/lib/morpheus/cli.rb +2 -1
- data/lib/morpheus/cli/archives_command.rb +24 -18
- data/lib/morpheus/cli/curl_command.rb +28 -4
- data/lib/morpheus/cli/execute_schedules_command.rb +727 -0
- data/lib/morpheus/cli/image_builder_command.rb +36 -16
- data/lib/morpheus/cli/policies_command.rb +12 -4
- data/lib/morpheus/cli/{power_scheduling_command.rb → power_schedules_command.rb} +34 -38
- data/lib/morpheus/cli/shell.rb +8 -6
- data/lib/morpheus/cli/version.rb +1 -1
- metadata +6 -4
@@ -342,7 +342,7 @@ class Morpheus::Cli::ImageBuilderCommand
|
|
342
342
|
opts.on('--keepResults VALUE', String, "Keep only the most recent builds. Older executions will be deleted along with their associated Virtual Images. The value 0 disables this functionality.") do |val|
|
343
343
|
options['keepResults'] = val.to_i
|
344
344
|
end
|
345
|
-
build_common_options(opts, options, [:options, :json, :dry_run, :quiet])
|
345
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet])
|
346
346
|
end
|
347
347
|
optparse.parse!(args)
|
348
348
|
if args.count > 1
|
@@ -351,20 +351,29 @@ class Morpheus::Cli::ImageBuilderCommand
|
|
351
351
|
end
|
352
352
|
connect(options)
|
353
353
|
begin
|
354
|
-
|
354
|
+
payload = nil
|
355
|
+
if options[:payload]
|
356
|
+
payload = options[:payload]
|
357
|
+
# support options top of --payload
|
358
|
+
options.merge!(options[:options]) if options[:options] # so -O var= works..
|
359
|
+
option_params = options.reject {|k,v| k.is_a?(Symbol) }
|
360
|
+
payload.deep_merge!({'imageBuild' => option_params}) unless option_params.empty?
|
361
|
+
else
|
362
|
+
options.merge!(options[:options]) if options[:options] # so -O var= works..
|
363
|
+
|
364
|
+
# use the -g GROUP or active group by default
|
365
|
+
# options['group'] ||= @active_group_id
|
366
|
+
|
367
|
+
# support first arg as name instead of --name
|
368
|
+
if args[0] && !options['name']
|
369
|
+
options['name'] = args[0]
|
370
|
+
end
|
355
371
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
# support first arg as name instead of --name
|
360
|
-
if args[0] && !options['name']
|
361
|
-
options['name'] = args[0]
|
372
|
+
image_build_payload = prompt_new_image_build(options)
|
373
|
+
return 1 if !image_build_payload
|
374
|
+
payload = {'imageBuild' => image_build_payload}
|
362
375
|
end
|
363
376
|
|
364
|
-
image_build_payload = prompt_new_image_build(options)
|
365
|
-
return 1 if !image_build_payload
|
366
|
-
payload = {'imageBuild' => image_build_payload}
|
367
|
-
|
368
377
|
if options[:dry_run]
|
369
378
|
print_dry_run @image_builds_interface.dry.create(payload)
|
370
379
|
return
|
@@ -461,7 +470,7 @@ class Morpheus::Cli::ImageBuilderCommand
|
|
461
470
|
# 0 disables it
|
462
471
|
# options['deleteOldResults'] = (options['keepResults'] > 0)
|
463
472
|
end
|
464
|
-
build_common_options(opts, options, [:options, :json, :dry_run, :quiet])
|
473
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet])
|
465
474
|
end
|
466
475
|
optparse.parse!(args)
|
467
476
|
if args.count != 1
|
@@ -472,9 +481,20 @@ class Morpheus::Cli::ImageBuilderCommand
|
|
472
481
|
begin
|
473
482
|
image_build = find_image_build_by_name_or_id(args[0])
|
474
483
|
return 1 if !image_build
|
475
|
-
|
476
|
-
|
477
|
-
|
484
|
+
payload = nil
|
485
|
+
if options[:payload]
|
486
|
+
payload = options[:payload]
|
487
|
+
# support options top of --payload
|
488
|
+
options.merge!(options[:options]) if options[:options] # so -O var= works..
|
489
|
+
option_params = options.reject {|k,v| k.is_a?(Symbol) }
|
490
|
+
payload.deep_merge!({'imageBuild' => option_params}) unless option_params.empty?
|
491
|
+
else
|
492
|
+
options.merge!(options[:options]) if options[:options] # so -O var= works..
|
493
|
+
image_build_payload = prompt_edit_image_build(image_build, options)
|
494
|
+
return 1 if !image_build_payload
|
495
|
+
payload = {'imageBuild' => image_build_payload}
|
496
|
+
end
|
497
|
+
|
478
498
|
if options[:dry_run]
|
479
499
|
print_dry_run @image_builds_interface.dry.update(image_build["id"], payload)
|
480
500
|
return
|
@@ -58,7 +58,7 @@ class Morpheus::Cli::PoliciesCommand
|
|
58
58
|
opts.on( '-G', '--global', "Global policies only" ) do
|
59
59
|
params[:global] = true
|
60
60
|
end
|
61
|
-
build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :
|
61
|
+
build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
62
62
|
opts.footer = "List policies."
|
63
63
|
end
|
64
64
|
optparse.parse!(args)
|
@@ -390,7 +390,8 @@ class Morpheus::Cli::PoliciesCommand
|
|
390
390
|
return 1
|
391
391
|
end
|
392
392
|
# payload['policy']['policyTypeId'] = policy_type['id']
|
393
|
-
payload['policy']['policyType'] = {'id' => policy_type['id']}
|
393
|
+
# payload['policy']['policyType'] = {'id' => policy_type['id']}
|
394
|
+
payload['policy']['policyType'] = {'code' => policy_type['code']}
|
394
395
|
|
395
396
|
# Scope
|
396
397
|
if user
|
@@ -692,7 +693,7 @@ class Morpheus::Cli::PoliciesCommand
|
|
692
693
|
options = {}
|
693
694
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
694
695
|
opts.banner = subcommand_usage()
|
695
|
-
build_common_options(opts, options, [:json, :dry_run, :remote])
|
696
|
+
build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
|
696
697
|
opts.footer = "List policy types."
|
697
698
|
end
|
698
699
|
optparse.parse!(args)
|
@@ -712,7 +713,14 @@ class Morpheus::Cli::PoliciesCommand
|
|
712
713
|
json_response = @policies_interface.list_policy_types()
|
713
714
|
policy_types = json_response['policyTypes']
|
714
715
|
if options[:json]
|
715
|
-
puts as_json(json_response)
|
716
|
+
puts as_json(json_response, options, "policyTypes")
|
717
|
+
return 0
|
718
|
+
elsif options[:yaml]
|
719
|
+
puts as_yaml(json_response, options, "policyTypes")
|
720
|
+
return 0
|
721
|
+
elsif options[:csv]
|
722
|
+
puts records_as_csv(policy_types, options)
|
723
|
+
return 0
|
716
724
|
else
|
717
725
|
print_h1 "Morpheus Policy Types"
|
718
726
|
rows = policy_types.collect {|policy_type|
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'morpheus/cli/cli_command'
|
2
2
|
|
3
|
-
class Morpheus::Cli::
|
3
|
+
class Morpheus::Cli::PowerSchedulesCommand
|
4
4
|
include Morpheus::Cli::CliCommand
|
5
5
|
# include Morpheus::Cli::ProvisioningHelper
|
6
|
-
|
7
|
-
# this is the only type of schedule right now
|
8
|
-
#set_command_name :'schedules'
|
9
|
-
#set_command_name :'scheduling'
|
10
|
-
set_command_name :'power-scheduling'
|
6
|
+
set_command_name :'power-schedules'
|
11
7
|
|
12
8
|
register_subcommands :list, :get, :add, :update, :remove
|
13
9
|
register_subcommands :'add-instances' => :add_instances
|
@@ -17,7 +13,7 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
17
13
|
|
18
14
|
def connect(opts)
|
19
15
|
@api_client = establish_remote_appliance_connection(opts)
|
20
|
-
@
|
16
|
+
@power_schedules_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).power_schedules
|
21
17
|
@instances_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instances
|
22
18
|
@servers_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).servers
|
23
19
|
end
|
@@ -38,21 +34,21 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
38
34
|
begin
|
39
35
|
params.merge!(parse_list_options(options))
|
40
36
|
if options[:dry_run]
|
41
|
-
print_dry_run @
|
37
|
+
print_dry_run @power_schedules_interface.dry.list(params)
|
42
38
|
return
|
43
39
|
end
|
44
|
-
json_response = @
|
40
|
+
json_response = @power_schedules_interface.list(params)
|
45
41
|
if options[:json]
|
46
|
-
puts as_json(json_response, options, "
|
42
|
+
puts as_json(json_response, options, "schedules")
|
47
43
|
return 0
|
48
44
|
elsif options[:csv]
|
49
|
-
puts records_as_csv(json_response['
|
45
|
+
puts records_as_csv(json_response['schedules'], options)
|
50
46
|
return 0
|
51
47
|
elsif options[:yaml]
|
52
|
-
puts as_yaml(json_response, options, "
|
48
|
+
puts as_yaml(json_response, options, "schedules")
|
53
49
|
return 0
|
54
50
|
end
|
55
|
-
schedules = json_response['
|
51
|
+
schedules = json_response['schedules']
|
56
52
|
title = "Morpheus Power Schedules"
|
57
53
|
subtitles = []
|
58
54
|
subtitles += parse_list_subtitles(options)
|
@@ -107,18 +103,18 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
107
103
|
return 1
|
108
104
|
end
|
109
105
|
if options[:dry_run]
|
110
|
-
print_dry_run @
|
106
|
+
print_dry_run @power_schedules_interface.dry.get(schedule['id'])
|
111
107
|
return
|
112
108
|
end
|
113
|
-
json_response = @
|
114
|
-
schedule = json_response['
|
109
|
+
json_response = @power_schedules_interface.get(schedule['id'])
|
110
|
+
schedule = json_response['schedule']
|
115
111
|
instances = json_response['instances'] || []
|
116
112
|
servers = json_response['servers'] || []
|
117
113
|
if options[:json]
|
118
|
-
puts as_json(json_response, options, "
|
114
|
+
puts as_json(json_response, options, "schedule")
|
119
115
|
return 0
|
120
116
|
elsif options[:yaml]
|
121
|
-
puts as_yaml(json_response, options, "
|
117
|
+
puts as_yaml(json_response, options, "schedule")
|
122
118
|
return 0
|
123
119
|
elsif options[:csv]
|
124
120
|
puts records_as_csv([json_response['schedule']], options)
|
@@ -236,10 +232,10 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
236
232
|
payload = {'schedule' => params}
|
237
233
|
end
|
238
234
|
if options[:dry_run]
|
239
|
-
print_dry_run @
|
235
|
+
print_dry_run @power_schedules_interface.dry.create(payload)
|
240
236
|
return
|
241
237
|
end
|
242
|
-
json_response = @
|
238
|
+
json_response = @power_schedules_interface.create(payload)
|
243
239
|
if options[:json]
|
244
240
|
puts as_json(json_response, options)
|
245
241
|
elsif !options[:quiet]
|
@@ -311,13 +307,13 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
311
307
|
else
|
312
308
|
# merge -O options into normally parsed options
|
313
309
|
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
314
|
-
payload = {'
|
310
|
+
payload = {'schedule' => params}
|
315
311
|
end
|
316
312
|
if options[:dry_run]
|
317
|
-
print_dry_run @
|
313
|
+
print_dry_run @power_schedules_interface.dry.update(schedule["id"], payload)
|
318
314
|
return
|
319
315
|
end
|
320
|
-
json_response = @
|
316
|
+
json_response = @power_schedules_interface.update(schedule["id"], payload)
|
321
317
|
if options[:json]
|
322
318
|
puts as_json(json_response, options)
|
323
319
|
elsif !options[:quiet]
|
@@ -356,17 +352,17 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
356
352
|
end
|
357
353
|
|
358
354
|
# payload = {
|
359
|
-
# '
|
355
|
+
# 'schedule' => {id: schedule["id"]}
|
360
356
|
# }
|
361
|
-
# payload['
|
357
|
+
# payload['schedule'].merge!(schedule)
|
362
358
|
payload = params
|
363
359
|
|
364
360
|
if options[:dry_run]
|
365
|
-
print_dry_run @
|
361
|
+
print_dry_run @power_schedules_interface.dry.destroy(schedule["id"])
|
366
362
|
return
|
367
363
|
end
|
368
364
|
|
369
|
-
json_response = @
|
365
|
+
json_response = @power_schedules_interface.destroy(schedule["id"])
|
370
366
|
if options[:json]
|
371
367
|
puts as_json(json_response, options)
|
372
368
|
elsif !options[:quiet]
|
@@ -416,10 +412,10 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
416
412
|
payload = {'instances' => instances.collect {|it| it['id'] } }
|
417
413
|
end
|
418
414
|
if options[:dry_run]
|
419
|
-
print_dry_run @
|
415
|
+
print_dry_run @power_schedules_interface.dry.add_instances(schedule["id"], payload)
|
420
416
|
return 0
|
421
417
|
end
|
422
|
-
json_response = @
|
418
|
+
json_response = @power_schedules_interface.add_instances(schedule["id"], payload)
|
423
419
|
if options[:json]
|
424
420
|
puts as_json(json_response, options)
|
425
421
|
elsif !options[:quiet]
|
@@ -474,10 +470,10 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
474
470
|
payload = {'instances' => instances.collect {|it| it['id'] } }
|
475
471
|
end
|
476
472
|
if options[:dry_run]
|
477
|
-
print_dry_run @
|
473
|
+
print_dry_run @power_schedules_interface.dry.remove_instances(schedule["id"], payload)
|
478
474
|
return 0
|
479
475
|
end
|
480
|
-
json_response = @
|
476
|
+
json_response = @power_schedules_interface.remove_instances(schedule["id"], payload)
|
481
477
|
if options[:json]
|
482
478
|
puts as_json(json_response, options)
|
483
479
|
elsif !options[:quiet]
|
@@ -532,10 +528,10 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
532
528
|
payload = {'servers' => servers.collect {|it| it['id'] } }
|
533
529
|
end
|
534
530
|
if options[:dry_run]
|
535
|
-
print_dry_run @
|
531
|
+
print_dry_run @power_schedules_interface.dry.add_servers(schedule["id"], payload)
|
536
532
|
return 0
|
537
533
|
end
|
538
|
-
json_response = @
|
534
|
+
json_response = @power_schedules_interface.add_servers(schedule["id"], payload)
|
539
535
|
if options[:json]
|
540
536
|
puts as_json(json_response, options)
|
541
537
|
elsif !options[:quiet]
|
@@ -590,10 +586,10 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
590
586
|
payload = {'servers' => servers.collect {|it| it['id'] } }
|
591
587
|
end
|
592
588
|
if options[:dry_run]
|
593
|
-
print_dry_run @
|
589
|
+
print_dry_run @power_schedules_interface.dry.remove_servers(schedule["id"], payload)
|
594
590
|
return 0
|
595
591
|
end
|
596
|
-
json_response = @
|
592
|
+
json_response = @power_schedules_interface.remove_servers(schedule["id"], payload)
|
597
593
|
if options[:json]
|
598
594
|
puts as_json(json_response, options)
|
599
595
|
elsif !options[:quiet]
|
@@ -624,8 +620,8 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
624
620
|
|
625
621
|
def find_schedule_by_id(id)
|
626
622
|
begin
|
627
|
-
json_response = @
|
628
|
-
return json_response['
|
623
|
+
json_response = @power_schedules_interface.get(id.to_i)
|
624
|
+
return json_response['schedule']
|
629
625
|
rescue RestClient::Exception => e
|
630
626
|
if e.response && e.response.code == 404
|
631
627
|
print_red_alert "Power Schedule not found by id #{id}"
|
@@ -636,7 +632,7 @@ class Morpheus::Cli::PowerSchedulingCommand
|
|
636
632
|
end
|
637
633
|
|
638
634
|
def find_schedule_by_name(name)
|
639
|
-
schedules = @
|
635
|
+
schedules = @power_schedules_interface.list({name: name.to_s})['schedules']
|
640
636
|
if schedules.empty?
|
641
637
|
print_red_alert "Power Schedule not found by name #{name}"
|
642
638
|
return nil
|
data/lib/morpheus/cli/shell.rb
CHANGED
@@ -335,6 +335,7 @@ class Morpheus::Cli::Shell
|
|
335
335
|
end
|
336
336
|
|
337
337
|
def execute_command(input)
|
338
|
+
|
338
339
|
#Morpheus::Logging::DarkPrinter.puts "Shell command: #{input}"
|
339
340
|
input = input.to_s.strip
|
340
341
|
|
@@ -529,6 +530,7 @@ class Morpheus::Cli::Shell
|
|
529
530
|
return Morpheus::Cli::SourceCommand.new.handle(input.split[1..-1])
|
530
531
|
end
|
531
532
|
cmd_result = nil
|
533
|
+
@return_to_log_level = Morpheus::Logging.log_level
|
532
534
|
begin
|
533
535
|
argv = Shellwords.shellsplit(input)
|
534
536
|
cmd_name = argv[0]
|
@@ -553,12 +555,12 @@ class Morpheus::Cli::Shell
|
|
553
555
|
@history_logger.error "#{e.message}" if @history_logger
|
554
556
|
cmd_result = Morpheus::Cli::ErrorHandler.new(my_terminal.stderr).handle_error(e) # lol
|
555
557
|
# exit 1
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
558
|
+
ensure
|
559
|
+
if @return_to_log_level
|
560
|
+
Morpheus::Logging.set_log_level(@return_to_log_level)
|
561
|
+
::RestClient.log = Morpheus::Logging.debug? ? Morpheus::Logging::DarkPrinter.instance : nil
|
562
|
+
@return_to_log_level = nil
|
563
|
+
end
|
562
564
|
end
|
563
565
|
|
564
566
|
# commands should be a number or nil (treated as 0)
|
data/lib/morpheus/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morpheus-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.1.
|
4
|
+
version: 3.5.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Estes
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2018-09-
|
14
|
+
date: 2018-09-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/morpheus/api/dashboard_interface.rb
|
174
174
|
- lib/morpheus/api/deploy_interface.rb
|
175
175
|
- lib/morpheus/api/deployments_interface.rb
|
176
|
+
- lib/morpheus/api/execute_schedules_interface.rb
|
176
177
|
- lib/morpheus/api/group_policies_interface.rb
|
177
178
|
- lib/morpheus/api/groups_interface.rb
|
178
179
|
- lib/morpheus/api/image_builder_boot_scripts_interface.rb
|
@@ -209,7 +210,7 @@ files:
|
|
209
210
|
- lib/morpheus/api/options_interface.rb
|
210
211
|
- lib/morpheus/api/packages_interface.rb
|
211
212
|
- lib/morpheus/api/policies_interface.rb
|
212
|
-
- lib/morpheus/api/
|
213
|
+
- lib/morpheus/api/power_schedules_interface.rb
|
213
214
|
- lib/morpheus/api/provision_types_interface.rb
|
214
215
|
- lib/morpheus/api/roles_interface.rb
|
215
216
|
- lib/morpheus/api/security_group_rules_interface.rb
|
@@ -251,6 +252,7 @@ files:
|
|
251
252
|
- lib/morpheus/cli/edit_profile_command.rb
|
252
253
|
- lib/morpheus/cli/edit_rc_command.rb
|
253
254
|
- lib/morpheus/cli/error_handler.rb
|
255
|
+
- lib/morpheus/cli/execute_schedules_command.rb
|
254
256
|
- lib/morpheus/cli/expression_parser.rb
|
255
257
|
- lib/morpheus/cli/groups.rb
|
256
258
|
- lib/morpheus/cli/hosts.rb
|
@@ -296,7 +298,7 @@ files:
|
|
296
298
|
- lib/morpheus/cli/option_types.rb
|
297
299
|
- lib/morpheus/cli/packages_command.rb
|
298
300
|
- lib/morpheus/cli/policies_command.rb
|
299
|
-
- lib/morpheus/cli/
|
301
|
+
- lib/morpheus/cli/power_schedules_command.rb
|
300
302
|
- lib/morpheus/cli/preseed_scripts_command.rb
|
301
303
|
- lib/morpheus/cli/recent_activity_command.rb
|
302
304
|
- lib/morpheus/cli/remote.rb
|