morpheus-cli 3.6.8 → 3.6.9
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/account_groups_interface.rb +2 -2
- data/lib/morpheus/api/accounts_interface.rb +4 -7
- data/lib/morpheus/api/api_client.rb +207 -70
- data/lib/morpheus/api/app_templates_interface.rb +7 -28
- data/lib/morpheus/api/apps_interface.rb +14 -21
- data/lib/morpheus/api/archive_buckets_interface.rb +2 -2
- data/lib/morpheus/api/archive_files_interface.rb +6 -6
- data/lib/morpheus/api/auth_interface.rb +14 -1
- data/lib/morpheus/api/blueprints_interface.rb +9 -16
- data/lib/morpheus/api/cloud_datastores_interface.rb +1 -1
- data/lib/morpheus/api/cloud_policies_interface.rb +1 -1
- data/lib/morpheus/api/clouds_interface.rb +18 -21
- data/lib/morpheus/api/cypher_interface.rb +19 -28
- data/lib/morpheus/api/file_copy_request_interface.rb +1 -1
- data/lib/morpheus/api/group_policies_interface.rb +1 -1
- data/lib/morpheus/api/groups_interface.rb +4 -4
- data/lib/morpheus/api/image_builder_boot_scripts_interface.rb +1 -1
- data/lib/morpheus/api/image_builder_image_builds_interface.rb +2 -2
- data/lib/morpheus/api/image_builder_preseed_scripts_interface.rb +1 -1
- data/lib/morpheus/api/instances_interface.rb +17 -23
- data/lib/morpheus/api/logs_interface.rb +7 -10
- data/lib/morpheus/api/network_domains_interface.rb +1 -1
- data/lib/morpheus/api/network_groups_interface.rb +1 -1
- data/lib/morpheus/api/network_pool_servers_interface.rb +1 -1
- data/lib/morpheus/api/network_pools_interface.rb +1 -1
- data/lib/morpheus/api/network_proxies_interface.rb +1 -1
- data/lib/morpheus/api/network_services_interface.rb +1 -1
- data/lib/morpheus/api/networks_interface.rb +1 -1
- data/lib/morpheus/api/old_cypher_interface.rb +55 -0
- data/lib/morpheus/api/packages_interface.rb +1 -1
- data/lib/morpheus/api/policies_interface.rb +1 -1
- data/lib/morpheus/api/setup_interface.rb +1 -1
- data/lib/morpheus/api/storage_providers_interface.rb +1 -1
- data/lib/morpheus/api/whoami_interface.rb +1 -1
- data/lib/morpheus/benchmarking.rb +277 -0
- data/lib/morpheus/cli.rb +6 -22
- data/lib/morpheus/cli/access_token_command.rb +172 -0
- data/lib/morpheus/cli/accounts.rb +5 -0
- data/lib/morpheus/cli/apps.rb +93 -37
- data/lib/morpheus/cli/archives_command.rb +0 -2
- data/lib/morpheus/cli/auth_command.rb +112 -0
- data/lib/morpheus/cli/blueprints_command.rb +50 -13
- data/lib/morpheus/cli/change_password_command.rb +148 -0
- data/lib/morpheus/cli/cli_command.rb +173 -49
- data/lib/morpheus/cli/clouds.rb +15 -5
- data/lib/morpheus/cli/command_error.rb +7 -1
- data/lib/morpheus/cli/{alias_command.rb → commands/standard/alias_command.rb} +79 -51
- data/lib/morpheus/cli/commands/standard/benchmark_command.rb +399 -0
- data/lib/morpheus/cli/commands/standard/coloring_command.rb +60 -0
- data/lib/morpheus/cli/{curl_command.rb → commands/standard/curl_command.rb} +0 -7
- data/lib/morpheus/cli/commands/standard/debug_command.rb +61 -0
- data/lib/morpheus/cli/{echo_command.rb → commands/standard/echo_command.rb} +1 -1
- data/lib/morpheus/cli/{edit_profile_command.rb → commands/standard/edit_profile_command.rb} +0 -0
- data/lib/morpheus/cli/{edit_rc_command.rb → commands/standard/edit_rc_command.rb} +0 -0
- data/lib/morpheus/cli/commands/standard/get_prompt_command.rb +39 -0
- data/lib/morpheus/cli/commands/standard/history_command.rb +76 -0
- data/lib/morpheus/cli/{log_level_command.rb → commands/standard/log_level_command.rb} +1 -1
- data/lib/morpheus/cli/{man_command.rb → commands/standard/man_command.rb} +2 -2
- data/lib/morpheus/cli/commands/standard/rm_command.rb +14 -0
- data/lib/morpheus/cli/commands/standard/set_prompt_command.rb +54 -0
- data/lib/morpheus/cli/{sleep_command.rb → commands/standard/sleep_command.rb} +0 -0
- data/lib/morpheus/cli/{source_command.rb → commands/standard/source_command.rb} +0 -0
- data/lib/morpheus/cli/{ssl_verification_command.rb → commands/standard/ssl_verification_command.rb} +1 -1
- data/lib/morpheus/cli/commands/standard/tee_command.rb +14 -0
- data/lib/morpheus/cli/{version_command.rb → commands/standard/version_command.rb} +0 -0
- data/lib/morpheus/cli/credentials.rb +276 -87
- data/lib/morpheus/cli/cypher_command.rb +333 -214
- data/lib/morpheus/cli/error_handler.rb +12 -2
- data/lib/morpheus/cli/groups.rb +44 -20
- data/lib/morpheus/cli/hosts.rb +39 -16
- data/lib/morpheus/cli/instances.rb +114 -62
- data/lib/morpheus/cli/login.rb +74 -21
- data/lib/morpheus/cli/logout.rb +3 -4
- data/lib/morpheus/cli/mixins/accounts_helper.rb +50 -18
- data/lib/morpheus/cli/mixins/print_helper.rb +207 -42
- data/lib/morpheus/cli/old_cypher_command.rb +414 -0
- data/lib/morpheus/cli/option_parser.rb +6 -1
- data/lib/morpheus/cli/processes_command.rb +3 -0
- data/lib/morpheus/cli/remote.rb +11 -17
- data/lib/morpheus/cli/roles.rb +17 -17
- data/lib/morpheus/cli/security_groups.rb +47 -17
- data/lib/morpheus/cli/shell.rb +139 -79
- data/lib/morpheus/cli/tenants_command.rb +353 -0
- data/lib/morpheus/cli/users.rb +26 -18
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/whoami.rb +14 -10
- data/lib/morpheus/formatters.rb +4 -4
- data/lib/morpheus/logging.rb +16 -8
- data/lib/morpheus/terminal.rb +63 -34
- metadata +28 -15
- data/lib/morpheus/cli/coloring_command.rb +0 -45
- data/lib/morpheus/cli/set_prompt_command.rb +0 -51
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# require 'yaml'
|
|
2
|
+
require 'io/console'
|
|
3
|
+
require 'rest_client'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'morpheus/cli/cli_command'
|
|
6
|
+
require 'morpheus/cli/option_types'
|
|
7
|
+
require 'morpheus/cli/mixins/accounts_helper'
|
|
8
|
+
require 'json'
|
|
9
|
+
|
|
10
|
+
class Morpheus::Cli::TenantsCommand
|
|
11
|
+
include Morpheus::Cli::CliCommand
|
|
12
|
+
include Morpheus::Cli::AccountsHelper
|
|
13
|
+
set_command_name :tenants
|
|
14
|
+
set_command_description "View and manage tenants (accounts)."
|
|
15
|
+
register_subcommands :list, :count, :get, :add, :update, :remove
|
|
16
|
+
alias_subcommand :details, :get
|
|
17
|
+
set_default_subcommand :list
|
|
18
|
+
|
|
19
|
+
# account-groups is under this namespace for now
|
|
20
|
+
register_subcommands :'groups' => :account_groups
|
|
21
|
+
|
|
22
|
+
def initialize()
|
|
23
|
+
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def connect(opts)
|
|
27
|
+
@api_client = establish_remote_appliance_connection(opts)
|
|
28
|
+
@users_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).users
|
|
29
|
+
@accounts_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).accounts
|
|
30
|
+
@roles_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).roles
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def handle(args)
|
|
34
|
+
handle_subcommand(args)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def account_groups(args)
|
|
38
|
+
Morpheus::Cli::AccountGroupsCommand.new.handle(args)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def list(args)
|
|
42
|
+
options = {}
|
|
43
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
44
|
+
opts.banner = subcommand_usage()
|
|
45
|
+
build_common_options(opts, options, [:list, :query, :json, :remote, :dry_run])
|
|
46
|
+
opts.footer = "List tenants."
|
|
47
|
+
end
|
|
48
|
+
optparse.parse!(args)
|
|
49
|
+
connect(options)
|
|
50
|
+
begin
|
|
51
|
+
params = {}
|
|
52
|
+
params.merge!(parse_list_options(options))
|
|
53
|
+
if options[:dry_run]
|
|
54
|
+
print_dry_run @accounts_interface.dry.list(params)
|
|
55
|
+
return
|
|
56
|
+
end
|
|
57
|
+
json_response = @accounts_interface.list(params)
|
|
58
|
+
accounts = json_response['accounts']
|
|
59
|
+
if options[:json]
|
|
60
|
+
print JSON.pretty_generate(json_response)
|
|
61
|
+
print "\n"
|
|
62
|
+
else
|
|
63
|
+
title = "Morpheus Tenants"
|
|
64
|
+
subtitles = []
|
|
65
|
+
subtitles += parse_list_subtitles(options)
|
|
66
|
+
print_h1 title, subtitles
|
|
67
|
+
if accounts.empty?
|
|
68
|
+
puts yellow,"No tenants found.",reset
|
|
69
|
+
else
|
|
70
|
+
print_accounts_table(accounts)
|
|
71
|
+
print_results_pagination(json_response)
|
|
72
|
+
end
|
|
73
|
+
print reset,"\n"
|
|
74
|
+
end
|
|
75
|
+
rescue RestClient::Exception => e
|
|
76
|
+
print_rest_exception(e, options)
|
|
77
|
+
exit 1
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def count(args)
|
|
82
|
+
options = {}
|
|
83
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
84
|
+
opts.banner = subcommand_usage("[options]")
|
|
85
|
+
build_common_options(opts, options, [:query, :remote, :dry_run])
|
|
86
|
+
opts.footer = "Get the number of tenants."
|
|
87
|
+
end
|
|
88
|
+
optparse.parse!(args)
|
|
89
|
+
connect(options)
|
|
90
|
+
begin
|
|
91
|
+
params = {}
|
|
92
|
+
params.merge!(parse_list_options(options))
|
|
93
|
+
if options[:dry_run]
|
|
94
|
+
print_dry_run @accounts_interface.dry.list(params)
|
|
95
|
+
return
|
|
96
|
+
end
|
|
97
|
+
json_response = @accounts_interface.list(params)
|
|
98
|
+
# print number only
|
|
99
|
+
if json_response['meta'] && json_response['meta']['total']
|
|
100
|
+
print cyan, json_response['meta']['total'], reset, "\n"
|
|
101
|
+
else
|
|
102
|
+
print yellow, "unknown", reset, "\n"
|
|
103
|
+
end
|
|
104
|
+
rescue RestClient::Exception => e
|
|
105
|
+
print_rest_exception(e, options)
|
|
106
|
+
exit 1
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def get(args)
|
|
111
|
+
options = {}
|
|
112
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
113
|
+
opts.banner = subcommand_usage("[name]")
|
|
114
|
+
build_common_options(opts, options, [:json, :remote, :dry_run])
|
|
115
|
+
end
|
|
116
|
+
optparse.parse!(args)
|
|
117
|
+
if args.count < 1
|
|
118
|
+
puts optparse
|
|
119
|
+
exit 1
|
|
120
|
+
end
|
|
121
|
+
connect(options)
|
|
122
|
+
begin
|
|
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
|
|
130
|
+
end
|
|
131
|
+
account = find_account_by_name_or_id(args[0])
|
|
132
|
+
exit 1 if account.nil?
|
|
133
|
+
|
|
134
|
+
if options[:json]
|
|
135
|
+
print JSON.pretty_generate({account: account})
|
|
136
|
+
print "\n"
|
|
137
|
+
else
|
|
138
|
+
print_h1 "Account Details"
|
|
139
|
+
print cyan
|
|
140
|
+
puts "ID: #{account['id']}"
|
|
141
|
+
puts "Name: #{account['name']}"
|
|
142
|
+
puts "Description: #{account['description']}"
|
|
143
|
+
puts "Subdomain: #{account['subdomain']}" if !account['subdomain'].to_s.empty?
|
|
144
|
+
puts "Currency: #{account['currency']}"
|
|
145
|
+
# puts "# Users: #{account['usersCount']}"
|
|
146
|
+
# puts "# Instances: #{account['instancesCount']}"
|
|
147
|
+
puts "Date Created: #{format_local_dt(account['dateCreated'])}"
|
|
148
|
+
puts "Last Updated: #{format_local_dt(account['lastUpdated'])}"
|
|
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
|
+
puts "Status: #{status_state}"
|
|
156
|
+
# JD: pretty sure this is deprecated
|
|
157
|
+
# print_h2 "Tenant Instance Limits"
|
|
158
|
+
# print cyan
|
|
159
|
+
# puts "Max Storage (bytes): #{account['instanceLimits'] ? account['instanceLimits']['maxStorage'] : 0}"
|
|
160
|
+
# puts "Max Memory (bytes): #{account['instanceLimits'] ? account['instanceLimits']['maxMemory'] : 0}"
|
|
161
|
+
# puts "CPU Count: #{account['instanceLimits'] ? account['instanceLimits']['maxCpu'] : 0}"
|
|
162
|
+
print reset,"\n"
|
|
163
|
+
end
|
|
164
|
+
rescue RestClient::Exception => e
|
|
165
|
+
print_rest_exception(e, options)
|
|
166
|
+
exit 1
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def add(args)
|
|
171
|
+
options = {}
|
|
172
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
173
|
+
opts.banner = subcommand_usage("[options]")
|
|
174
|
+
build_option_type_options(opts, options, add_account_option_types)
|
|
175
|
+
build_common_options(opts, options, [:options, :json, :remote, :dry_run])
|
|
176
|
+
end
|
|
177
|
+
optparse.parse!(args)
|
|
178
|
+
connect(options)
|
|
179
|
+
begin
|
|
180
|
+
if args.count > 1
|
|
181
|
+
raise_command_error "wrong number of arguments. Expected 0-1 and received #{args.count} #{args.join(' ')}\n#{optparse}", args, 127
|
|
182
|
+
#puts_error "#{Morpheus::Terminal.angry_prompt}wrong number of arguments. Expected 0-1 and received #{args.count} #{args.join(' ')}\n#{optparse}"
|
|
183
|
+
#return 127
|
|
184
|
+
end
|
|
185
|
+
if args[0]
|
|
186
|
+
options[:options]['name'] = args[0]
|
|
187
|
+
end
|
|
188
|
+
params = Morpheus::Cli::OptionTypes.prompt(add_account_option_types, options[:options], @api_client, options[:params])
|
|
189
|
+
#puts "parsed params is : #{params.inspect}"
|
|
190
|
+
account_keys = ['name', 'description', 'currency']
|
|
191
|
+
account_payload = params.select {|k,v| account_keys.include?(k) }
|
|
192
|
+
account_payload['currency'] = account_payload['currency'].to_s.empty? ? "USD" : account_payload['currency'].upcase
|
|
193
|
+
if !account_payload['instanceLimits']
|
|
194
|
+
account_payload['instanceLimits'] = {}
|
|
195
|
+
account_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
|
196
|
+
account_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
|
197
|
+
account_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
|
198
|
+
end
|
|
199
|
+
if params['role'].to_s != ''
|
|
200
|
+
role = find_role_by_name(nil, params['role'])
|
|
201
|
+
exit 1 if role.nil?
|
|
202
|
+
account_payload['role'] = {id: role['id']}
|
|
203
|
+
end
|
|
204
|
+
payload = {account: account_payload}
|
|
205
|
+
if options[:dry_run] && options[:json]
|
|
206
|
+
puts as_json(payload, options)
|
|
207
|
+
return 0
|
|
208
|
+
end
|
|
209
|
+
if options[:dry_run]
|
|
210
|
+
print_dry_run @accounts_interface.dry.create(payload)
|
|
211
|
+
return
|
|
212
|
+
end
|
|
213
|
+
json_response = @accounts_interface.create(payload)
|
|
214
|
+
if options[:json]
|
|
215
|
+
print JSON.pretty_generate(json_response)
|
|
216
|
+
print "\n"
|
|
217
|
+
else
|
|
218
|
+
print_green_success "Account #{account_payload['name']} added"
|
|
219
|
+
get([account_payload["name"]])
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
rescue RestClient::Exception => e
|
|
223
|
+
print_rest_exception(e, options)
|
|
224
|
+
exit 1
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def update(args)
|
|
229
|
+
options = {}
|
|
230
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
231
|
+
opts.banner = subcommand_usage("[name] [options]")
|
|
232
|
+
build_option_type_options(opts, options, update_account_option_types)
|
|
233
|
+
build_common_options(opts, options, [:options, :json, :remote, :dry_run])
|
|
234
|
+
end
|
|
235
|
+
optparse.parse!(args)
|
|
236
|
+
if args.count < 1
|
|
237
|
+
print_red_alert "Specify atleast one option to update"
|
|
238
|
+
puts optparse
|
|
239
|
+
exit 1
|
|
240
|
+
end
|
|
241
|
+
connect(options)
|
|
242
|
+
begin
|
|
243
|
+
account = find_account_by_name_or_id(args[0])
|
|
244
|
+
exit 1 if account.nil?
|
|
245
|
+
|
|
246
|
+
#params = Morpheus::Cli::OptionTypes.prompt(update_account_option_types, options[:options], @api_client, options[:params])
|
|
247
|
+
params = options[:options] || {}
|
|
248
|
+
|
|
249
|
+
if params.empty?
|
|
250
|
+
puts optparse
|
|
251
|
+
exit 1
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
#puts "parsed params is : #{params.inspect}"
|
|
255
|
+
account_keys = ['name', 'description', 'currency', 'instanceLimits']
|
|
256
|
+
account_payload = params.select {|k,v| account_keys.include?(k) }
|
|
257
|
+
account_payload['currency'] = account_payload['currency'].upcase unless account_payload['currency'].to_s.empty?
|
|
258
|
+
if !account_payload['instanceLimits']
|
|
259
|
+
account_payload['instanceLimits'] = {}
|
|
260
|
+
account_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
|
261
|
+
account_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
|
262
|
+
account_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
|
263
|
+
end
|
|
264
|
+
if params['role'].to_s != ''
|
|
265
|
+
role = find_role_by_name(nil, params['role'])
|
|
266
|
+
exit 1 if role.nil?
|
|
267
|
+
account_payload['role'] = {id: role['id']}
|
|
268
|
+
end
|
|
269
|
+
payload = {account: account_payload}
|
|
270
|
+
if options[:dry_run] && options[:json]
|
|
271
|
+
puts as_json(payload, options)
|
|
272
|
+
return 0
|
|
273
|
+
end
|
|
274
|
+
if options[:dry_run]
|
|
275
|
+
print_dry_run @accounts_interface.dry.update(account['id'], payload)
|
|
276
|
+
return
|
|
277
|
+
end
|
|
278
|
+
json_response = @accounts_interface.update(account['id'], payload)
|
|
279
|
+
|
|
280
|
+
if options[:json]
|
|
281
|
+
print JSON.pretty_generate(json_response)
|
|
282
|
+
print "\n"
|
|
283
|
+
else
|
|
284
|
+
account_name = account_payload['name'] || account['name']
|
|
285
|
+
print_green_success "Account #{account_name} updated"
|
|
286
|
+
get([account_name])
|
|
287
|
+
end
|
|
288
|
+
rescue RestClient::Exception => e
|
|
289
|
+
print_rest_exception(e, options)
|
|
290
|
+
exit 1
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
def remove(args)
|
|
295
|
+
options = {}
|
|
296
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
297
|
+
opts.banner = subcommand_usage("[name]")
|
|
298
|
+
build_common_options(opts, options, [:auto_confirm, :json, :remote, :dry_run])
|
|
299
|
+
end
|
|
300
|
+
optparse.parse!(args)
|
|
301
|
+
if args.count < 1
|
|
302
|
+
puts optparse
|
|
303
|
+
exit 1
|
|
304
|
+
end
|
|
305
|
+
connect(options)
|
|
306
|
+
begin
|
|
307
|
+
# allow finding by ID since name is not unique!
|
|
308
|
+
account = find_account_by_name_or_id(args[0])
|
|
309
|
+
exit 1 if account.nil?
|
|
310
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the account #{account['name']}?")
|
|
311
|
+
exit
|
|
312
|
+
end
|
|
313
|
+
if options[:dry_run] && options[:json]
|
|
314
|
+
puts as_json(payload, options)
|
|
315
|
+
return 0
|
|
316
|
+
end
|
|
317
|
+
if options[:dry_run]
|
|
318
|
+
print_dry_run @accounts_interface.dry.destroy(account['id'])
|
|
319
|
+
return
|
|
320
|
+
end
|
|
321
|
+
json_response = @accounts_interface.destroy(account['id'])
|
|
322
|
+
if options[:json]
|
|
323
|
+
print JSON.pretty_generate(json_response)
|
|
324
|
+
print "\n"
|
|
325
|
+
else
|
|
326
|
+
print_green_success "Account #{account['name']} removed"
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
rescue RestClient::Exception => e
|
|
330
|
+
print_rest_exception(e, options)
|
|
331
|
+
exit 1
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
private
|
|
336
|
+
|
|
337
|
+
def add_account_option_types
|
|
338
|
+
[
|
|
339
|
+
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
|
|
340
|
+
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
|
|
341
|
+
{'fieldName' => 'role', 'fieldLabel' => 'Base Role', 'type' => 'text', 'displayOrder' => 3},
|
|
342
|
+
{'fieldName' => 'currency', 'fieldLabel' => 'Currency', 'type' => 'text', 'displayOrder' => 4}
|
|
343
|
+
# {'fieldName' => 'instanceLimits.maxStorage', 'fieldLabel' => 'Max Storage (bytes)', 'type' => 'text', 'displayOrder' => 5},
|
|
344
|
+
# {'fieldName' => 'instanceLimits.maxMemory', 'fieldLabel' => 'Max Memory (bytes)', 'type' => 'text', 'displayOrder' => 6},
|
|
345
|
+
# {'fieldName' => 'instanceLimits.maxCpu', 'fieldLabel' => 'CPU Count', 'type' => 'text', 'displayOrder' => 7},
|
|
346
|
+
]
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def update_account_option_types
|
|
350
|
+
add_account_option_types
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
end
|
data/lib/morpheus/cli/users.rb
CHANGED
|
@@ -69,11 +69,11 @@ class Morpheus::Cli::Users
|
|
|
69
69
|
subtitles << "Account: #{account['name']}".strip
|
|
70
70
|
end
|
|
71
71
|
subtitles += parse_list_subtitles(options)
|
|
72
|
-
print_h1 title, subtitles
|
|
72
|
+
print_h1 title, subtitles, options
|
|
73
73
|
if users.empty?
|
|
74
74
|
puts yellow,"No users found.",reset
|
|
75
75
|
else
|
|
76
|
-
print_users_table(users)
|
|
76
|
+
print_users_table(users, options)
|
|
77
77
|
print_results_pagination(json_response)
|
|
78
78
|
end
|
|
79
79
|
print reset,"\n"
|
|
@@ -188,7 +188,7 @@ class Morpheus::Cli::Users
|
|
|
188
188
|
user_feature_permissions_json = @users_interface.feature_permissions(account_id, user['id'])
|
|
189
189
|
user_feature_permissions = user_feature_permissions_json['featurePermissions']
|
|
190
190
|
end
|
|
191
|
-
print_h1 "User Details"
|
|
191
|
+
print_h1 "User Details", options
|
|
192
192
|
print cyan
|
|
193
193
|
description_cols = {
|
|
194
194
|
"ID" => 'id',
|
|
@@ -205,17 +205,17 @@ class Morpheus::Cli::Users
|
|
|
205
205
|
}
|
|
206
206
|
print_description_list(description_cols, user)
|
|
207
207
|
|
|
208
|
-
print_h2 "User Instance Limits"
|
|
209
|
-
print cyan
|
|
210
|
-
print_description_list({
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}, user['instanceLimits'])
|
|
208
|
+
# print_h2 "User Instance Limits", options
|
|
209
|
+
# print cyan
|
|
210
|
+
# print_description_list({
|
|
211
|
+
# "Max Storage" => lambda {|it| (it && it['maxStorage'].to_i != 0) ? Filesize.from("#{it['maxStorage']} B").pretty : "no limit" },
|
|
212
|
+
# "Max Memory" => lambda {|it| (it && it['maxMemory'].to_i != 0) ? Filesize.from("#{it['maxMemory']} B").pretty : "no limit" },
|
|
213
|
+
# "CPU Count" => lambda {|it| (it && it['maxCpu'].to_i != 0) ? it['maxCpu'] : "no limit" }
|
|
214
|
+
# }, user['instanceLimits'])
|
|
215
215
|
|
|
216
216
|
if options[:include_feature_access] && user_feature_permissions
|
|
217
217
|
if user_feature_permissions
|
|
218
|
-
print_h2 "Feature Permissions"
|
|
218
|
+
print_h2 "Feature Permissions", options
|
|
219
219
|
print cyan
|
|
220
220
|
rows = user_feature_permissions.collect do |code, access|
|
|
221
221
|
{code: code, access: get_access_string(access) }
|
|
@@ -276,7 +276,10 @@ class Morpheus::Cli::Users
|
|
|
276
276
|
end
|
|
277
277
|
payload = {'user' => params}
|
|
278
278
|
end
|
|
279
|
-
|
|
279
|
+
if options[:dry_run] && options[:json]
|
|
280
|
+
puts as_json(payload, options)
|
|
281
|
+
return 0
|
|
282
|
+
end
|
|
280
283
|
if options[:dry_run]
|
|
281
284
|
print_dry_run @users_interface.dry.create(account_id, payload)
|
|
282
285
|
return
|
|
@@ -402,7 +405,7 @@ class Morpheus::Cli::Users
|
|
|
402
405
|
opts.on('--password VALUE', String, "New password") do |val|
|
|
403
406
|
new_password = val
|
|
404
407
|
end
|
|
405
|
-
build_common_options(opts, options, [:account, :options, :json, :dry_run, :remote])
|
|
408
|
+
build_common_options(opts, options, [:account, :options, :json, :dry_run, :remote, :quiet])
|
|
406
409
|
end
|
|
407
410
|
optparse.parse!(args)
|
|
408
411
|
|
|
@@ -422,6 +425,10 @@ class Morpheus::Cli::Users
|
|
|
422
425
|
user = find_user_by_username_or_id(account_id, args[0])
|
|
423
426
|
return 1 if user.nil?
|
|
424
427
|
|
|
428
|
+
if !options[:quiet]
|
|
429
|
+
print cyan, "Changing password for #{user['username']}", reset, "\n"
|
|
430
|
+
end
|
|
431
|
+
|
|
425
432
|
if new_password.nil?
|
|
426
433
|
|
|
427
434
|
password_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'password', 'fieldLabel' => 'New Password', 'type' => 'password', 'required' => true}], options[:options], @api_client)
|
|
@@ -442,22 +449,23 @@ class Morpheus::Cli::Users
|
|
|
442
449
|
|
|
443
450
|
payload = {
|
|
444
451
|
'user' => {
|
|
445
|
-
'password' => new_password
|
|
446
|
-
'passwordConfirmation' => new_password
|
|
452
|
+
'password' => new_password
|
|
447
453
|
}
|
|
448
454
|
}
|
|
449
|
-
|
|
455
|
+
|
|
450
456
|
if options[:dry_run]
|
|
451
457
|
print_dry_run @users_interface.dry.update(account_id, user['id'], payload)
|
|
452
458
|
return
|
|
453
459
|
end
|
|
454
460
|
|
|
461
|
+
json_response = @users_interface.update(account_id, user['id'], payload)
|
|
462
|
+
|
|
455
463
|
if options[:json]
|
|
456
464
|
puts JSON.pretty_generate(json_response)
|
|
457
|
-
|
|
465
|
+
elsif !options[:quiet]
|
|
458
466
|
print_green_success "Updated password for user #{user['username']}"
|
|
459
467
|
end
|
|
460
|
-
|
|
468
|
+
return 0
|
|
461
469
|
rescue RestClient::Exception => e
|
|
462
470
|
print_rest_exception(e, options)
|
|
463
471
|
return 1
|