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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/README.md +8 -6
  4. data/lib/morpheus/api/api_client.rb +32 -14
  5. data/lib/morpheus/api/auth_interface.rb +4 -2
  6. data/lib/morpheus/api/backup_jobs_interface.rb +9 -0
  7. data/lib/morpheus/api/backups_interface.rb +16 -0
  8. data/lib/morpheus/api/deploy_interface.rb +25 -56
  9. data/lib/morpheus/api/deployments_interface.rb +43 -54
  10. data/lib/morpheus/api/doc_interface.rb +57 -0
  11. data/lib/morpheus/api/instances_interface.rb +5 -0
  12. data/lib/morpheus/api/rest_interface.rb +40 -0
  13. data/lib/morpheus/api/user_sources_interface.rb +0 -15
  14. data/lib/morpheus/api/users_interface.rb +2 -3
  15. data/lib/morpheus/benchmarking.rb +2 -2
  16. data/lib/morpheus/cli.rb +3 -1
  17. data/lib/morpheus/cli/access_token_command.rb +27 -10
  18. data/lib/morpheus/cli/apps.rb +21 -15
  19. data/lib/morpheus/cli/backup_jobs_command.rb +276 -0
  20. data/lib/morpheus/cli/backups_command.rb +271 -0
  21. data/lib/morpheus/cli/boot_scripts_command.rb +1 -1
  22. data/lib/morpheus/cli/cli_command.rb +92 -41
  23. data/lib/morpheus/cli/clusters.rb +0 -18
  24. data/lib/morpheus/cli/commands/standard/benchmark_command.rb +7 -7
  25. data/lib/morpheus/cli/commands/standard/man_command.rb +1 -1
  26. data/lib/morpheus/cli/credentials.rb +13 -9
  27. data/lib/morpheus/cli/deploy.rb +374 -0
  28. data/lib/morpheus/cli/deployments.rb +521 -197
  29. data/lib/morpheus/cli/deploys.rb +271 -126
  30. data/lib/morpheus/cli/doc.rb +182 -0
  31. data/lib/morpheus/cli/error_handler.rb +23 -8
  32. data/lib/morpheus/cli/errors.rb +3 -2
  33. data/lib/morpheus/cli/image_builder_command.rb +2 -2
  34. data/lib/morpheus/cli/instances.rb +136 -17
  35. data/lib/morpheus/cli/invoices_command.rb +51 -38
  36. data/lib/morpheus/cli/library_layouts_command.rb +1 -1
  37. data/lib/morpheus/cli/login.rb +9 -3
  38. data/lib/morpheus/cli/mixins/accounts_helper.rb +158 -100
  39. data/lib/morpheus/cli/mixins/backups_helper.rb +115 -0
  40. data/lib/morpheus/cli/mixins/deployments_helper.rb +135 -0
  41. data/lib/morpheus/cli/mixins/option_source_helper.rb +1 -1
  42. data/lib/morpheus/cli/mixins/print_helper.rb +110 -74
  43. data/lib/morpheus/cli/mixins/provisioning_helper.rb +2 -2
  44. data/lib/morpheus/cli/mixins/whoami_helper.rb +19 -6
  45. data/lib/morpheus/cli/network_routers_command.rb +1 -1
  46. data/lib/morpheus/cli/option_parser.rb +48 -5
  47. data/lib/morpheus/cli/option_types.rb +1 -1
  48. data/lib/morpheus/cli/remote.rb +3 -2
  49. data/lib/morpheus/cli/roles.rb +49 -92
  50. data/lib/morpheus/cli/security_groups.rb +7 -1
  51. data/lib/morpheus/cli/service_plans_command.rb +10 -10
  52. data/lib/morpheus/cli/setup.rb +1 -1
  53. data/lib/morpheus/cli/shell.rb +7 -6
  54. data/lib/morpheus/cli/subnets_command.rb +1 -1
  55. data/lib/morpheus/cli/tenants_command.rb +133 -163
  56. data/lib/morpheus/cli/user_groups_command.rb +20 -65
  57. data/lib/morpheus/cli/user_settings_command.rb +115 -13
  58. data/lib/morpheus/cli/user_sources_command.rb +57 -24
  59. data/lib/morpheus/cli/users.rb +210 -186
  60. data/lib/morpheus/cli/version.rb +1 -1
  61. data/lib/morpheus/cli/whitelabel_settings_command.rb +29 -5
  62. data/lib/morpheus/cli/whoami.rb +113 -6
  63. data/lib/morpheus/cli/workflows.rb +1 -1
  64. data/lib/morpheus/ext/hash.rb +21 -0
  65. data/lib/morpheus/terminal.rb +1 -0
  66. metadata +12 -3
  67. 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, [:account, :auto_confirm, :json, :dry_run, :remote])
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
- build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
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
- begin
51
- params = {}
52
- params.merge!(parse_list_options(options))
53
- @accounts_interface.setopts(options)
54
- if options[:dry_run]
55
- print_dry_run @accounts_interface.dry.list(params)
56
- return 0
57
- end
58
- json_response = @accounts_interface.list(params)
59
- render_result = render_with_format(json_response, options, 'accounts')
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
- print_accounts_table(accounts)
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("[name]")
114
- build_common_options(opts, options, [:json, :yaml, :csv, :fields, :outfile, :dry_run, :remote])
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
- if args.count != 1
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
- begin
122
- @accounts_interface.setopts(options)
123
- if options[:dry_run]
124
- if args[0].to_s =~ /\A\d{1,}\Z/
125
- print_dry_run @accounts_interface.dry.get(args[0].to_i)
126
- else
127
- print_dry_run @accounts_interface.dry.list({name:args[0]})
128
- end
129
- return
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
- account = find_account_by_name_or_id(args[0])
132
- exit 1 if account.nil?
137
+ return
138
+ end
139
+ account = find_account_by_name_or_id(args[0])
140
+ exit 1 if account.nil?
133
141
 
134
- json_response = {'account' => account}
135
- render_result = render_with_format(json_response, options, 'account')
136
- return 0 if render_result
142
+ json_response = {'account' => account}
143
+ render_result = render_with_format(json_response, options, 'account')
144
+ return 0 if render_result
137
145
 
138
- print_h1 "Tenant Details", [], options
139
-
140
- description_cols = {
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
- print reset,"\n"
161
- return 0
162
- rescue RestClient::Exception => e
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("[options]")
160
+ opts.banner = subcommand_usage("[name]")
172
161
  build_option_type_options(opts, options, add_account_option_types)
173
- build_common_options(opts, options, [:options, :json, :remote, :dry_run])
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
- begin
178
- if args.count > 1
179
- raise_command_error "wrong number of arguments. Expected 0-1 and received #{args.count} #{args.join(' ')}\n#{optparse}", args, 127
180
- #puts_error "#{Morpheus::Terminal.angry_prompt}wrong number of arguments. Expected 0-1 and received #{args.count} #{args.join(' ')}\n#{optparse}"
181
- #return 127
182
- end
183
- if args[0]
184
- options[:options]['name'] = args[0]
185
- end
186
- params = Morpheus::Cli::OptionTypes.prompt(add_account_option_types, options[:options], @api_client, options[:params])
187
- #puts "parsed params is : #{params.inspect}"
188
- account_keys = ['name', 'description', 'currency']
189
- account_payload = params.select {|k,v| account_keys.include?(k) }
190
- account_payload['currency'] = account_payload['currency'].to_s.empty? ? "USD" : account_payload['currency'].upcase
191
-
192
- if params['role'].to_s != ''
193
- role = find_role_by_name(nil, params['role'])
194
- exit 1 if role.nil?
195
- account_payload['role'] = {id: role['id']}
196
- end
197
- payload = {account: account_payload}
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("[name] [options]")
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
- build_common_options(opts, options, [:options, :json, :remote, :dry_run])
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
- if args.count < 1
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
- #params = Morpheus::Cli::OptionTypes.prompt(update_account_option_types, options[:options], @api_client, options[:params])
245
- params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
246
-
247
- if params.empty?
248
- puts optparse
249
- exit 1
250
- end
251
-
252
- #puts "parsed params is : #{params.inspect}"
253
- #account_keys = ['name', 'description', 'currency']
254
- account_payload = params
255
- account_payload['currency'] = account_payload['currency'].upcase unless account_payload['currency'].to_s.empty?
256
-
257
- if params['role'].to_s != ''
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
- json_response = @accounts_interface.update(account['id'], payload)
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
- rescue RestClient::Exception => e
283
- print_rest_exception(e, options)
284
- exit 1
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
- {'fieldName' => 'role', 'fieldLabel' => 'Base Role', 'type' => 'text', 'displayOrder' => 3},
337
- {'fieldName' => 'currency', 'fieldLabel' => 'Currency', 'type' => 'text', 'displayOrder' => 4}
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
- build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
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
- begin
34
- params.merge!(parse_list_options(options))
35
- @user_groups_interface.setopts(options)
36
- if options[:dry_run]
37
- print_dry_run @user_groups_interface.dry.list(nil, params)
38
- return
39
- end
40
- json_response = @user_groups_interface.list(nil, params)
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
- print_user_groups_table(user_groups, options)
60
- print_results_pagination(json_response, {:label => "user group", :n_label => "user groups"})
61
- # print_results_pagination(json_response)
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
- description_cols = {
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