morpheus-cli 4.2.16 → 4.2.17
Sign up to get free protection for your applications and to get access to all the features.
- 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 +43 -54
- 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 +3 -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/boot_scripts_command.rb +1 -1
- data/lib/morpheus/cli/cli_command.rb +92 -41
- data/lib/morpheus/cli/clusters.rb +0 -18
- data/lib/morpheus/cli/commands/standard/benchmark_command.rb +7 -7
- 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 +51 -38
- data/lib/morpheus/cli/library_layouts_command.rb +1 -1
- 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/option_source_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +110 -74
- 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 +1 -1
- 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/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 +1 -1
- data/lib/morpheus/ext/hash.rb +21 -0
- data/lib/morpheus/terminal.rb +1 -0
- metadata +12 -3
- data/lib/morpheus/cli/auth_command.rb +0 -105
@@ -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
|
@@ -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
|
@@ -25,19 +25,24 @@ class Morpheus::Cli::UserGroupsCommand
|
|
25
25
|
options = {}
|
26
26
|
params = {}
|
27
27
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
28
|
-
opts.banner = subcommand_usage()
|
29
|
-
|
28
|
+
opts.banner = subcommand_usage("[search phrase]")
|
29
|
+
build_standard_list_options(opts, options)
|
30
|
+
opts.footer = "List user groups."
|
30
31
|
end
|
31
32
|
optparse.parse!(args)
|
33
|
+
# verify_args!(args:args, optparse:optparse, count:0)
|
34
|
+
options[:phrase] = args.join(" ") if args.count > 0
|
32
35
|
connect(options)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
|
37
|
+
params.merge!(parse_list_options(options))
|
38
|
+
@user_groups_interface.setopts(options)
|
39
|
+
if options[:dry_run]
|
40
|
+
print_dry_run @user_groups_interface.dry.list(nil, params)
|
41
|
+
return
|
42
|
+
end
|
43
|
+
json_response = @user_groups_interface.list(nil, params)
|
44
|
+
|
45
|
+
render_response(json_response, options, "userGroups") do
|
41
46
|
if options[:json]
|
42
47
|
puts as_json(json_response, options, "userGroups")
|
43
48
|
return 0
|
@@ -56,15 +61,13 @@ class Morpheus::Cli::UserGroupsCommand
|
|
56
61
|
if user_groups.empty?
|
57
62
|
print cyan,"No user groups found.",reset,"\n"
|
58
63
|
else
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
print cyan
|
65
|
+
print as_pretty_table(user_groups, list_user_group_column_definitions, options)
|
66
|
+
print_results_pagination(json_response)
|
62
67
|
end
|
63
68
|
print reset,"\n"
|
64
|
-
rescue RestClient::Exception => e
|
65
|
-
print_rest_exception(e, options)
|
66
|
-
exit 1
|
67
69
|
end
|
70
|
+
return 0, nil
|
68
71
|
end
|
69
72
|
|
70
73
|
def get(args)
|
@@ -113,18 +116,7 @@ class Morpheus::Cli::UserGroupsCommand
|
|
113
116
|
|
114
117
|
print_h1 "User Group Details"
|
115
118
|
print cyan
|
116
|
-
|
117
|
-
"ID" => lambda {|it| it['id'] },
|
118
|
-
#"Account" => lambda {|it| it['account'] ? it['account']['name'] : '' },
|
119
|
-
"Name" => lambda {|it| it['name'] },
|
120
|
-
"Description" => lambda {|it| it['description'] },
|
121
|
-
"Server Group" => lambda {|it| it['serverGroup'] },
|
122
|
-
"Sudo Access" => lambda {|it| format_boolean it['sudoAccess'] },
|
123
|
-
# "Shared User" => lambda {|it| format_boolean it['sharedUser'] },
|
124
|
-
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
125
|
-
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
|
126
|
-
}
|
127
|
-
print_description_list(description_cols, user_group)
|
119
|
+
print_description_list(user_group_column_definitions, user_group, options)
|
128
120
|
|
129
121
|
## Users
|
130
122
|
print_h2 "Users (#{users.size})"
|
@@ -518,41 +510,4 @@ class Morpheus::Cli::UserGroupsCommand
|
|
518
510
|
print as_pretty_table(user_groups, columns, opts)
|
519
511
|
end
|
520
512
|
|
521
|
-
def find_user_group_by_name_or_id(account_id, val)
|
522
|
-
if val.to_s =~ /\A\d{1,}\Z/
|
523
|
-
return find_user_group_by_id(account_id, val)
|
524
|
-
else
|
525
|
-
return find_user_group_by_name(account_id, val)
|
526
|
-
end
|
527
|
-
end
|
528
|
-
|
529
|
-
def find_user_group_by_id(account_id, id)
|
530
|
-
begin
|
531
|
-
json_response = @user_groups_interface.get(account_id, id.to_i)
|
532
|
-
return json_response['userGroup']
|
533
|
-
rescue RestClient::Exception => e
|
534
|
-
if e.response && e.response.code == 404
|
535
|
-
print_red_alert "User Group not found by id #{id}"
|
536
|
-
else
|
537
|
-
raise e
|
538
|
-
end
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
def find_user_group_by_name(account_id, name)
|
543
|
-
user_groups = @user_groups_interface.list(account_id, {name: name.to_s})['userGroups']
|
544
|
-
if user_groups.empty?
|
545
|
-
print_red_alert "User Group not found by name #{name}"
|
546
|
-
return nil
|
547
|
-
elsif user_groups.size > 1
|
548
|
-
print_red_alert "#{user_groups.size} user groups found by name #{name}"
|
549
|
-
print_user_groups_table(user_groups, {color: red})
|
550
|
-
print_red_alert "Try using ID instead"
|
551
|
-
print reset,"\n"
|
552
|
-
return nil
|
553
|
-
else
|
554
|
-
return user_groups[0]
|
555
|
-
end
|
556
|
-
end
|
557
|
-
|
558
513
|
end
|