morpheus-cli 4.2.14 → 4.2.19
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/README.md +8 -6
- data/lib/morpheus/api/api_client.rb +32 -14
- data/lib/morpheus/api/auth_interface.rb +4 -2
- data/lib/morpheus/api/backup_jobs_interface.rb +9 -0
- data/lib/morpheus/api/backups_interface.rb +16 -0
- data/lib/morpheus/api/deploy_interface.rb +25 -56
- data/lib/morpheus/api/deployments_interface.rb +44 -55
- data/lib/morpheus/api/doc_interface.rb +57 -0
- data/lib/morpheus/api/instances_interface.rb +5 -0
- data/lib/morpheus/api/rest_interface.rb +40 -0
- data/lib/morpheus/api/user_sources_interface.rb +0 -15
- data/lib/morpheus/api/users_interface.rb +2 -3
- data/lib/morpheus/benchmarking.rb +2 -2
- data/lib/morpheus/cli.rb +4 -1
- data/lib/morpheus/cli/access_token_command.rb +27 -10
- data/lib/morpheus/cli/apps.rb +21 -15
- data/lib/morpheus/cli/backup_jobs_command.rb +276 -0
- data/lib/morpheus/cli/backups_command.rb +271 -0
- data/lib/morpheus/cli/blueprints_command.rb +27 -61
- data/lib/morpheus/cli/boot_scripts_command.rb +1 -1
- data/lib/morpheus/cli/cli_command.rb +183 -45
- data/lib/morpheus/cli/cli_registry.rb +3 -0
- data/lib/morpheus/cli/clouds.rb +7 -10
- data/lib/morpheus/cli/clusters.rb +0 -18
- data/lib/morpheus/cli/commands/standard/benchmark_command.rb +23 -20
- data/lib/morpheus/cli/commands/standard/man_command.rb +1 -1
- data/lib/morpheus/cli/credentials.rb +13 -9
- data/lib/morpheus/cli/deploy.rb +374 -0
- data/lib/morpheus/cli/deployments.rb +521 -197
- data/lib/morpheus/cli/deploys.rb +271 -126
- data/lib/morpheus/cli/doc.rb +182 -0
- data/lib/morpheus/cli/error_handler.rb +23 -8
- data/lib/morpheus/cli/errors.rb +3 -2
- data/lib/morpheus/cli/image_builder_command.rb +2 -2
- data/lib/morpheus/cli/instances.rb +136 -17
- data/lib/morpheus/cli/invoices_command.rb +339 -225
- data/lib/morpheus/cli/jobs_command.rb +2 -2
- data/lib/morpheus/cli/library_layouts_command.rb +1 -1
- data/lib/morpheus/cli/library_option_lists_command.rb +61 -125
- data/lib/morpheus/cli/library_option_types_command.rb +32 -37
- data/lib/morpheus/cli/login.rb +9 -3
- data/lib/morpheus/cli/mixins/accounts_helper.rb +158 -100
- data/lib/morpheus/cli/mixins/backups_helper.rb +115 -0
- data/lib/morpheus/cli/mixins/deployments_helper.rb +135 -0
- data/lib/morpheus/cli/mixins/library_helper.rb +32 -0
- data/lib/morpheus/cli/mixins/option_source_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +149 -84
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +2 -2
- data/lib/morpheus/cli/mixins/whoami_helper.rb +19 -6
- data/lib/morpheus/cli/network_routers_command.rb +1 -1
- data/lib/morpheus/cli/option_parser.rb +48 -5
- data/lib/morpheus/cli/option_types.rb +46 -10
- data/lib/morpheus/cli/price_sets_command.rb +1 -1
- data/lib/morpheus/cli/projects_command.rb +7 -7
- data/lib/morpheus/cli/remote.rb +3 -2
- data/lib/morpheus/cli/roles.rb +49 -92
- data/lib/morpheus/cli/security_groups.rb +7 -1
- data/lib/morpheus/cli/service_plans_command.rb +10 -10
- data/lib/morpheus/cli/setup.rb +1 -1
- data/lib/morpheus/cli/shell.rb +7 -6
- data/lib/morpheus/cli/subnets_command.rb +1 -1
- data/lib/morpheus/cli/tasks.rb +24 -10
- data/lib/morpheus/cli/tenants_command.rb +133 -163
- data/lib/morpheus/cli/user_groups_command.rb +20 -65
- data/lib/morpheus/cli/user_settings_command.rb +115 -13
- data/lib/morpheus/cli/user_sources_command.rb +57 -24
- data/lib/morpheus/cli/users.rb +210 -186
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/whitelabel_settings_command.rb +29 -5
- data/lib/morpheus/cli/whoami.rb +113 -6
- data/lib/morpheus/cli/workflows.rb +11 -8
- data/lib/morpheus/ext/hash.rb +21 -0
- data/lib/morpheus/formatters.rb +7 -19
- data/lib/morpheus/terminal.rb +1 -0
- metadata +12 -3
- data/lib/morpheus/cli/auth_command.rb +0 -105
@@ -156,8 +156,8 @@ class Morpheus::Cli::SecurityGroups
|
|
156
156
|
"Description" => 'description',
|
157
157
|
"Scoped Cloud" => lambda {|it| it['zone'] ? it['zone']['name'] : 'All' },
|
158
158
|
"Source" => lambda {|it| it['syncSource'] == 'external' ? 'SYNCED' : 'CREATED' },
|
159
|
-
# "Active" => lambda {|it| format_boolean(it['active']) },
|
160
159
|
"Visibility" => 'visibility',
|
160
|
+
"Active" => lambda {|it| format_boolean(it['active']) },
|
161
161
|
"Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|it| it['name'] }.uniq.sort.join(', ') : '' },
|
162
162
|
}
|
163
163
|
print_description_list(description_cols, security_group)
|
@@ -295,6 +295,9 @@ class Morpheus::Cli::SecurityGroups
|
|
295
295
|
opts.on('--visibility [private|public]', String, "Visibility") do |val|
|
296
296
|
options['visibility'] = val
|
297
297
|
end
|
298
|
+
opts.on('--active [on|off]', String, "Can be used to disable a security group") do |val|
|
299
|
+
options[:options]['active'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
300
|
+
end
|
298
301
|
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
299
302
|
opts.footer = "Create a security group." + "\n" +
|
300
303
|
"[name] is required. This is the name of the security group."
|
@@ -469,6 +472,9 @@ class Morpheus::Cli::SecurityGroups
|
|
469
472
|
opts.on('--visibility [private|public]', String, "Visibility") do |val|
|
470
473
|
options['visibility'] = val
|
471
474
|
end
|
475
|
+
opts.on('--active [on|off]', String, "Can be used to disable a security group") do |val|
|
476
|
+
options[:options]['active'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
477
|
+
end
|
472
478
|
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
473
479
|
opts.footer = "Update a security group." + "\n" +
|
474
480
|
"[security-group] is required. This is the name or id of the security group."
|
@@ -650,13 +650,13 @@ class Morpheus::Cli::ServicePlanCommand
|
|
650
650
|
|
651
651
|
if !plan
|
652
652
|
print_red_alert "Service plan #{args[0]} not found"
|
653
|
-
|
653
|
+
return 1
|
654
654
|
end
|
655
655
|
|
656
|
-
if plan['active'] == true
|
657
|
-
|
658
|
-
|
659
|
-
end
|
656
|
+
# if plan['active'] == true
|
657
|
+
# print_green_success "Service plan #{plan['name']} already actived."
|
658
|
+
# return 0
|
659
|
+
# end
|
660
660
|
|
661
661
|
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to activate the service plan '#{plan['name']}'?", options)
|
662
662
|
return 9, "aborted command"
|
@@ -704,13 +704,13 @@ class Morpheus::Cli::ServicePlanCommand
|
|
704
704
|
|
705
705
|
if !plan
|
706
706
|
print_red_alert "Service plan #{args[0]} not found"
|
707
|
-
|
707
|
+
return 1
|
708
708
|
end
|
709
709
|
|
710
|
-
if plan['active'] == false
|
711
|
-
|
712
|
-
|
713
|
-
end
|
710
|
+
# if plan['active'] == false
|
711
|
+
# print_green_success "Service plan #{plan['name']} already deactivated."
|
712
|
+
# return 0
|
713
|
+
# end
|
714
714
|
|
715
715
|
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to deactivate the service plan '#{plan['name']}'?", options)
|
716
716
|
return 9, "aborted command"
|
data/lib/morpheus/cli/setup.rb
CHANGED
@@ -281,7 +281,7 @@ EOT
|
|
281
281
|
#print cyan
|
282
282
|
#puts "Initializing remote appliance at URL: #{@appliance_url}"
|
283
283
|
|
284
|
-
# Master
|
284
|
+
# Master Tenant
|
285
285
|
print_h2 "Create Master Tenant", options
|
286
286
|
account_option_types = [
|
287
287
|
{'fieldName' => 'accountName', 'fieldLabel' => 'Master Tenant Name', 'type' => 'text', 'required' => true, 'defaultValue' => (hub_info ? hub_info['companyName'] : nil), 'description' => 'A unique name for the Master Tenant (account).'},
|
data/lib/morpheus/cli/shell.rb
CHANGED
@@ -507,16 +507,17 @@ class Morpheus::Cli::Shell
|
|
507
507
|
return 0
|
508
508
|
|
509
509
|
elsif ["hello","hi","hey","hola"].include?(input.strip.downcase)
|
510
|
+
user_msg = input.strip.downcase
|
510
511
|
# need a logged_in? method already damnit
|
511
|
-
#wallet = @wallet
|
512
512
|
wallet = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
print "#{input} #{green}#{wallet['username']}#{reset}, how may I #{cyan}help#{reset} you?\n"
|
513
|
+
help_msg = case user_msg
|
514
|
+
when "hola"
|
515
|
+
"¿como puedo ayudarte? tratar #{cyan}help#{reset}"
|
517
516
|
else
|
518
|
-
|
517
|
+
"how may I #{cyan}help#{reset} you?"
|
519
518
|
end
|
519
|
+
greeting = "#{user_msg.capitalize}#{wallet ? (' '+green+wallet['username'].to_s+reset) : ''}, #{help_msg}#{reset}"
|
520
|
+
puts greeting
|
520
521
|
return 0
|
521
522
|
elsif input.strip =~ /^shell\s*/
|
522
523
|
# just allow shell to fall through
|
@@ -609,7 +609,7 @@ class Morpheus::Cli::SubnetsCommand
|
|
609
609
|
options = {}
|
610
610
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
611
611
|
opts.banner = subcommand_usage("[subnet]")
|
612
|
-
build_common_options(opts, options, [:
|
612
|
+
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
|
613
613
|
opts.footer = "Delete a subnet." + "\n" +
|
614
614
|
"[subnet] is required. This is the name or id of a subnet."
|
615
615
|
end
|
data/lib/morpheus/cli/tasks.rb
CHANGED
@@ -832,6 +832,7 @@ class Morpheus::Cli::Tasks
|
|
832
832
|
payload = options[:payload]
|
833
833
|
payload.deep_merge!({'job' => passed_options}) unless passed_options.empty?
|
834
834
|
else
|
835
|
+
# always parse instances and/or hosts
|
835
836
|
if instance_ids.size > 0 && server_ids.size > 0
|
836
837
|
raise_command_error "Pass --instance or --host, not both.\n#{optparse}"
|
837
838
|
elsif instance_ids.size > 0
|
@@ -848,19 +849,30 @@ class Morpheus::Cli::Tasks
|
|
848
849
|
servers << server
|
849
850
|
end
|
850
851
|
params['servers'] = servers.collect {|it| it['id'] }
|
851
|
-
|
852
|
-
|
852
|
+
end
|
853
|
+
# validate requires inputs based on task executeTarget
|
854
|
+
if task['executeTarget'] == 'resource'
|
855
|
+
if instance_ids.empty? && server_ids.empty?
|
856
|
+
# todo: prompt for Context: None,Instance,Server and then Instance(s) or Server(s)
|
857
|
+
raise_command_error "missing required option: --instance or --host\n#{optparse}"
|
858
|
+
end
|
859
|
+
elsif task['executeTarget'] == 'local'
|
860
|
+
# no targetType required for local
|
861
|
+
elsif task['executeTarget'] == 'remote'
|
862
|
+
# not sure about this one
|
853
863
|
else
|
854
|
-
|
864
|
+
# unknown executeTarget
|
855
865
|
end
|
866
|
+
|
867
|
+
|
856
868
|
|
857
869
|
# todo: prompt to task optionTypes for customOptions
|
858
870
|
if task['optionTypes']
|
859
871
|
|
860
872
|
end
|
861
|
-
|
862
|
-
|
863
|
-
|
873
|
+
if target_type
|
874
|
+
params['targetType'] = target_type
|
875
|
+
end
|
864
876
|
job_payload = {}
|
865
877
|
job_payload.deep_merge!(params)
|
866
878
|
job_payload.deep_merge!(passed_options) unless passed_options.empty?
|
@@ -877,15 +889,17 @@ class Morpheus::Cli::Tasks
|
|
877
889
|
puts as_json(json_response, options)
|
878
890
|
return json_response['success'] ? 0 : 1
|
879
891
|
else
|
880
|
-
target_desc =
|
892
|
+
target_desc = nil
|
881
893
|
if instances.size() > 0
|
882
894
|
target_desc = (instances.size() == 1) ? "instance #{instances[0]['name']}" : "#{instances.size()} instances"
|
883
895
|
elsif servers.size() > 0
|
884
896
|
target_desc = (servers.size() == 1) ? "host #{servers[0]['name']}" : "#{servers.size()} hosts"
|
885
|
-
elsif target_type == 'appliance'
|
886
|
-
target_desc = "appliance"
|
887
897
|
end
|
888
|
-
|
898
|
+
if target_desc
|
899
|
+
print_green_success "Executing task #{task['name']} on #{target_desc}"
|
900
|
+
else
|
901
|
+
print_green_success "Executing task #{task['name']}"
|
902
|
+
end
|
889
903
|
# todo: refresh, use get processId and load process record isntead? err
|
890
904
|
if json_response["jobExecution"] && json_response["jobExecution"]["id"]
|
891
905
|
get_args = [json_response["jobExecution"]["id"], "--details"] + (options[:remote] ? ["-r",options[:remote]] : [])
|
@@ -41,23 +41,24 @@ class Morpheus::Cli::TenantsCommand
|
|
41
41
|
def list(args)
|
42
42
|
options = {}
|
43
43
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
44
|
-
opts.banner = subcommand_usage()
|
45
|
-
|
44
|
+
opts.banner = subcommand_usage("[search phrase]")
|
45
|
+
build_standard_list_options(opts, options)
|
46
46
|
opts.footer = "List tenants."
|
47
47
|
end
|
48
48
|
optparse.parse!(args)
|
49
|
+
# verify_args!(args:args, optparse:optparse, count:0)
|
50
|
+
options[:phrase] = args.join(" ") if args.count > 0
|
49
51
|
connect(options)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
return 0 if render_result
|
52
|
+
|
53
|
+
params = {}
|
54
|
+
params.merge!(parse_list_options(options))
|
55
|
+
@accounts_interface.setopts(options)
|
56
|
+
if options[:dry_run]
|
57
|
+
print_dry_run @accounts_interface.dry.list(params)
|
58
|
+
return 0, nil
|
59
|
+
end
|
60
|
+
json_response = @accounts_interface.list(params)
|
61
|
+
render_response(json_response, options, "accounts") do
|
61
62
|
accounts = json_response['accounts']
|
62
63
|
title = "Morpheus Tenants"
|
63
64
|
subtitles = []
|
@@ -66,15 +67,13 @@ class Morpheus::Cli::TenantsCommand
|
|
66
67
|
if accounts.empty?
|
67
68
|
print cyan,"No tenants found.",reset,"\n"
|
68
69
|
else
|
69
|
-
|
70
|
+
print cyan
|
71
|
+
print as_pretty_table(accounts, list_account_column_definitions, options)
|
70
72
|
print_results_pagination(json_response)
|
71
73
|
end
|
72
74
|
print reset,"\n"
|
73
|
-
return 0
|
74
|
-
rescue RestClient::Exception => e
|
75
|
-
print_rest_exception(e, options)
|
76
|
-
exit 1
|
77
75
|
end
|
76
|
+
return 0, nil
|
78
77
|
end
|
79
78
|
|
80
79
|
def count(args)
|
@@ -110,112 +109,89 @@ class Morpheus::Cli::TenantsCommand
|
|
110
109
|
def get(args)
|
111
110
|
options = {}
|
112
111
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
113
|
-
opts.banner = subcommand_usage("[
|
114
|
-
|
112
|
+
opts.banner = subcommand_usage("[tenant]")
|
113
|
+
build_standard_get_options(opts, options)
|
114
|
+
opts.footer = <<-EOT
|
115
|
+
Get details about a tenant (account).
|
116
|
+
[tenant] is required. This is the name or id of a tenant. Supports 1-N arguments.
|
117
|
+
EOT
|
115
118
|
end
|
116
119
|
optparse.parse!(args)
|
117
|
-
|
118
|
-
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(', ')}\n#{optparse}"
|
119
|
-
end
|
120
|
+
verify_args!(args:args, optparse:optparse, min:1)
|
120
121
|
connect(options)
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
122
|
+
id_list = parse_id_list(args)
|
123
|
+
return run_command_for_each_arg(id_list) do |arg|
|
124
|
+
_get(arg, options)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def _get(id, options={})
|
129
|
+
args = [id] # heh
|
130
|
+
@accounts_interface.setopts(options)
|
131
|
+
if options[:dry_run]
|
132
|
+
if args[0].to_s =~ /\A\d{1,}\Z/
|
133
|
+
print_dry_run @accounts_interface.dry.get(args[0].to_i)
|
134
|
+
else
|
135
|
+
print_dry_run @accounts_interface.dry.list({name:args[0]})
|
130
136
|
end
|
131
|
-
|
132
|
-
|
137
|
+
return
|
138
|
+
end
|
139
|
+
account = find_account_by_name_or_id(args[0])
|
140
|
+
exit 1 if account.nil?
|
133
141
|
|
134
|
-
|
135
|
-
|
136
|
-
|
142
|
+
json_response = {'account' => account}
|
143
|
+
render_result = render_with_format(json_response, options, 'account')
|
144
|
+
return 0 if render_result
|
137
145
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
"ID" => 'id',
|
142
|
-
"Name" => 'name',
|
143
|
-
"Description" => 'description',
|
144
|
-
"Subdomain" => 'subdomain',
|
145
|
-
"Currency" => 'currency',
|
146
|
-
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
147
|
-
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
|
148
|
-
"Status" => lambda {|it|
|
149
|
-
status_state = nil
|
150
|
-
if account['active']
|
151
|
-
status_state = "#{green}ACTIVE#{cyan}"
|
152
|
-
else
|
153
|
-
status_state = "#{red}INACTIVE#{cyan}"
|
154
|
-
end
|
155
|
-
status_state
|
156
|
-
},
|
157
|
-
}
|
158
|
-
print_description_list(description_cols, account)
|
146
|
+
print_h1 "Tenant Details", [], options
|
147
|
+
|
148
|
+
print_description_list(account_column_definitions, account, options)
|
159
149
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
print_rest_exception(e, options)
|
164
|
-
exit 1
|
165
|
-
end
|
150
|
+
print reset,"\n"
|
151
|
+
return 0
|
152
|
+
|
166
153
|
end
|
167
154
|
|
155
|
+
|
168
156
|
def add(args)
|
169
157
|
options = {}
|
158
|
+
params = {}
|
170
159
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
171
|
-
opts.banner = subcommand_usage("[
|
160
|
+
opts.banner = subcommand_usage("[name]")
|
172
161
|
build_option_type_options(opts, options, add_account_option_types)
|
173
|
-
|
162
|
+
build_standard_add_options(opts, options)
|
163
|
+
opts.footer = <<-EOT
|
164
|
+
Create a new tenant.
|
165
|
+
[name] is required. Name
|
166
|
+
[role] is required. Base Role name or ID
|
167
|
+
EOT
|
174
168
|
end
|
175
169
|
optparse.parse!(args)
|
170
|
+
verify_args!(args:args, optparse:optparse, min:0, max:2)
|
171
|
+
options[:options]['name'] = args[0] if args[0]
|
172
|
+
#options[:options]['role'] = {'id' => args[1]} if args[1]
|
176
173
|
connect(options)
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
if options[:dry_run] && options[:json]
|
199
|
-
puts as_json(payload, options)
|
200
|
-
return 0
|
201
|
-
end
|
202
|
-
@accounts_interface.setopts(options)
|
203
|
-
if options[:dry_run]
|
204
|
-
print_dry_run @accounts_interface.dry.create(payload)
|
205
|
-
return
|
206
|
-
end
|
207
|
-
json_response = @accounts_interface.create(payload)
|
208
|
-
if options[:json]
|
209
|
-
print JSON.pretty_generate(json_response)
|
210
|
-
print "\n"
|
211
|
-
else
|
212
|
-
print_green_success "Tenant #{account_payload['name']} added"
|
213
|
-
get([account_payload["name"]])
|
214
|
-
end
|
215
|
-
|
216
|
-
rescue RestClient::Exception => e
|
217
|
-
print_rest_exception(e, options)
|
218
|
-
exit 1
|
174
|
+
|
175
|
+
object_key = 'account' # 'tenant' someday
|
176
|
+
payload = {}
|
177
|
+
if options[:payload]
|
178
|
+
payload = options[:payload]
|
179
|
+
payload.deep_merge!({object_key => parse_passed_options(options)})
|
180
|
+
else
|
181
|
+
payload.deep_merge!({object_key => parse_passed_options(options)})
|
182
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(add_account_option_types, options[:options], @api_client, options[:params])
|
183
|
+
payload.deep_merge!({object_key => v_prompt})
|
184
|
+
end
|
185
|
+
@accounts_interface.setopts(options)
|
186
|
+
if options[:dry_run]
|
187
|
+
print_dry_run @accounts_interface.dry.create(payload)
|
188
|
+
return
|
189
|
+
end
|
190
|
+
json_response = @accounts_interface.create(payload)
|
191
|
+
render_response(json_response, options, object_key) do
|
192
|
+
account = json_response[object_key]
|
193
|
+
print_green_success "Tenant #{account['name']} added"
|
194
|
+
return _get(account["id"], options)
|
219
195
|
end
|
220
196
|
end
|
221
197
|
|
@@ -223,68 +199,54 @@ class Morpheus::Cli::TenantsCommand
|
|
223
199
|
options = {}
|
224
200
|
params = {}
|
225
201
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
226
|
-
opts.banner = subcommand_usage("[
|
227
|
-
opts.on('--active [on|off]', String, "Can be used to disable a network") do |val|
|
228
|
-
params['active'] = val.to_s.empty? || val.to_s == 'on' || val.to_s == 'true'
|
229
|
-
end
|
202
|
+
opts.banner = subcommand_usage("[tenant]")
|
230
203
|
build_option_type_options(opts, options, update_account_option_types)
|
231
|
-
|
204
|
+
opts.on('--active [on|off]', String, "Can be used to disable a tenant") do |val|
|
205
|
+
options[:options]['active'] = val.to_s.empty? || val.to_s == 'on' || val.to_s == 'true'
|
206
|
+
end
|
207
|
+
build_standard_update_options(opts, options)
|
208
|
+
opts.footer = <<-EOT
|
209
|
+
Update an existing tenant.
|
210
|
+
[tenant] is required. Tenant name or ID
|
211
|
+
EOT
|
232
212
|
end
|
233
213
|
optparse.parse!(args)
|
234
|
-
|
235
|
-
print_red_alert "Specify at least one option to update"
|
236
|
-
puts optparse
|
237
|
-
exit 1
|
238
|
-
end
|
214
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
239
215
|
connect(options)
|
240
|
-
begin
|
241
|
-
account = find_account_by_name_or_id(args[0])
|
242
|
-
exit 1 if account.nil?
|
243
216
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
role = find_role_by_name(nil, params['role'])
|
259
|
-
exit 1 if role.nil?
|
260
|
-
account_payload['role'] = {id: role['id']}
|
261
|
-
end
|
262
|
-
payload = {account: account_payload}
|
263
|
-
if options[:dry_run] && options[:json]
|
264
|
-
puts as_json(payload, options)
|
265
|
-
return 0
|
266
|
-
end
|
267
|
-
@accounts_interface.setopts(options)
|
268
|
-
if options[:dry_run]
|
269
|
-
print_dry_run @accounts_interface.dry.update(account['id'], payload)
|
270
|
-
return
|
217
|
+
account = find_account_by_name_or_id(args[0])
|
218
|
+
return [1, "account not found"] if account.nil?
|
219
|
+
object_key = 'account' # 'tenant' someday
|
220
|
+
payload = {}
|
221
|
+
if options[:payload]
|
222
|
+
payload = options[:payload]
|
223
|
+
payload.deep_merge!({object_key => parse_passed_options(options)})
|
224
|
+
else
|
225
|
+
payload.deep_merge!({object_key => parse_passed_options(options)})
|
226
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(update_account_option_types, options[:options].merge(:no_prompt => true), @api_client, options[:params])
|
227
|
+
payload.deep_merge!({object_key => v_prompt})
|
228
|
+
# remove empty role object.. todo: prompt() or deep_compact! needs to handle this!
|
229
|
+
if payload[object_key]['role'] && payload[object_key]['role'].empty?
|
230
|
+
payload[object_key].delete('role')
|
271
231
|
end
|
272
|
-
|
273
|
-
|
274
|
-
if options[:json]
|
275
|
-
print JSON.pretty_generate(json_response)
|
276
|
-
print "\n"
|
277
|
-
else
|
278
|
-
account_name = account_payload['name'] || account['name']
|
279
|
-
print_green_success "Tenant #{account_name} updated"
|
280
|
-
get([account_name])
|
232
|
+
if payload[object_key].empty?
|
233
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
281
234
|
end
|
282
|
-
|
283
|
-
|
284
|
-
|
235
|
+
end
|
236
|
+
@accounts_interface.setopts(options)
|
237
|
+
if options[:dry_run]
|
238
|
+
print_dry_run @accounts_interface.dry.update(account['id'], payload)
|
239
|
+
return
|
240
|
+
end
|
241
|
+
json_response = @accounts_interface.update(account['id'], payload)
|
242
|
+
render_response(json_response, options, object_key) do
|
243
|
+
account = json_response[object_key]
|
244
|
+
print_green_success "Tenant #{account['name']} updated"
|
245
|
+
return _get(account["id"], options)
|
285
246
|
end
|
286
247
|
end
|
287
248
|
|
249
|
+
|
288
250
|
def remove(args)
|
289
251
|
options = {}
|
290
252
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
@@ -333,13 +295,21 @@ class Morpheus::Cli::TenantsCommand
|
|
333
295
|
[
|
334
296
|
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
|
335
297
|
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
|
336
|
-
{'
|
337
|
-
|
298
|
+
{'fieldContext' => 'role', 'fieldName' => 'id', 'fieldLabel' => 'Base Role', 'type' => 'select', 'optionSource' => lambda {
|
299
|
+
@roles_interface.list(nil, {roleType:'account'})['roles'].collect {|it|
|
300
|
+
{"name" => (it["authority"] || it["name"]), "value" => it["id"]}
|
301
|
+
}
|
302
|
+
}, 'displayOrder' => 3},
|
303
|
+
{'fieldName' => 'currency', 'fieldLabel' => 'Currency', 'type' => 'text', 'defaultValue' => 'USD', 'displayOrder' => 4}
|
338
304
|
]
|
339
305
|
end
|
340
306
|
|
341
307
|
def update_account_option_types
|
342
|
-
add_account_option_types
|
308
|
+
list = add_account_option_types()
|
309
|
+
# list = list.reject {|it| ["interval"].include? it['fieldName'] }
|
310
|
+
list.each {|it| it.delete('required') }
|
311
|
+
list.each {|it| it.delete('defaultValue') }
|
312
|
+
list
|
343
313
|
end
|
344
314
|
|
345
315
|
end
|