morpheus-cli 5.5.0 → 5.5.1
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.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/lib/morpheus/api/api_client.rb +4 -0
- data/lib/morpheus/api/clusters_interface.rb +12 -0
- data/lib/morpheus/api/network_pool_servers_interface.rb +7 -0
- data/lib/morpheus/api/scale_thresholds_interface.rb +9 -0
- data/lib/morpheus/cli/cli_command.rb +39 -20
- data/lib/morpheus/cli/commands/apps.rb +1 -1
- data/lib/morpheus/cli/commands/cloud_resource_pools_command.rb +33 -2
- data/lib/morpheus/cli/commands/clouds.rb +12 -6
- data/lib/morpheus/cli/commands/clusters.rb +66 -5
- data/lib/morpheus/cli/commands/hosts.rb +5 -1
- data/lib/morpheus/cli/commands/instances.rb +1 -1
- data/lib/morpheus/cli/commands/integrations_command.rb +1 -1
- data/lib/morpheus/cli/commands/invoices_command.rb +8 -1
- data/lib/morpheus/cli/commands/jobs_command.rb +45 -225
- data/lib/morpheus/cli/commands/library_container_types_command.rb +52 -3
- data/lib/morpheus/cli/commands/library_option_types_command.rb +56 -62
- data/lib/morpheus/cli/commands/load_balancers.rb +11 -19
- data/lib/morpheus/cli/commands/network_pool_servers_command.rb +5 -2
- data/lib/morpheus/cli/commands/roles.rb +475 -70
- data/lib/morpheus/cli/commands/scale_thresholds.rb +103 -0
- data/lib/morpheus/cli/commands/tasks.rb +19 -12
- data/lib/morpheus/cli/commands/user_sources_command.rb +107 -39
- data/lib/morpheus/cli/commands/users.rb +10 -10
- data/lib/morpheus/cli/commands/view.rb +1 -0
- data/lib/morpheus/cli/commands/workflows.rb +21 -14
- data/lib/morpheus/cli/error_handler.rb +13 -4
- data/lib/morpheus/cli/mixins/accounts_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/execution_request_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/infrastructure_helper.rb +3 -3
- data/lib/morpheus/cli/mixins/jobs_helper.rb +173 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +120 -38
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +1 -3
- data/lib/morpheus/cli/mixins/rest_command.rb +41 -14
- data/lib/morpheus/cli/option_types.rb +68 -37
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/logging.rb +6 -8
- metadata +6 -4
@@ -2,6 +2,7 @@ require 'morpheus/cli/cli_command'
|
|
2
2
|
|
3
3
|
class Morpheus::Cli::JobsCommand
|
4
4
|
include Morpheus::Cli::CliCommand
|
5
|
+
include Morpheus::Cli::JobsHelper
|
5
6
|
include Morpheus::Cli::AccountsHelper
|
6
7
|
|
7
8
|
set_command_name :'jobs'
|
@@ -90,7 +91,7 @@ class Morpheus::Cli::JobsCommand
|
|
90
91
|
# "Last Updated" => lambda {|job| format_local_dt(job['lastUpdated']) },
|
91
92
|
"Last Run" => lambda {|job| format_local_dt(job['lastRun']) },
|
92
93
|
"Next Run" => lambda {|job| job['enabled'] && job['scheduleMode'] && job['scheduleMode'] != 'manual' ? format_local_dt(job['nextFire']) : '' },
|
93
|
-
"Last Result" => lambda {|job|
|
94
|
+
"Last Result" => lambda {|job| format_job_status(job['lastResult']) },
|
94
95
|
}
|
95
96
|
print as_pretty_table(jobs, columns.upcase_keys!, options)
|
96
97
|
print_results_pagination(json_response)
|
@@ -124,7 +125,7 @@ class Morpheus::Cli::JobsCommand
|
|
124
125
|
options = {}
|
125
126
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
126
127
|
opts.banner = subcommand_usage("[job] [max-exec-count]")
|
127
|
-
|
128
|
+
build_standard_get_options(opts, options)
|
128
129
|
opts.footer = "Get details about a job.\n" +
|
129
130
|
"[job] is required. Job ID or name.\n" +
|
130
131
|
"[max-exec-count] is optional. Specified max # of most recent executions. Defaults is 3"
|
@@ -274,17 +275,13 @@ class Morpheus::Cli::JobsCommand
|
|
274
275
|
options[:schedule] = 'dateTime'
|
275
276
|
params['dateTime'] = val.to_s
|
276
277
|
end
|
277
|
-
|
278
|
+
build_standard_add_options(opts, options)
|
278
279
|
opts.footer = "Create job."
|
279
280
|
end
|
280
281
|
optparse.parse!(args)
|
281
282
|
connect(options)
|
282
|
-
|
283
|
-
raise_command_error "wrong number of arguments, expected 0 or 1 and got (#{args.count}) #{args}\n#{optparse}"
|
284
|
-
return 1
|
285
|
-
end
|
283
|
+
verify_args!(args:args, optparse:optparse, max:1)
|
286
284
|
|
287
|
-
begin
|
288
285
|
if options[:payload]
|
289
286
|
payload = parse_payload(options, 'job')
|
290
287
|
else
|
@@ -425,22 +422,10 @@ class Morpheus::Cli::JobsCommand
|
|
425
422
|
return
|
426
423
|
end
|
427
424
|
json_response = @jobs_interface.create(payload)
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
elsif !options[:quiet]
|
432
|
-
if json_response['success']
|
433
|
-
print_green_success "Job created"
|
434
|
-
_get(json_response['id'], 0, options)
|
435
|
-
else
|
436
|
-
print_red_alert "Error creating job: #{json_response['msg'] || json_response['errors']}"
|
437
|
-
end
|
425
|
+
render_response(json_response, options, 'job') do
|
426
|
+
print_green_success "Job created"
|
427
|
+
_get(json_response['id'], 0, options)
|
438
428
|
end
|
439
|
-
return 0
|
440
|
-
rescue RestClient::Exception => e
|
441
|
-
print_rest_exception(e, options)
|
442
|
-
exit 1
|
443
|
-
end
|
444
429
|
end
|
445
430
|
|
446
431
|
def update(args)
|
@@ -492,18 +477,14 @@ class Morpheus::Cli::JobsCommand
|
|
492
477
|
options[:schedule] = 'dateTime'
|
493
478
|
params['dateTime'] = val.to_s
|
494
479
|
end
|
495
|
-
|
480
|
+
build_standard_update_options(opts, options)
|
496
481
|
opts.footer = "Update job.\n" +
|
497
482
|
"[job] is required. Job ID or name"
|
498
483
|
end
|
499
484
|
optparse.parse!(args)
|
500
485
|
connect(options)
|
501
|
-
|
502
|
-
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
|
503
|
-
return 1
|
504
|
-
end
|
486
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
505
487
|
|
506
|
-
begin
|
507
488
|
job = find_by_name_or_id('job', args[0])
|
508
489
|
|
509
490
|
if job.nil?
|
@@ -609,22 +590,10 @@ class Morpheus::Cli::JobsCommand
|
|
609
590
|
return
|
610
591
|
end
|
611
592
|
json_response = @jobs_interface.update(job['id'], payload)
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
elsif !options[:quiet]
|
616
|
-
if json_response['success']
|
617
|
-
print_green_success "Job updated"
|
618
|
-
_get(job['id'], nil, options)
|
619
|
-
else
|
620
|
-
print_red_alert "Error updating job: #{json_response['msg'] || json_response['errors']}"
|
621
|
-
end
|
593
|
+
render_response(json_response, options, 'job') do
|
594
|
+
print_green_success "Job updated"
|
595
|
+
_get(job['id'], nil, options)
|
622
596
|
end
|
623
|
-
return 0
|
624
|
-
rescue RestClient::Exception => e
|
625
|
-
print_rest_exception(e, options)
|
626
|
-
exit 1
|
627
|
-
end
|
628
597
|
end
|
629
598
|
|
630
599
|
def execute(args)
|
@@ -684,48 +653,31 @@ class Morpheus::Cli::JobsCommand
|
|
684
653
|
params = {}
|
685
654
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
686
655
|
opts.banner = subcommand_usage( "[job]")
|
687
|
-
|
656
|
+
build_standard_remove_options(opts, options)
|
688
657
|
opts.footer = "Remove job.\n" +
|
689
658
|
"[job] is required. Job ID or name"
|
690
659
|
end
|
691
660
|
optparse.parse!(args)
|
692
661
|
connect(options)
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
begin
|
699
|
-
job = find_by_name_or_id('job', args[0])
|
700
|
-
|
701
|
-
if job.nil?
|
702
|
-
print_red_alert "Job #{args[0]} not found"
|
703
|
-
exit 1
|
704
|
-
end
|
705
|
-
|
706
|
-
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to remove the job '#{job['name']}'?", options)
|
707
|
-
return 9, "aborted command"
|
708
|
-
end
|
709
|
-
|
710
|
-
@jobs_interface.setopts(options)
|
711
|
-
if options[:dry_run]
|
712
|
-
print_dry_run @jobs_interface.dry.destroy(job['id'], params)
|
713
|
-
return
|
714
|
-
end
|
715
|
-
|
716
|
-
json_response = @jobs_interface.destroy(job['id'], params)
|
717
|
-
|
718
|
-
if options[:json]
|
719
|
-
print JSON.pretty_generate(json_response)
|
720
|
-
print "\n"
|
721
|
-
elsif !options[:quiet]
|
722
|
-
print_green_success "Job #{job['name']} removed"
|
723
|
-
end
|
724
|
-
return 0
|
725
|
-
rescue RestClient::Exception => e
|
726
|
-
print_rest_exception(e, options)
|
662
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
663
|
+
job = find_by_name_or_id('job', args[0])
|
664
|
+
if job.nil?
|
665
|
+
print_red_alert "Job #{args[0]} not found"
|
727
666
|
exit 1
|
728
667
|
end
|
668
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to remove the job '#{job['name']}'?", options)
|
669
|
+
return 9, "aborted command"
|
670
|
+
end
|
671
|
+
@jobs_interface.setopts(options)
|
672
|
+
if options[:dry_run]
|
673
|
+
print_dry_run @jobs_interface.dry.destroy(job['id'], params)
|
674
|
+
return
|
675
|
+
end
|
676
|
+
json_response = @jobs_interface.destroy(job['id'], params)
|
677
|
+
render_response(json_response, options) do
|
678
|
+
print_green_success "Job #{job['name']} removed"
|
679
|
+
end
|
680
|
+
return 0, nil
|
729
681
|
end
|
730
682
|
|
731
683
|
def list_executions(args)
|
@@ -739,7 +691,7 @@ class Morpheus::Cli::JobsCommand
|
|
739
691
|
opts.on("--internal [true|false]", String, "Filters executions based on internal flag. Internal executions are excluded by default.") do |val|
|
740
692
|
params["internalOnly"] = (val.to_s != "false")
|
741
693
|
end
|
742
|
-
build_standard_list_options(opts, options)
|
694
|
+
build_standard_list_options(opts, options, [:details])
|
743
695
|
opts.footer = "List job executions.\n" +
|
744
696
|
"[job] is optional. Job ID or name to filter executions."
|
745
697
|
|
@@ -792,10 +744,7 @@ class Morpheus::Cli::JobsCommand
|
|
792
744
|
params = {}
|
793
745
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
794
746
|
opts.banner = subcommand_usage("[id]")
|
795
|
-
opts
|
796
|
-
options[:details] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
|
797
|
-
end
|
798
|
-
build_common_options(opts, options, [:json, :dry_run, :remote])
|
747
|
+
build_standard_get_options(opts, options, [:details])
|
799
748
|
opts.footer = "Get details about a job.\n" +
|
800
749
|
"[id] is required. Job execution ID."
|
801
750
|
end
|
@@ -805,82 +754,17 @@ class Morpheus::Cli::JobsCommand
|
|
805
754
|
end
|
806
755
|
connect(options)
|
807
756
|
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
print_dry_run @jobs_interface.dry.get_execution(args[0], params)
|
813
|
-
return
|
814
|
-
end
|
815
|
-
json_response = @jobs_interface.get_execution(args[0], params)
|
816
|
-
|
817
|
-
render_result = render_with_format(json_response, options, 'jobExecution')
|
818
|
-
return 0 if render_result
|
819
|
-
|
820
|
-
title = "Morpheus Job Execution"
|
821
|
-
subtitles = []
|
822
|
-
subtitles += parse_list_subtitles(options)
|
823
|
-
print_h1 title, subtitles
|
824
|
-
|
825
|
-
exec = json_response['jobExecution']
|
826
|
-
process = exec['process']
|
827
|
-
print cyan
|
828
|
-
description_cols = {
|
829
|
-
"ID" => lambda {|it| it['id'] },
|
830
|
-
"Job" => lambda {|it| it['job'] ? it['job']['name'] : ''},
|
831
|
-
"Job Type" => lambda {|it| it['job'] && it['job']['type'] ? (it['job']['type']['code'] == 'morpheus.workflow' ? 'Workflow' : 'Task') : ''},
|
832
|
-
# "Description" => lambda {|it| it['description'] || (it['job'] ? it['job']['description'] : '') },
|
833
|
-
"Start Date" => lambda {|it| format_local_dt(it['startDate'])},
|
834
|
-
"ETA/Time" => lambda {|it| it['duration'] ? format_human_duration(it['duration'] / 1000.0) : ''},
|
835
|
-
"Status" => lambda {|it| format_status(it['status'])},
|
836
|
-
"Error" => lambda {|it| it['process'] && (it['process']['message'] || it['process']['error']) ? red + (it['process']['message'] || it['process']['error']) + cyan : ''},
|
837
|
-
"Created By" => lambda {|it| it['createdBy'].nil? ? '' : it['createdBy']['displayName'] || it['createdBy']['username']}
|
838
|
-
}
|
839
|
-
description_cols["Process ID"] = lambda {|it| process['id']} if !process.nil?
|
840
|
-
|
841
|
-
print_description_list(description_cols, exec)
|
842
|
-
|
843
|
-
if !process.nil?
|
844
|
-
if options[:details]
|
845
|
-
process_data = get_process_event_data(process)
|
846
|
-
print_h2 "Execution Details"
|
847
|
-
description_cols = {
|
848
|
-
"Process ID" => lambda {|it| it[:id]},
|
849
|
-
"Description" => lambda {|it| it[:description]},
|
850
|
-
"Start Date" => lambda {|it| it[:start_date]},
|
851
|
-
"Created By" => lambda {|it| it[:created_by]},
|
852
|
-
"Duration" => lambda {|it| it[:duration]},
|
853
|
-
"Status" => lambda {|it| it[:status]}
|
854
|
-
}
|
855
|
-
if !options[:details]
|
856
|
-
description_cols["Output"] = lambda {|it| it[:output]} if process_data[:output] && process_data[:output].strip.length > 0
|
857
|
-
description_cols["Error"] = lambda {|it| it[:error]} if process_data[:error] && process_data[:error].strip.length > 0
|
858
|
-
end
|
859
|
-
|
860
|
-
print_description_list(description_cols, process_data)
|
861
|
-
|
862
|
-
if process_data[:output] && process_data[:output].strip.length > 0
|
863
|
-
print_h2 "Output"
|
864
|
-
print process['output']
|
865
|
-
end
|
866
|
-
if process_data[:error] && process_data[:error].strip.length > 0
|
867
|
-
print_h2 "Error"
|
868
|
-
print process['message'] || process['error']
|
869
|
-
print reset,"\n"
|
870
|
-
end
|
871
|
-
end
|
872
|
-
|
873
|
-
if process['events'] && !process['events'].empty?
|
874
|
-
print_h2 "Execution Events"
|
875
|
-
print_process_events(process['events'])
|
876
|
-
end
|
877
|
-
end
|
878
|
-
print reset,"\n"
|
879
|
-
return 0
|
880
|
-
rescue RestClient::Exception => e
|
881
|
-
print_rest_exception(e, options)
|
882
|
-
exit 1
|
757
|
+
@jobs_interface.setopts(options)
|
758
|
+
if options[:dry_run]
|
759
|
+
print_dry_run @jobs_interface.dry.get_execution(args[0], params)
|
760
|
+
return
|
883
761
|
end
|
762
|
+
json_response = @jobs_interface.get_execution(args[0], params)
|
763
|
+
render_response(json_response, options, 'jobExecution') do
|
764
|
+
print_h1 "Morpheus Job Execution", [], options
|
765
|
+
print_job_execution(json_response['jobExecution'], options)
|
766
|
+
end
|
767
|
+
return 0, nil
|
884
768
|
end
|
885
769
|
|
886
770
|
def get_execution_event(args)
|
@@ -888,7 +772,7 @@ class Morpheus::Cli::JobsCommand
|
|
888
772
|
params = {}
|
889
773
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
890
774
|
opts.banner = subcommand_usage("[id] [event]")
|
891
|
-
|
775
|
+
build_standard_get_options(opts, options)
|
892
776
|
opts.footer = "Get details about a job.\n" +
|
893
777
|
"[id] is required. Job execution ID.\n" +
|
894
778
|
"[event] is required. Process event ID."
|
@@ -947,72 +831,8 @@ class Morpheus::Cli::JobsCommand
|
|
947
831
|
|
948
832
|
private
|
949
833
|
|
950
|
-
def get_process_event_data(process_or_event)
|
951
|
-
{
|
952
|
-
id: process_or_event['id'],
|
953
|
-
description: process_or_event['description'] || (process_or_event['refType'] == 'instance' ? process_or_event['displayName'] : (process_or_event['processTypeName'] || '').capitalize),
|
954
|
-
start_date: format_local_dt(process_or_event['startDate']),
|
955
|
-
created_by: process_or_event['createdBy'] ? process_or_event['createdBy']['displayName'] : '',
|
956
|
-
duration: format_human_duration((process_or_event['duration'] || process_or_event['statusEta'] || 0) / 1000.0),
|
957
|
-
status: format_status(process_or_event['status']),
|
958
|
-
error: truncate_string(process_or_event['message'] || process_or_event['error'], 32),
|
959
|
-
output: truncate_string(process_or_event['output'], 32)
|
960
|
-
}
|
961
|
-
end
|
962
|
-
|
963
|
-
# both process and process events
|
964
|
-
def print_process_events(events, options={})
|
965
|
-
print as_pretty_table(events.collect {|it| get_process_event_data(it)}, [:id, :description, :start_date, :created_by, :duration, :status, :error], options)
|
966
|
-
print reset,"\n"
|
967
|
-
end
|
968
|
-
|
969
|
-
def print_job_executions(execs, options={})
|
970
|
-
if execs.empty?
|
971
|
-
print cyan,"No job executions found.",reset,"\n"
|
972
|
-
else
|
973
|
-
rows = execs.collect do |ex|
|
974
|
-
{
|
975
|
-
id: ex['id'],
|
976
|
-
job: ex['job'] ? ex['job']['name'] : '',
|
977
|
-
description: ex['description'] || ex['job'] ? ex['job']['description'] : '',
|
978
|
-
type: ex['job'] && ex['job']['type'] ? (ex['job']['type']['code'] == 'morpheus.workflow' ? 'Workflow' : 'Task') : '',
|
979
|
-
start: format_local_dt(ex['startDate']),
|
980
|
-
duration: ex['duration'] ? format_human_duration(ex['duration'] / 1000.0) : '',
|
981
|
-
status: format_status(ex['status']),
|
982
|
-
error: truncate_string(ex['process'] && (ex['process']['message'] || ex['process']['error']) ? ex['process']['message'] || ex['process']['error'] : '', 32)
|
983
|
-
}
|
984
|
-
end
|
985
|
-
|
986
|
-
columns = [
|
987
|
-
:id, :job, :type, {'START DATE' => :start}, {'ETA/TIME' => :duration}, :status, :error
|
988
|
-
]
|
989
|
-
print as_pretty_table(rows, columns, options)
|
990
|
-
print reset,"\n"
|
991
|
-
end
|
992
|
-
end
|
993
|
-
|
994
|
-
def format_status(status_string, return_color=cyan)
|
995
|
-
out = ""
|
996
|
-
if status_string
|
997
|
-
if ['complete','success', 'successful', 'ok'].include?(status_string)
|
998
|
-
out << "#{green}#{status_string.upcase}"
|
999
|
-
elsif ['error', 'offline', 'failed', 'failure'].include?(status_string)
|
1000
|
-
out << "#{red}#{status_string.upcase}"
|
1001
|
-
else
|
1002
|
-
out << "#{yellow}#{status_string.upcase}"
|
1003
|
-
end
|
1004
|
-
end
|
1005
|
-
out + return_color
|
1006
|
-
end
|
1007
|
-
|
1008
|
-
def find_by_name_or_id(type, val)
|
1009
|
-
interface = instance_variable_get "@#{type}s_interface"
|
1010
|
-
typeCamelCase = type.gsub(/(?:^|_)([a-z])/) do $1.upcase end
|
1011
|
-
typeCamelCase = typeCamelCase[0, 1].downcase + typeCamelCase[1..-1]
|
1012
|
-
(val.to_s =~ /\A\d{1,}\Z/) ? interface.get(val.to_i)[typeCamelCase] : interface.list({'name' => val})["#{typeCamelCase}s"].first
|
1013
|
-
end
|
1014
|
-
|
1015
834
|
def load_job_type_id_by_code(code)
|
1016
835
|
@options_interface.options_for_source('jobTypes', {})['data'].find {|it| it['code'] == code}['value'] rescue nil
|
1017
836
|
end
|
837
|
+
|
1018
838
|
end
|
@@ -118,10 +118,10 @@ class Morpheus::Cli::LibraryContainerTypesCommand
|
|
118
118
|
begin
|
119
119
|
@library_container_types_interface.setopts(options)
|
120
120
|
if options[:dry_run]
|
121
|
-
if
|
122
|
-
print_dry_run @library_container_types_interface.dry.get(layout_id,
|
121
|
+
if id.to_s =~ /\A\d{1,}\Z/
|
122
|
+
print_dry_run @library_container_types_interface.dry.get(layout_id, id.to_i)
|
123
123
|
else
|
124
|
-
print_dry_run @library_container_types_interface.dry.list(layout_id, {name:
|
124
|
+
print_dry_run @library_container_types_interface.dry.list(layout_id, {name:id})
|
125
125
|
end
|
126
126
|
return
|
127
127
|
end
|
@@ -255,6 +255,24 @@ class Morpheus::Cli::LibraryContainerTypesCommand
|
|
255
255
|
opts.on('--technology CODE', String, "Technology. This is the provision type code.") do |val|
|
256
256
|
params['provisionTypeCode'] = val
|
257
257
|
end
|
258
|
+
opts.on('--ports NAME=PORT,NAME=PORT', String, "List of exposed port definitions in the format NAME=PORT|PROTOCOL, Example: \"WEB=80|HTTP,SECURE=443|HTTPS\"") do |val|
|
259
|
+
params['containerPorts'] ||= []
|
260
|
+
parsed_ports = val.split(",").each do |value_pair|
|
261
|
+
k,v = value_pair.strip.split("=")
|
262
|
+
value_array = v.split("|")
|
263
|
+
port_name = k.to_s.strip
|
264
|
+
port_number = value_array[0].to_s.strip.to_i
|
265
|
+
exposed_port = {'name' => port_name,'port' => port_number }
|
266
|
+
if value_array[1]
|
267
|
+
exposed_port['loadBalanceProtocol'] = value_array[1].strip
|
268
|
+
end
|
269
|
+
if exposed_port['name'].to_s.empty? || !exposed_port['port'] || exposed_port['port'].to_i <= 0
|
270
|
+
raise_command_error "Invalid exposed port definition: '#{value_pair}'. Expected format is 'NAME=PORT'", args, optparse
|
271
|
+
end
|
272
|
+
params['containerPorts'] << exposed_port
|
273
|
+
end
|
274
|
+
# options[:options]['containerPorts'] = params['containerPorts']
|
275
|
+
end
|
258
276
|
opts.on('--scripts x,y,z', Array, "List of Script IDs") do |val|
|
259
277
|
script_ids = val #.collect {|it| it.to_i }
|
260
278
|
end
|
@@ -345,6 +363,12 @@ class Morpheus::Cli::LibraryContainerTypesCommand
|
|
345
363
|
|
346
364
|
# payload.deep_merge!(provision_type_v_prompt)
|
347
365
|
|
366
|
+
# PORTS
|
367
|
+
# if !params['containerPorts']
|
368
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'containerPorts', 'type' => 'exposedPorts', 'fieldLabel' => 'Exposed Ports', 'description' => 'The exposed ports in the format NAME=PORT,NAME=PORT for example HTTP=80,HTTPS=443'}], prompt_params)
|
369
|
+
# params['containerPorts'] = v_prompt['containerPorts']
|
370
|
+
# end
|
371
|
+
|
348
372
|
# ENVIRONMENT VARIABLES
|
349
373
|
if evars
|
350
374
|
params['environmentVariables'] = evars
|
@@ -367,6 +391,7 @@ class Morpheus::Cli::LibraryContainerTypesCommand
|
|
367
391
|
# prompt
|
368
392
|
end
|
369
393
|
|
394
|
+
|
370
395
|
# payload = {'containerType' => params}
|
371
396
|
payload['containerType'] ||= {}
|
372
397
|
payload['containerType'].deep_merge!(params)
|
@@ -422,6 +447,24 @@ class Morpheus::Cli::LibraryContainerTypesCommand
|
|
422
447
|
# opts.on('--technology CODE', String, "Technology") do |val|
|
423
448
|
# params['provisionTypeCode'] = val
|
424
449
|
# end
|
450
|
+
opts.on('--ports NAME=PORT,NAME=PORT', String, "List of exposed port definitions in the format NAME=PORT|PROTOCOL, Example: \"WEB=80|HTTP,SECURE=443|HTTPS\"") do |val|
|
451
|
+
params['containerPorts'] ||= []
|
452
|
+
parsed_ports = val.split(",").each do |value_pair|
|
453
|
+
k,v = value_pair.strip.split("=")
|
454
|
+
value_array = v.split("|")
|
455
|
+
port_name = k.to_s.strip
|
456
|
+
port_number = value_array[0].to_s.strip.to_i
|
457
|
+
exposed_port = {'name' => port_name,'port' => port_number }
|
458
|
+
if value_array[1]
|
459
|
+
exposed_port['loadBalanceProtocol'] = value_array[1].strip
|
460
|
+
end
|
461
|
+
if exposed_port['name'].to_s.empty? || !exposed_port['port'] || exposed_port['port'].to_i <= 0
|
462
|
+
raise_command_error "Invalid exposed port definition: '#{value_pair}'. Expected format is 'NAME=PORT'", args, optparse
|
463
|
+
end
|
464
|
+
params['containerPorts'] << exposed_port
|
465
|
+
end
|
466
|
+
# options[:options]['containerPorts'] = params['containerPorts']
|
467
|
+
end
|
425
468
|
opts.on('--scripts x,y,z', Array, "List of Script IDs") do |val|
|
426
469
|
script_ids = val #.collect {|it| it.to_i }
|
427
470
|
end
|
@@ -455,6 +498,12 @@ class Morpheus::Cli::LibraryContainerTypesCommand
|
|
455
498
|
# params = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
|
456
499
|
payload.deep_merge!({'containerType' => passed_options}) unless passed_options.empty?
|
457
500
|
|
501
|
+
# PORTS
|
502
|
+
# if !params['containerPorts']
|
503
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'containerPorts', 'type' => 'exposedPorts', 'fieldLabel' => 'Exposed Ports', 'description' => 'The exposed ports in the format NAME=PORT,NAME=PORT for example HTTP=80,HTTPS=443'}], prompt_params)
|
504
|
+
# params['containerPorts'] = v_prompt['containerPorts']
|
505
|
+
# end
|
506
|
+
|
458
507
|
# ENVIRONMENT VARIABLES
|
459
508
|
if evars
|
460
509
|
|
@@ -36,20 +36,18 @@ class Morpheus::Cli::LibraryOptionTypesCommand
|
|
36
36
|
options[:phrase] = args.join(" ")
|
37
37
|
end
|
38
38
|
connect(options)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
|
40
|
+
params = {}
|
41
|
+
params.merge!(parse_list_options(options))
|
42
|
+
@option_types_interface.setopts(options)
|
43
|
+
if options[:dry_run]
|
44
|
+
print_dry_run @option_types_interface.dry.list(params)
|
45
|
+
return
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
render_result = render_with_format(json_response, options, 'optionTypes')
|
51
|
-
return 0 if render_result
|
48
|
+
json_response = @option_types_interface.list(params)
|
52
49
|
|
50
|
+
render_response(json_response, options, "optionTypes") do
|
53
51
|
option_types = json_response['optionTypes']
|
54
52
|
subtitles = []
|
55
53
|
subtitles += parse_list_subtitles(options)
|
@@ -84,10 +82,8 @@ class Morpheus::Cli::LibraryOptionTypesCommand
|
|
84
82
|
print_results_pagination(json_response)
|
85
83
|
end
|
86
84
|
print reset,"\n"
|
87
|
-
rescue RestClient::Exception => e
|
88
|
-
print_rest_exception(e, options)
|
89
|
-
exit 1
|
90
85
|
end
|
86
|
+
return 0, nil
|
91
87
|
end
|
92
88
|
|
93
89
|
def get(args)
|
@@ -110,23 +106,21 @@ class Morpheus::Cli::LibraryOptionTypesCommand
|
|
110
106
|
end
|
111
107
|
|
112
108
|
def _get(id, options)
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
121
|
-
return
|
109
|
+
|
110
|
+
@option_types_interface.setopts(options)
|
111
|
+
if options[:dry_run]
|
112
|
+
if id.to_s =~ /\A\d{1,}\Z/
|
113
|
+
print_dry_run @option_types_interface.dry.get(id.to_i)
|
114
|
+
else
|
115
|
+
print_dry_run @option_types_interface.dry.list({name: id})
|
122
116
|
end
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
return 0 if render_result
|
117
|
+
return
|
118
|
+
end
|
119
|
+
option_type = find_option_type_by_name_or_id(id)
|
120
|
+
return 1 if option_type.nil?
|
121
|
+
json_response = {'optionType' => option_type}
|
129
122
|
|
123
|
+
render_response(json_response, options, "optionType") do
|
130
124
|
print_h1 "Option Type Details"
|
131
125
|
print cyan
|
132
126
|
columns = {
|
@@ -144,15 +138,13 @@ class Morpheus::Cli::LibraryOptionTypesCommand
|
|
144
138
|
"Default Value" => 'defaultValue',
|
145
139
|
"Required" => lambda {|it| format_boolean(it['required']) },
|
146
140
|
"Export As Tag" => lambda {|it| it['exportMeta'].nil? ? '' : format_boolean(it['exportMeta']) },
|
141
|
+
"Verify Pattern" => 'verifyPattern',
|
147
142
|
}
|
148
143
|
columns.delete("Option List") if option_type['optionList'].nil?
|
149
144
|
print as_description_list(option_type, columns, options)
|
150
145
|
print reset,"\n"
|
151
|
-
return 0
|
152
|
-
rescue RestClient::Exception => e
|
153
|
-
print_rest_exception(e, options)
|
154
|
-
return 1
|
155
146
|
end
|
147
|
+
return 0, nil
|
156
148
|
end
|
157
149
|
|
158
150
|
def add(args)
|
@@ -165,37 +157,38 @@ class Morpheus::Cli::LibraryOptionTypesCommand
|
|
165
157
|
end
|
166
158
|
optparse.parse!(args)
|
167
159
|
connect(options)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
return
|
160
|
+
verify_args!(args:args, optparse:optparse, max:1)
|
161
|
+
if args[0]
|
162
|
+
options[:options]['name'] = args[0]
|
163
|
+
end
|
164
|
+
|
165
|
+
payload = nil
|
166
|
+
if options[:payload]
|
167
|
+
payload = options[:payload]
|
168
|
+
payload.deep_merge!({'optionType' => parse_passed_options(options)})
|
169
|
+
else
|
170
|
+
payload = {}
|
171
|
+
payload.deep_merge!({'optionType' => parse_passed_options(options)})
|
172
|
+
option_type_payload = Morpheus::Cli::OptionTypes.prompt(new_option_type_option_types, options[:options], @api_client)
|
173
|
+
# tweak payload for API
|
174
|
+
option_type_payload['optionList'] = {'id' => option_type_payload['optionList'].to_i} if option_type_payload['optionList'].is_a?(String) || option_type_payload['optionList'].is_a?(Numeric)
|
175
|
+
option_type_payload['required'] = ['on','true'].include?(option_type_payload['required'].to_s) if option_type_payload.key?('required')
|
176
|
+
option_type_payload['exportMeta'] = ['on','true'].include?(option_type_payload['exportMeta'].to_s) if option_type_payload.key?('exportMeta')
|
177
|
+
payload.deep_merge!({'optionType' => option_type_payload})
|
178
|
+
end
|
179
|
+
@option_types_interface.setopts(options)
|
180
|
+
if options[:dry_run]
|
181
|
+
print_dry_run @option_types_interface.dry.create(payload)
|
182
|
+
return
|
183
|
+
end
|
184
|
+
json_response = @option_types_interface.create(payload)
|
185
|
+
|
186
|
+
render_response(json_response, options, "optionType") do
|
191
187
|
option_type = json_response['optionType']
|
192
188
|
print_green_success "Added Option Type #{option_type['name']}"
|
193
|
-
|
194
|
-
get([option_type['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
|
195
|
-
rescue RestClient::Exception => e
|
196
|
-
print_rest_exception(e, options)
|
197
|
-
exit 1
|
189
|
+
_get(option_type['id'], options)
|
198
190
|
end
|
191
|
+
return 0, nil
|
199
192
|
end
|
200
193
|
|
201
194
|
def update(args)
|
@@ -302,6 +295,7 @@ class Morpheus::Cli::LibraryOptionTypesCommand
|
|
302
295
|
{'fieldName' => 'defaultValue', 'fieldLabel' => 'Default Value', 'type' => 'text', 'displayOrder' => 9},
|
303
296
|
{'fieldName' => 'required', 'fieldLabel' => 'Required', 'type' => 'checkbox', 'defaultValue' => false, 'displayOrder' => 10},
|
304
297
|
{'fieldName' => 'exportMeta', 'fieldLabel' => 'Export As Tag', 'type' => 'checkbox', 'defaultValue' => false, 'description' => 'Export as Tag.', 'displayOrder' => 11},
|
298
|
+
{'fieldName' => 'verifyPattern', 'fieldLabel' => 'Verify Pattern', 'type' => 'text', 'dependsOnCode' => 'optionType.type:text', 'description' => 'A regexp string that validates the input, use (?i) to make the matcher case insensitive', 'displayOrder' => 12},
|
305
299
|
]
|
306
300
|
end
|
307
301
|
|