morpheus-cli 0.9.9 → 0.9.10
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/lib/morpheus/api/api_client.rb +4 -0
- data/lib/morpheus/api/app_templates_interface.rb +74 -0
- data/lib/morpheus/api/instance_types_interface.rb +9 -0
- data/lib/morpheus/api/instances_interface.rb +16 -0
- data/lib/morpheus/api/roles_interface.rb +37 -1
- data/lib/morpheus/cli.rb +4 -1
- data/lib/morpheus/cli/accounts.rb +82 -58
- data/lib/morpheus/cli/app_templates.rb +908 -0
- data/lib/morpheus/cli/apps.rb +226 -187
- data/lib/morpheus/cli/cli_command.rb +57 -30
- data/lib/morpheus/cli/clouds.rb +50 -65
- data/lib/morpheus/cli/deployments.rb +18 -33
- data/lib/morpheus/cli/deploys.rb +1 -3
- data/lib/morpheus/cli/groups.rb +54 -38
- data/lib/morpheus/cli/hosts.rb +86 -80
- data/lib/morpheus/cli/instance_types.rb +42 -29
- data/lib/morpheus/cli/instances.rb +192 -69
- data/lib/morpheus/cli/key_pairs.rb +70 -87
- data/lib/morpheus/cli/license.rb +7 -9
- data/lib/morpheus/cli/load_balancers.rb +23 -53
- data/lib/morpheus/cli/mixins/accounts_helper.rb +7 -8
- data/lib/morpheus/cli/mixins/print_helper.rb +67 -0
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +461 -0
- data/lib/morpheus/cli/option_types.rb +71 -18
- data/lib/morpheus/cli/roles.rb +725 -34
- data/lib/morpheus/cli/security_group_rules.rb +50 -70
- data/lib/morpheus/cli/security_groups.rb +61 -48
- data/lib/morpheus/cli/shell.rb +123 -14
- data/lib/morpheus/cli/tasks.rb +24 -59
- data/lib/morpheus/cli/users.rb +86 -71
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +21 -51
- data/lib/morpheus/cli/workflows.rb +14 -29
- data/lib/morpheus/ext/nil_class.rb +5 -0
- data/lib/morpheus/formatters.rb +1 -0
- metadata +7 -3
- data/lib/morpheus/cli/error_handler.rb +0 -44
data/lib/morpheus/cli/tasks.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
# require 'yaml'
|
2
2
|
require 'io/console'
|
3
3
|
require 'rest_client'
|
4
|
-
require 'term/ansicolor'
|
5
4
|
require 'optparse'
|
6
5
|
require 'table_print'
|
7
6
|
require 'morpheus/cli/cli_command'
|
8
7
|
|
9
8
|
class Morpheus::Cli::Tasks
|
10
9
|
include Morpheus::Cli::CliCommand
|
11
|
-
|
10
|
+
|
12
11
|
def initialize()
|
13
12
|
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
14
13
|
end
|
@@ -25,7 +24,7 @@ class Morpheus::Cli::Tasks
|
|
25
24
|
@tasks_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).tasks
|
26
25
|
@task_sets_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).task_sets
|
27
26
|
if @access_token.empty?
|
28
|
-
|
27
|
+
print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
|
29
28
|
exit 1
|
30
29
|
end
|
31
30
|
end
|
@@ -60,20 +59,14 @@ class Morpheus::Cli::Tasks
|
|
60
59
|
options = {}
|
61
60
|
optparse = OptionParser.new do|opts|
|
62
61
|
opts.banner = "Usage: morpheus tasks list [-s] [-o] [-m]"
|
63
|
-
|
62
|
+
build_common_options(opts, options, [:list, :json, :remote])
|
64
63
|
end
|
65
64
|
optparse.parse(args)
|
66
65
|
connect(options)
|
67
66
|
begin
|
68
67
|
params = {}
|
69
|
-
|
70
|
-
params[
|
71
|
-
end
|
72
|
-
if options[:max]
|
73
|
-
params[:max] = options[:max]
|
74
|
-
end
|
75
|
-
if options[:phrase]
|
76
|
-
params[:phrase] = options[:phrase]
|
68
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
69
|
+
params[k] = options[k] unless options[k].nil?
|
77
70
|
end
|
78
71
|
json_response = @tasks_interface.get(params)
|
79
72
|
if options[:json]
|
@@ -94,13 +87,8 @@ class Morpheus::Cli::Tasks
|
|
94
87
|
end
|
95
88
|
|
96
89
|
|
97
|
-
rescue => e
|
98
|
-
|
99
|
-
error = JSON.parse(e.response.to_s)
|
100
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
|
101
|
-
else
|
102
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
103
|
-
end
|
90
|
+
rescue RestClient::Exception => e
|
91
|
+
print_rest_exception(e, options)
|
104
92
|
exit 1
|
105
93
|
end
|
106
94
|
end
|
@@ -110,7 +98,7 @@ class Morpheus::Cli::Tasks
|
|
110
98
|
options = {}
|
111
99
|
optparse = OptionParser.new do|opts|
|
112
100
|
opts.banner = "Usage: morpheus tasks details [task]"
|
113
|
-
|
101
|
+
build_common_options(opts, options, [:json, :remote])
|
114
102
|
end
|
115
103
|
if args.count < 1
|
116
104
|
puts "\n#{optparse.banner}\n\n"
|
@@ -133,12 +121,7 @@ class Morpheus::Cli::Tasks
|
|
133
121
|
print reset,"\n\n"
|
134
122
|
end
|
135
123
|
rescue RestClient::Exception => e
|
136
|
-
|
137
|
-
error = JSON.parse(e.response.to_s)
|
138
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
|
139
|
-
else
|
140
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
141
|
-
end
|
124
|
+
print_rest_exception(e, options)
|
142
125
|
exit 1
|
143
126
|
end
|
144
127
|
end
|
@@ -149,7 +132,7 @@ class Morpheus::Cli::Tasks
|
|
149
132
|
account_name = nil
|
150
133
|
optparse = OptionParser.new do|opts|
|
151
134
|
opts.banner = "Usage: morpheus tasks update [task] [options]"
|
152
|
-
|
135
|
+
build_common_options(opts, options, [:options, :json, :remote])
|
153
136
|
end
|
154
137
|
if args.count < 1
|
155
138
|
puts "\n#{optparse.banner}\n\n"
|
@@ -198,12 +181,7 @@ class Morpheus::Cli::Tasks
|
|
198
181
|
print "\n", cyan, "Task #{response['task']['name']} updated", reset, "\n\n"
|
199
182
|
end
|
200
183
|
rescue RestClient::Exception => e
|
201
|
-
|
202
|
-
error = JSON.parse(e.response.to_s)
|
203
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
204
|
-
else
|
205
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
206
|
-
end
|
184
|
+
print_rest_exception(e, options)
|
207
185
|
exit 1
|
208
186
|
end
|
209
187
|
end
|
@@ -213,7 +191,7 @@ class Morpheus::Cli::Tasks
|
|
213
191
|
options = {}
|
214
192
|
optparse = OptionParser.new do|opts|
|
215
193
|
opts.banner = "Usage: morpheus tasks task-types"
|
216
|
-
|
194
|
+
build_common_options(opts, options, [:json, :remote])
|
217
195
|
end
|
218
196
|
optparse.parse(args)
|
219
197
|
connect(options)
|
@@ -238,13 +216,8 @@ class Morpheus::Cli::Tasks
|
|
238
216
|
end
|
239
217
|
|
240
218
|
|
241
|
-
rescue => e
|
242
|
-
|
243
|
-
error = JSON.parse(e.response.to_s)
|
244
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
|
245
|
-
else
|
246
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
247
|
-
end
|
219
|
+
rescue RestClient::Exception => e
|
220
|
+
print_rest_exception(e, options)
|
248
221
|
exit 1
|
249
222
|
end
|
250
223
|
end
|
@@ -258,7 +231,7 @@ class Morpheus::Cli::Tasks
|
|
258
231
|
opts.on( '-t', '--type TASK_TYPE', "Task Type" ) do |val|
|
259
232
|
task_type_name = val
|
260
233
|
end
|
261
|
-
|
234
|
+
build_common_options(opts, options, [:options, :json, :remote])
|
262
235
|
end
|
263
236
|
if args.count < 1
|
264
237
|
puts "\n#{optparse.banner}\n\n"
|
@@ -286,12 +259,7 @@ class Morpheus::Cli::Tasks
|
|
286
259
|
print "\n", cyan, "Task #{json_response['task']['name']} created successfully", reset, "\n\n"
|
287
260
|
end
|
288
261
|
rescue RestClient::Exception => e
|
289
|
-
|
290
|
-
error = JSON.parse(e.response.to_s)
|
291
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
|
292
|
-
else
|
293
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
294
|
-
end
|
262
|
+
print_rest_exception(e, options)
|
295
263
|
exit 1
|
296
264
|
end
|
297
265
|
end
|
@@ -301,7 +269,7 @@ class Morpheus::Cli::Tasks
|
|
301
269
|
options = {}
|
302
270
|
optparse = OptionParser.new do|opts|
|
303
271
|
opts.banner = "Usage: morpheus tasks remove [task]"
|
304
|
-
|
272
|
+
build_common_options(opts, options, [:auto_confirm, :json, :remote])
|
305
273
|
end
|
306
274
|
if args.count < 1
|
307
275
|
puts "\n#{optparse.banner}\n\n"
|
@@ -312,7 +280,9 @@ class Morpheus::Cli::Tasks
|
|
312
280
|
begin
|
313
281
|
task = find_task_by_name_or_code_or_id(task_name)
|
314
282
|
exit 1 if task.nil?
|
315
|
-
|
283
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the task #{task['name']}?")
|
284
|
+
exit
|
285
|
+
end
|
316
286
|
json_response = @tasks_interface.destroy(task['id'])
|
317
287
|
if options[:json]
|
318
288
|
print JSON.pretty_generate(json_response)
|
@@ -320,12 +290,7 @@ class Morpheus::Cli::Tasks
|
|
320
290
|
print "\n", cyan, "Task #{task['name']} removed", reset, "\n\n"
|
321
291
|
end
|
322
292
|
rescue RestClient::Exception => e
|
323
|
-
|
324
|
-
error = JSON.parse(e.response.to_s)
|
325
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
|
326
|
-
else
|
327
|
-
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
328
|
-
end
|
293
|
+
print_rest_exception(e, options)
|
329
294
|
exit 1
|
330
295
|
end
|
331
296
|
end
|
@@ -343,7 +308,7 @@ private
|
|
343
308
|
result = results['task']
|
344
309
|
end
|
345
310
|
if result.nil?
|
346
|
-
|
311
|
+
print_red_alert "Task not found by '#{val}'"
|
347
312
|
return nil
|
348
313
|
end
|
349
314
|
return result
|
@@ -360,7 +325,7 @@ private
|
|
360
325
|
result = results['taskType']
|
361
326
|
end
|
362
327
|
if result.nil?
|
363
|
-
|
328
|
+
print_red_alert "Task Type not found by '#{val}'"
|
364
329
|
return nil
|
365
330
|
end
|
366
331
|
return result
|
@@ -371,4 +336,4 @@ private
|
|
371
336
|
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 0}
|
372
337
|
] + task_type['optionTypes']
|
373
338
|
end
|
374
|
-
end
|
339
|
+
end
|
data/lib/morpheus/cli/users.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# require 'yaml'
|
2
2
|
require 'io/console'
|
3
3
|
require 'rest_client'
|
4
|
-
require 'term/ansicolor'
|
5
4
|
require 'optparse'
|
6
5
|
require 'morpheus/cli/cli_command'
|
7
6
|
require 'morpheus/cli/option_types'
|
@@ -9,7 +8,6 @@ require 'morpheus/cli/mixins/accounts_helper'
|
|
9
8
|
require 'json'
|
10
9
|
|
11
10
|
class Morpheus::Cli::Users
|
12
|
-
include Term::ANSIColor
|
13
11
|
include Morpheus::Cli::CliCommand
|
14
12
|
include Morpheus::Cli::AccountsHelper
|
15
13
|
|
@@ -21,7 +19,7 @@ class Morpheus::Cli::Users
|
|
21
19
|
def connect(opts)
|
22
20
|
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
|
23
21
|
if @access_token.empty?
|
24
|
-
|
22
|
+
print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
|
25
23
|
exit 1
|
26
24
|
end
|
27
25
|
@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
|
@@ -57,12 +55,9 @@ class Morpheus::Cli::Users
|
|
57
55
|
def list(args)
|
58
56
|
usage = "Usage: morpheus users list [options]"
|
59
57
|
options = {}
|
60
|
-
params = {}
|
61
|
-
account = nil
|
62
58
|
optparse = OptionParser.new do|opts|
|
63
59
|
opts.banner = usage
|
64
|
-
|
65
|
-
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
60
|
+
build_common_options(opts, options, [:account, :list, :json])
|
66
61
|
end
|
67
62
|
optparse.parse(args)
|
68
63
|
connect(options)
|
@@ -71,6 +66,7 @@ class Morpheus::Cli::Users
|
|
71
66
|
account = find_account_from_options(options)
|
72
67
|
account_id = account ? account['id'] : nil
|
73
68
|
|
69
|
+
params = {}
|
74
70
|
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
75
71
|
params[k] = options[k] unless options[k].nil?
|
76
72
|
end
|
@@ -91,27 +87,26 @@ class Morpheus::Cli::Users
|
|
91
87
|
print reset,"\n\n"
|
92
88
|
end
|
93
89
|
rescue RestClient::Exception => e
|
94
|
-
|
90
|
+
print_rest_exception(e, options)
|
95
91
|
exit 1
|
96
92
|
end
|
97
93
|
end
|
98
94
|
|
99
95
|
def details(args)
|
100
96
|
usage = "Usage: morpheus users details [username] [options]"
|
101
|
-
if args.count < 1
|
102
|
-
puts "\n#{usage}\n\n"
|
103
|
-
exit 1
|
104
|
-
end
|
105
|
-
account = nil
|
106
|
-
username = args[0]
|
107
97
|
options = {}
|
108
|
-
params = {}
|
109
98
|
optparse = OptionParser.new do|opts|
|
110
99
|
opts.banner = usage
|
111
|
-
|
112
|
-
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
100
|
+
build_common_options(opts, options, [:account, :json])
|
113
101
|
end
|
114
102
|
optparse.parse(args)
|
103
|
+
|
104
|
+
if args.count < 1
|
105
|
+
puts "\n#{usage}\n\n"
|
106
|
+
exit 1
|
107
|
+
end
|
108
|
+
username = args[0]
|
109
|
+
|
115
110
|
connect(options)
|
116
111
|
begin
|
117
112
|
|
@@ -124,7 +119,7 @@ class Morpheus::Cli::Users
|
|
124
119
|
exit 1 if user.nil?
|
125
120
|
|
126
121
|
if options[:json]
|
127
|
-
print JSON.pretty_generate(user)
|
122
|
+
print JSON.pretty_generate({user:user})
|
128
123
|
print "\n"
|
129
124
|
else
|
130
125
|
print "\n" ,cyan, bold, "User Details\n","==================", reset, "\n\n"
|
@@ -146,24 +141,17 @@ class Morpheus::Cli::Users
|
|
146
141
|
print reset,"\n\n"
|
147
142
|
end
|
148
143
|
rescue RestClient::Exception => e
|
149
|
-
|
144
|
+
print_rest_exception(e, options)
|
150
145
|
exit 1
|
151
146
|
end
|
152
147
|
end
|
153
148
|
|
154
149
|
def add(args)
|
155
150
|
usage = "Usage: morpheus users add [options]"
|
156
|
-
# if args.count > 0
|
157
|
-
# puts "\#{usage}\n\n"
|
158
|
-
# exit 1
|
159
|
-
# end
|
160
151
|
options = {}
|
161
|
-
#options['username'] = args[0] if args[0]
|
162
|
-
account = nil
|
163
152
|
optparse = OptionParser.new do|opts|
|
164
153
|
opts.banner = usage
|
165
|
-
|
166
|
-
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
154
|
+
build_common_options(opts, options, [:account, :options, :json])
|
167
155
|
end
|
168
156
|
optparse.parse(args)
|
169
157
|
|
@@ -174,55 +162,63 @@ class Morpheus::Cli::Users
|
|
174
162
|
account = find_account_from_options(options)
|
175
163
|
account_id = account ? account['id'] : nil
|
176
164
|
|
177
|
-
|
178
|
-
params = Morpheus::Cli::OptionTypes.prompt(add_user_option_types, options[:options], @api_client, options[:params]) # options[:params] is mysterious
|
165
|
+
params = Morpheus::Cli::OptionTypes.prompt(add_user_option_types, options[:options], @api_client, options[:params])
|
179
166
|
|
180
167
|
#puts "parsed params is : #{params.inspect}"
|
181
168
|
user_keys = ['username', 'firstName', 'lastName', 'email', 'password', 'passwordConfirmation', 'instanceLimits']
|
182
169
|
user_payload = params.select {|k,v| user_keys.include?(k) }
|
170
|
+
if !user_payload['instanceLimits']
|
171
|
+
user_payload['instanceLimits'] = {}
|
172
|
+
user_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
173
|
+
user_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
174
|
+
user_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
175
|
+
end
|
183
176
|
if params['role'].to_s != ''
|
184
177
|
role = find_role_by_name(account_id, params['role'])
|
185
178
|
exit 1 if role.nil?
|
186
179
|
user_payload['role'] = {id: role['id']}
|
187
180
|
end
|
188
181
|
request_payload = {user: user_payload}
|
189
|
-
|
182
|
+
json_response = @users_interface.create(account_id, request_payload)
|
190
183
|
|
191
|
-
if
|
192
|
-
|
184
|
+
if options[:json]
|
185
|
+
print JSON.pretty_generate(json_response)
|
186
|
+
print "\n"
|
193
187
|
else
|
194
|
-
|
195
|
-
|
188
|
+
if account
|
189
|
+
print_green_success "Added user #{user_payload['username']} to account #{account['name']}"
|
190
|
+
else
|
191
|
+
print_green_success "Added user #{user_payload['username']}"
|
192
|
+
end
|
196
193
|
|
197
|
-
|
198
|
-
|
199
|
-
|
194
|
+
details_options = [user_payload["username"]]
|
195
|
+
if account
|
196
|
+
details_options.push "--account-id", account['id'].to_s
|
197
|
+
end
|
198
|
+
details(details_options)
|
200
199
|
end
|
201
|
-
details(details_options)
|
202
200
|
|
203
201
|
rescue RestClient::Exception => e
|
204
|
-
|
202
|
+
print_rest_exception(e, options)
|
205
203
|
exit 1
|
206
204
|
end
|
207
205
|
end
|
208
206
|
|
209
207
|
def update(args)
|
210
208
|
usage = "Usage: morpheus users update [username] [options]"
|
211
|
-
if args.count < 1
|
212
|
-
puts "\n#{usage}\n\n"
|
213
|
-
exit 1
|
214
|
-
end
|
215
|
-
account = nil
|
216
|
-
username = args[0]
|
217
209
|
options = {}
|
218
|
-
#options['username'] = args[0] if args[0]
|
219
210
|
optparse = OptionParser.new do|opts|
|
220
211
|
opts.banner = usage
|
221
|
-
|
222
|
-
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
212
|
+
build_common_options(opts, options, [:account, :options, :json])
|
223
213
|
end
|
224
214
|
optparse.parse(args)
|
225
215
|
|
216
|
+
if args.count < 1
|
217
|
+
puts "\n#{usage}\n\n"
|
218
|
+
exit 1
|
219
|
+
end
|
220
|
+
username = args[0]
|
221
|
+
|
226
222
|
connect(options)
|
227
223
|
|
228
224
|
begin
|
@@ -233,11 +229,11 @@ class Morpheus::Cli::Users
|
|
233
229
|
user = find_user_by_username(account_id, username)
|
234
230
|
exit 1 if user.nil?
|
235
231
|
|
236
|
-
#params = Morpheus::Cli::OptionTypes.prompt(
|
232
|
+
#params = Morpheus::Cli::OptionTypes.prompt(update_user_option_types, options[:options], @api_client, options[:params])
|
237
233
|
params = options[:options] || {}
|
238
234
|
|
239
235
|
if params.empty?
|
240
|
-
puts "\n#{usage}\n"
|
236
|
+
puts "\n#{usage}\n\n"
|
241
237
|
option_lines = update_user_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n")
|
242
238
|
puts "\nAvailable Options:\n#{option_lines}\n\n"
|
243
239
|
exit 1
|
@@ -246,43 +242,53 @@ class Morpheus::Cli::Users
|
|
246
242
|
#puts "parsed params is : #{params.inspect}"
|
247
243
|
user_keys = ['username', 'firstName', 'lastName', 'email', 'password', 'instanceLimits']
|
248
244
|
user_payload = params.select {|k,v| user_keys.include?(k) }
|
245
|
+
if !user_payload['instanceLimits']
|
246
|
+
user_payload['instanceLimits'] = {}
|
247
|
+
user_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
248
|
+
user_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
249
|
+
user_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
250
|
+
end
|
249
251
|
if params['role'].to_s != ''
|
250
252
|
role = find_role_by_name(account_id, params['role'])
|
251
253
|
exit 1 if role.nil?
|
252
254
|
user_payload['role'] = {id: role['id']}
|
253
255
|
end
|
254
256
|
request_payload = {user: user_payload}
|
255
|
-
|
257
|
+
json_response = @users_interface.update(account_id, user['id'], request_payload)
|
256
258
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
259
|
+
if options[:json]
|
260
|
+
print JSON.pretty_generate(json_response)
|
261
|
+
print "\n"
|
262
|
+
else
|
263
|
+
print_green_success "Updated user #{user_payload['username']}"
|
264
|
+
details_options = [user_payload["username"] || user['username']]
|
265
|
+
if account
|
266
|
+
details_options.push "--account-id", account['id'].to_s
|
267
|
+
end
|
268
|
+
details(details_options)
|
262
269
|
end
|
263
|
-
details(details_options)
|
264
270
|
|
265
271
|
rescue RestClient::Exception => e
|
266
|
-
|
272
|
+
print_rest_exception(e, options)
|
267
273
|
exit 1
|
268
274
|
end
|
269
275
|
end
|
270
276
|
|
271
277
|
def remove(args)
|
272
278
|
usage = "Usage: morpheus users remove [username]"
|
273
|
-
if args.count < 1
|
274
|
-
puts "\n#{usage}\n"
|
275
|
-
exit 1
|
276
|
-
end
|
277
|
-
account = nil
|
278
|
-
username = args[0]
|
279
279
|
options = {}
|
280
280
|
optparse = OptionParser.new do|opts|
|
281
281
|
opts.banner = usage
|
282
|
-
|
283
|
-
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
282
|
+
build_common_options(opts, options, [:account, :auto_confirm, :json])
|
284
283
|
end
|
285
284
|
optparse.parse(args)
|
285
|
+
|
286
|
+
if args.count < 1
|
287
|
+
puts "\n#{usage}\n\n"
|
288
|
+
exit 1
|
289
|
+
end
|
290
|
+
username = args[0]
|
291
|
+
|
286
292
|
connect(options)
|
287
293
|
begin
|
288
294
|
|
@@ -291,12 +297,21 @@ class Morpheus::Cli::Users
|
|
291
297
|
|
292
298
|
user = find_user_by_username(account_id, username)
|
293
299
|
exit 1 if user.nil?
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
300
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the user #{user['username']}?")
|
301
|
+
exit
|
302
|
+
end
|
303
|
+
json_response = @users_interface.destroy(account_id, user['id'])
|
304
|
+
|
305
|
+
if options[:json]
|
306
|
+
print JSON.pretty_generate(json_response)
|
307
|
+
print "\n"
|
308
|
+
else
|
309
|
+
print_green_success "User #{username} removed"
|
310
|
+
# list([])
|
311
|
+
end
|
312
|
+
|
298
313
|
rescue RestClient::Exception => e
|
299
|
-
|
314
|
+
print_rest_exception(e, options)
|
300
315
|
exit 1
|
301
316
|
end
|
302
317
|
end
|