morpheus-cli 4.1.8 → 4.1.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/Dockerfile +1 -1
- data/lib/morpheus/api/api_client.rb +24 -0
- data/lib/morpheus/api/{old_cypher_interface.rb → budgets_interface.rb} +10 -11
- data/lib/morpheus/api/cloud_datastores_interface.rb +7 -0
- data/lib/morpheus/api/cloud_resource_pools_interface.rb +2 -2
- data/lib/morpheus/api/cypher_interface.rb +18 -12
- data/lib/morpheus/api/health_interface.rb +72 -0
- data/lib/morpheus/api/instances_interface.rb +1 -1
- data/lib/morpheus/api/library_instance_types_interface.rb +7 -0
- data/lib/morpheus/api/log_settings_interface.rb +6 -0
- data/lib/morpheus/api/network_security_servers_interface.rb +30 -0
- data/lib/morpheus/api/price_sets_interface.rb +42 -0
- data/lib/morpheus/api/prices_interface.rb +68 -0
- data/lib/morpheus/api/provisioning_settings_interface.rb +29 -0
- data/lib/morpheus/api/servers_interface.rb +1 -1
- data/lib/morpheus/api/service_plans_interface.rb +34 -11
- data/lib/morpheus/api/task_sets_interface.rb +8 -0
- data/lib/morpheus/api/tasks_interface.rb +8 -0
- data/lib/morpheus/cli.rb +6 -3
- data/lib/morpheus/cli/appliance_settings_command.rb +13 -5
- data/lib/morpheus/cli/approvals_command.rb +1 -1
- data/lib/morpheus/cli/apps.rb +88 -28
- data/lib/morpheus/cli/backup_settings_command.rb +1 -1
- data/lib/morpheus/cli/blueprints_command.rb +2 -0
- data/lib/morpheus/cli/budgets_command.rb +672 -0
- data/lib/morpheus/cli/cli_command.rb +13 -2
- data/lib/morpheus/cli/cli_registry.rb +1 -0
- data/lib/morpheus/cli/clusters.rb +40 -274
- data/lib/morpheus/cli/commands/standard/benchmark_command.rb +114 -66
- data/lib/morpheus/cli/commands/standard/coloring_command.rb +12 -0
- data/lib/morpheus/cli/commands/standard/curl_command.rb +31 -6
- data/lib/morpheus/cli/commands/standard/echo_command.rb +8 -3
- data/lib/morpheus/cli/commands/standard/set_prompt_command.rb +1 -1
- data/lib/morpheus/cli/containers_command.rb +37 -24
- data/lib/morpheus/cli/cypher_command.rb +191 -150
- data/lib/morpheus/cli/health_command.rb +903 -0
- data/lib/morpheus/cli/hosts.rb +43 -32
- data/lib/morpheus/cli/instances.rb +119 -68
- data/lib/morpheus/cli/jobs_command.rb +1 -1
- data/lib/morpheus/cli/library_instance_types_command.rb +61 -11
- data/lib/morpheus/cli/library_option_types_command.rb +2 -2
- data/lib/morpheus/cli/log_settings_command.rb +46 -3
- data/lib/morpheus/cli/logs_command.rb +24 -17
- data/lib/morpheus/cli/mixins/accounts_helper.rb +2 -0
- data/lib/morpheus/cli/mixins/logs_helper.rb +73 -19
- data/lib/morpheus/cli/mixins/print_helper.rb +29 -1
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +554 -96
- data/lib/morpheus/cli/mixins/whoami_helper.rb +13 -1
- data/lib/morpheus/cli/networks_command.rb +3 -0
- data/lib/morpheus/cli/option_types.rb +83 -53
- data/lib/morpheus/cli/price_sets_command.rb +543 -0
- data/lib/morpheus/cli/prices_command.rb +669 -0
- data/lib/morpheus/cli/processes_command.rb +0 -2
- data/lib/morpheus/cli/provisioning_settings_command.rb +237 -0
- data/lib/morpheus/cli/remote.rb +9 -4
- data/lib/morpheus/cli/reports_command.rb +10 -4
- data/lib/morpheus/cli/roles.rb +93 -38
- data/lib/morpheus/cli/security_groups.rb +10 -0
- data/lib/morpheus/cli/service_plans_command.rb +736 -0
- data/lib/morpheus/cli/tasks.rb +220 -8
- data/lib/morpheus/cli/tenants_command.rb +3 -16
- data/lib/morpheus/cli/users.rb +2 -25
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/whitelabel_settings_command.rb +18 -18
- data/lib/morpheus/cli/whoami.rb +28 -10
- data/lib/morpheus/cli/workflows.rb +488 -36
- data/lib/morpheus/formatters.rb +22 -0
- data/morpheus-cli.gemspec +1 -0
- metadata +28 -5
- data/lib/morpheus/cli/accounts.rb +0 -335
- data/lib/morpheus/cli/old_cypher_command.rb +0 -412
data/lib/morpheus/formatters.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'time'
|
2
2
|
require 'filesize'
|
3
|
+
require 'money'
|
3
4
|
|
4
5
|
DEFAULT_TIME_FORMAT = "%x %I:%M %p"
|
5
6
|
|
@@ -326,3 +327,24 @@ def format_number(n, opts={})
|
|
326
327
|
end
|
327
328
|
return out
|
328
329
|
end
|
330
|
+
|
331
|
+
def currency_sym(currency)
|
332
|
+
Money::Currency.new((currency || 'usd').to_sym).symbol
|
333
|
+
end
|
334
|
+
|
335
|
+
# returns currency amount formatted like "$4,5123.00". 0.00 is formatted as "$0"
|
336
|
+
# this is not ideal
|
337
|
+
def format_money(amount, currency='usd')
|
338
|
+
if amount.to_f == 0
|
339
|
+
return currency_sym(currency).to_s + "0"
|
340
|
+
else
|
341
|
+
rtn = amount.to_f.round(2).to_s
|
342
|
+
if rtn.index('.').nil?
|
343
|
+
rtn += '.00'
|
344
|
+
elsif rtn.split('.')[1].length < 2
|
345
|
+
rtn = rtn + (['0'] * (2 - rtn.split('.')[1].length) * '')
|
346
|
+
end
|
347
|
+
dollars,cents = rtn.split(".")
|
348
|
+
currency_sym(currency).to_s + format_number(dollars.to_i) + "." + cents
|
349
|
+
end
|
350
|
+
end
|
data/morpheus-cli.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morpheus-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Estes
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2020-01-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -139,6 +139,20 @@ dependencies:
|
|
139
139
|
- - ">="
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: money
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
type: :runtime
|
150
|
+
prerelease: false
|
151
|
+
version_requirements: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
142
156
|
description: Infrastructure agnostic cloud application management & orchestration
|
143
157
|
CLI for Morpheus. Easily manage and orchestrate VMS on private or public infrastructure
|
144
158
|
and containerized architectures.
|
@@ -169,6 +183,7 @@ files:
|
|
169
183
|
- lib/morpheus/api/auth_interface.rb
|
170
184
|
- lib/morpheus/api/backup_settings_interface.rb
|
171
185
|
- lib/morpheus/api/blueprints_interface.rb
|
186
|
+
- lib/morpheus/api/budgets_interface.rb
|
172
187
|
- lib/morpheus/api/cloud_datastores_interface.rb
|
173
188
|
- lib/morpheus/api/cloud_folders_interface.rb
|
174
189
|
- lib/morpheus/api/cloud_policies_interface.rb
|
@@ -187,6 +202,7 @@ files:
|
|
187
202
|
- lib/morpheus/api/file_copy_request_interface.rb
|
188
203
|
- lib/morpheus/api/group_policies_interface.rb
|
189
204
|
- lib/morpheus/api/groups_interface.rb
|
205
|
+
- lib/morpheus/api/health_interface.rb
|
190
206
|
- lib/morpheus/api/image_builder_boot_scripts_interface.rb
|
191
207
|
- lib/morpheus/api/image_builder_image_builds_interface.rb
|
192
208
|
- lib/morpheus/api/image_builder_interface.rb
|
@@ -221,19 +237,22 @@ files:
|
|
221
237
|
- lib/morpheus/api/network_pool_servers_interface.rb
|
222
238
|
- lib/morpheus/api/network_pools_interface.rb
|
223
239
|
- lib/morpheus/api/network_proxies_interface.rb
|
240
|
+
- lib/morpheus/api/network_security_servers_interface.rb
|
224
241
|
- lib/morpheus/api/network_services_interface.rb
|
225
242
|
- lib/morpheus/api/network_subnets_interface.rb
|
226
243
|
- lib/morpheus/api/network_types_interface.rb
|
227
244
|
- lib/morpheus/api/networks_interface.rb
|
228
|
-
- lib/morpheus/api/old_cypher_interface.rb
|
229
245
|
- lib/morpheus/api/option_type_lists_interface.rb
|
230
246
|
- lib/morpheus/api/option_types_interface.rb
|
231
247
|
- lib/morpheus/api/options_interface.rb
|
232
248
|
- lib/morpheus/api/packages_interface.rb
|
233
249
|
- lib/morpheus/api/policies_interface.rb
|
234
250
|
- lib/morpheus/api/power_schedules_interface.rb
|
251
|
+
- lib/morpheus/api/price_sets_interface.rb
|
252
|
+
- lib/morpheus/api/prices_interface.rb
|
235
253
|
- lib/morpheus/api/processes_interface.rb
|
236
254
|
- lib/morpheus/api/provision_types_interface.rb
|
255
|
+
- lib/morpheus/api/provisioning_settings_interface.rb
|
237
256
|
- lib/morpheus/api/reports_interface.rb
|
238
257
|
- lib/morpheus/api/roles_interface.rb
|
239
258
|
- lib/morpheus/api/security_group_rules_interface.rb
|
@@ -259,7 +278,6 @@ files:
|
|
259
278
|
- lib/morpheus/cli.rb
|
260
279
|
- lib/morpheus/cli/access_token_command.rb
|
261
280
|
- lib/morpheus/cli/account_groups_command.rb
|
262
|
-
- lib/morpheus/cli/accounts.rb
|
263
281
|
- lib/morpheus/cli/appliance_settings_command.rb
|
264
282
|
- lib/morpheus/cli/approvals_command.rb
|
265
283
|
- lib/morpheus/cli/apps.rb
|
@@ -268,6 +286,7 @@ files:
|
|
268
286
|
- lib/morpheus/cli/backup_settings_command.rb
|
269
287
|
- lib/morpheus/cli/blueprints_command.rb
|
270
288
|
- lib/morpheus/cli/boot_scripts_command.rb
|
289
|
+
- lib/morpheus/cli/budgets_command.rb
|
271
290
|
- lib/morpheus/cli/change_password_command.rb
|
272
291
|
- lib/morpheus/cli/cli_command.rb
|
273
292
|
- lib/morpheus/cli/cli_registry.rb
|
@@ -312,6 +331,7 @@ files:
|
|
312
331
|
- lib/morpheus/cli/expression_parser.rb
|
313
332
|
- lib/morpheus/cli/file_copy_request_command.rb
|
314
333
|
- lib/morpheus/cli/groups.rb
|
334
|
+
- lib/morpheus/cli/health_command.rb
|
315
335
|
- lib/morpheus/cli/hosts.rb
|
316
336
|
- lib/morpheus/cli/image_builder_command.rb
|
317
337
|
- lib/morpheus/cli/instance_types.rb
|
@@ -356,20 +376,23 @@ files:
|
|
356
376
|
- lib/morpheus/cli/network_proxies_command.rb
|
357
377
|
- lib/morpheus/cli/network_services_command.rb
|
358
378
|
- lib/morpheus/cli/networks_command.rb
|
359
|
-
- lib/morpheus/cli/old_cypher_command.rb
|
360
379
|
- lib/morpheus/cli/option_parser.rb
|
361
380
|
- lib/morpheus/cli/option_types.rb
|
362
381
|
- lib/morpheus/cli/packages_command.rb
|
363
382
|
- lib/morpheus/cli/policies_command.rb
|
364
383
|
- lib/morpheus/cli/power_schedules_command.rb
|
365
384
|
- lib/morpheus/cli/preseed_scripts_command.rb
|
385
|
+
- lib/morpheus/cli/price_sets_command.rb
|
386
|
+
- lib/morpheus/cli/prices_command.rb
|
366
387
|
- lib/morpheus/cli/processes_command.rb
|
388
|
+
- lib/morpheus/cli/provisioning_settings_command.rb
|
367
389
|
- lib/morpheus/cli/recent_activity_command.rb
|
368
390
|
- lib/morpheus/cli/remote.rb
|
369
391
|
- lib/morpheus/cli/reports_command.rb
|
370
392
|
- lib/morpheus/cli/roles.rb
|
371
393
|
- lib/morpheus/cli/security_group_rules.rb
|
372
394
|
- lib/morpheus/cli/security_groups.rb
|
395
|
+
- lib/morpheus/cli/service_plans_command.rb
|
373
396
|
- lib/morpheus/cli/shell.rb
|
374
397
|
- lib/morpheus/cli/storage_providers_command.rb
|
375
398
|
- lib/morpheus/cli/subnets_command.rb
|
@@ -1,335 +0,0 @@
|
|
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::Accounts
|
11
|
-
include Morpheus::Cli::CliCommand
|
12
|
-
include Morpheus::Cli::AccountsHelper
|
13
|
-
|
14
|
-
# deprecated and replaced with tenants, remove soon
|
15
|
-
set_command_hidden
|
16
|
-
|
17
|
-
register_subcommands :list, :count, :get, :add, :update, :remove
|
18
|
-
alias_subcommand :details, :get
|
19
|
-
set_default_subcommand :list
|
20
|
-
|
21
|
-
# account-groups is under this namespace for now
|
22
|
-
register_subcommands :'groups' => :account_groups
|
23
|
-
|
24
|
-
def initialize()
|
25
|
-
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
26
|
-
end
|
27
|
-
|
28
|
-
def connect(opts)
|
29
|
-
@api_client = establish_remote_appliance_connection(opts)
|
30
|
-
@users_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).users
|
31
|
-
@accounts_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).accounts
|
32
|
-
@roles_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).roles
|
33
|
-
end
|
34
|
-
|
35
|
-
def handle(args)
|
36
|
-
print_error "#{yellow}DEPRECATION WARNING: `morpheus accounts` has been replaced with `morpheus tenants`. Please use `tenants` instead.#{reset}\n"
|
37
|
-
handle_subcommand(args)
|
38
|
-
end
|
39
|
-
|
40
|
-
def account_groups(args)
|
41
|
-
Morpheus::Cli::AccountGroupsCommand.new.handle(args)
|
42
|
-
end
|
43
|
-
|
44
|
-
def list(args)
|
45
|
-
options = {}
|
46
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
47
|
-
opts.banner = subcommand_usage()
|
48
|
-
build_common_options(opts, options, [:list, :query, :json, :remote, :dry_run])
|
49
|
-
opts.footer = "List accounts."
|
50
|
-
end
|
51
|
-
optparse.parse!(args)
|
52
|
-
connect(options)
|
53
|
-
begin
|
54
|
-
params = {}
|
55
|
-
params.merge!(parse_list_options(options))
|
56
|
-
if options[:dry_run]
|
57
|
-
print_dry_run @accounts_interface.dry.list(params)
|
58
|
-
return
|
59
|
-
end
|
60
|
-
json_response = @accounts_interface.list(params)
|
61
|
-
accounts = json_response['accounts']
|
62
|
-
if options[:json]
|
63
|
-
print JSON.pretty_generate(json_response)
|
64
|
-
print "\n"
|
65
|
-
else
|
66
|
-
title = "Morpheus Accounts"
|
67
|
-
subtitles = []
|
68
|
-
subtitles += parse_list_subtitles(options)
|
69
|
-
print_h1 title, subtitles
|
70
|
-
if accounts.empty?
|
71
|
-
puts yellow,"No accounts found.",reset
|
72
|
-
else
|
73
|
-
print_accounts_table(accounts)
|
74
|
-
print_results_pagination(json_response)
|
75
|
-
end
|
76
|
-
print reset,"\n"
|
77
|
-
end
|
78
|
-
rescue RestClient::Exception => e
|
79
|
-
print_rest_exception(e, options)
|
80
|
-
exit 1
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def count(args)
|
85
|
-
options = {}
|
86
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
87
|
-
opts.banner = subcommand_usage("[options]")
|
88
|
-
build_common_options(opts, options, [:query, :remote, :dry_run])
|
89
|
-
opts.footer = "Get the number of accounts."
|
90
|
-
end
|
91
|
-
optparse.parse!(args)
|
92
|
-
connect(options)
|
93
|
-
begin
|
94
|
-
params = {}
|
95
|
-
params.merge!(parse_list_options(options))
|
96
|
-
if options[:dry_run]
|
97
|
-
print_dry_run @accounts_interface.dry.list(params)
|
98
|
-
return
|
99
|
-
end
|
100
|
-
json_response = @accounts_interface.list(params)
|
101
|
-
# print number only
|
102
|
-
if json_response['meta'] && json_response['meta']['total']
|
103
|
-
print cyan, json_response['meta']['total'], reset, "\n"
|
104
|
-
else
|
105
|
-
print yellow, "unknown", reset, "\n"
|
106
|
-
end
|
107
|
-
rescue RestClient::Exception => e
|
108
|
-
print_rest_exception(e, options)
|
109
|
-
exit 1
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def get(args)
|
114
|
-
options = {}
|
115
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
116
|
-
opts.banner = subcommand_usage("[name]")
|
117
|
-
build_common_options(opts, options, [:json, :remote, :dry_run])
|
118
|
-
end
|
119
|
-
optparse.parse!(args)
|
120
|
-
if args.count < 1
|
121
|
-
puts optparse
|
122
|
-
exit 1
|
123
|
-
end
|
124
|
-
connect(options)
|
125
|
-
begin
|
126
|
-
if options[:dry_run]
|
127
|
-
if args[0].to_s =~ /\A\d{1,}\Z/
|
128
|
-
print_dry_run @accounts_interface.dry.get(args[0].to_i)
|
129
|
-
else
|
130
|
-
print_dry_run @accounts_interface.dry.list({name:args[0]})
|
131
|
-
end
|
132
|
-
return
|
133
|
-
end
|
134
|
-
account = find_account_by_name_or_id(args[0])
|
135
|
-
exit 1 if account.nil?
|
136
|
-
|
137
|
-
if options[:json]
|
138
|
-
print JSON.pretty_generate({account: account})
|
139
|
-
print "\n"
|
140
|
-
else
|
141
|
-
print_h1 "Account Details"
|
142
|
-
print cyan
|
143
|
-
puts "ID: #{account['id']}"
|
144
|
-
puts "Name: #{account['name']}"
|
145
|
-
puts "Description: #{account['description']}"
|
146
|
-
puts "Subdomain: #{account['subdomain']}" if !account['subdomain'].to_s.empty?
|
147
|
-
puts "Currency: #{account['currency']}"
|
148
|
-
# puts "# Users: #{account['usersCount']}"
|
149
|
-
# puts "# Instances: #{account['instancesCount']}"
|
150
|
-
puts "Date Created: #{format_local_dt(account['dateCreated'])}"
|
151
|
-
puts "Last Updated: #{format_local_dt(account['lastUpdated'])}"
|
152
|
-
status_state = nil
|
153
|
-
if account['active']
|
154
|
-
status_state = "#{green}ACTIVE#{cyan}"
|
155
|
-
else
|
156
|
-
status_state = "#{red}INACTIVE#{cyan}"
|
157
|
-
end
|
158
|
-
puts "Status: #{status_state}"
|
159
|
-
print_h2 "Account Instance Limits"
|
160
|
-
print cyan
|
161
|
-
puts "Max Storage (bytes): #{account['instanceLimits'] ? account['instanceLimits']['maxStorage'] : 0}"
|
162
|
-
puts "Max Memory (bytes): #{account['instanceLimits'] ? account['instanceLimits']['maxMemory'] : 0}"
|
163
|
-
puts "CPU Count: #{account['instanceLimits'] ? account['instanceLimits']['maxCpu'] : 0}"
|
164
|
-
print reset,"\n"
|
165
|
-
end
|
166
|
-
rescue RestClient::Exception => e
|
167
|
-
print_rest_exception(e, options)
|
168
|
-
exit 1
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def add(args)
|
173
|
-
options = {}
|
174
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
175
|
-
opts.banner = subcommand_usage("[options]")
|
176
|
-
build_option_type_options(opts, options, add_account_option_types)
|
177
|
-
build_common_options(opts, options, [:options, :json, :remote, :dry_run])
|
178
|
-
end
|
179
|
-
optparse.parse!(args)
|
180
|
-
connect(options)
|
181
|
-
begin
|
182
|
-
params = Morpheus::Cli::OptionTypes.prompt(add_account_option_types, options[:options], @api_client, options[:params])
|
183
|
-
#puts "parsed params is : #{params.inspect}"
|
184
|
-
account_keys = ['name', 'description', 'currency']
|
185
|
-
account_payload = params.select {|k,v| account_keys.include?(k) }
|
186
|
-
account_payload['currency'] = account_payload['currency'].to_s.empty? ? "USD" : account_payload['currency'].upcase
|
187
|
-
if !account_payload['instanceLimits']
|
188
|
-
account_payload['instanceLimits'] = {}
|
189
|
-
account_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
190
|
-
account_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
191
|
-
account_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
192
|
-
end
|
193
|
-
if params['role'].to_s != ''
|
194
|
-
role = find_role_by_name(nil, params['role'])
|
195
|
-
exit 1 if role.nil?
|
196
|
-
account_payload['role'] = {id: role['id']}
|
197
|
-
end
|
198
|
-
request_payload = {account: account_payload}
|
199
|
-
if options[:dry_run]
|
200
|
-
print_dry_run @accounts_interface.dry.create(request_payload)
|
201
|
-
return
|
202
|
-
end
|
203
|
-
json_response = @accounts_interface.create(request_payload)
|
204
|
-
if options[:json]
|
205
|
-
print JSON.pretty_generate(json_response)
|
206
|
-
print "\n"
|
207
|
-
else
|
208
|
-
print_green_success "Account #{account_payload['name']} added"
|
209
|
-
get([account_payload["name"]])
|
210
|
-
end
|
211
|
-
|
212
|
-
rescue RestClient::Exception => e
|
213
|
-
print_rest_exception(e, options)
|
214
|
-
exit 1
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
def update(args)
|
219
|
-
options = {}
|
220
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
221
|
-
opts.banner = subcommand_usage("[name] [options]")
|
222
|
-
build_option_type_options(opts, options, update_account_option_types)
|
223
|
-
build_common_options(opts, options, [:options, :json, :remote, :dry_run])
|
224
|
-
end
|
225
|
-
optparse.parse!(args)
|
226
|
-
if args.count < 1
|
227
|
-
print_red_alert "Specify at least one option to update"
|
228
|
-
puts optparse
|
229
|
-
exit 1
|
230
|
-
end
|
231
|
-
connect(options)
|
232
|
-
begin
|
233
|
-
account = find_account_by_name_or_id(args[0])
|
234
|
-
exit 1 if account.nil?
|
235
|
-
|
236
|
-
#params = Morpheus::Cli::OptionTypes.prompt(update_account_option_types, options[:options], @api_client, options[:params])
|
237
|
-
params = options[:options] || {}
|
238
|
-
|
239
|
-
if params.empty?
|
240
|
-
puts optparse
|
241
|
-
exit 1
|
242
|
-
end
|
243
|
-
|
244
|
-
#puts "parsed params is : #{params.inspect}"
|
245
|
-
account_keys = ['name', 'description', 'currency', 'instanceLimits']
|
246
|
-
account_payload = params.select {|k,v| account_keys.include?(k) }
|
247
|
-
account_payload['currency'] = account_payload['currency'].upcase unless account_payload['currency'].to_s.empty?
|
248
|
-
if !account_payload['instanceLimits']
|
249
|
-
account_payload['instanceLimits'] = {}
|
250
|
-
account_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
251
|
-
account_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
252
|
-
account_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
253
|
-
end
|
254
|
-
if params['role'].to_s != ''
|
255
|
-
role = find_role_by_name(nil, params['role'])
|
256
|
-
exit 1 if role.nil?
|
257
|
-
account_payload['role'] = {id: role['id']}
|
258
|
-
end
|
259
|
-
request_payload = {account: account_payload}
|
260
|
-
if options[:dry_run]
|
261
|
-
print_dry_run @accounts_interface.dry.update(account['id'], request_payload)
|
262
|
-
return
|
263
|
-
end
|
264
|
-
json_response = @accounts_interface.update(account['id'], request_payload)
|
265
|
-
|
266
|
-
if options[:json]
|
267
|
-
print JSON.pretty_generate(json_response)
|
268
|
-
print "\n"
|
269
|
-
else
|
270
|
-
account_name = account_payload['name'] || account['name']
|
271
|
-
print_green_success "Account #{account_name} updated"
|
272
|
-
get([account_name])
|
273
|
-
end
|
274
|
-
rescue RestClient::Exception => e
|
275
|
-
print_rest_exception(e, options)
|
276
|
-
exit 1
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
def remove(args)
|
281
|
-
options = {}
|
282
|
-
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
283
|
-
opts.banner = subcommand_usage("[name]")
|
284
|
-
build_common_options(opts, options, [:auto_confirm, :json, :remote, :dry_run])
|
285
|
-
end
|
286
|
-
optparse.parse!(args)
|
287
|
-
if args.count < 1
|
288
|
-
puts optparse
|
289
|
-
exit 1
|
290
|
-
end
|
291
|
-
connect(options)
|
292
|
-
begin
|
293
|
-
# allow finding by ID since name is not unique!
|
294
|
-
account = find_account_by_name_or_id(args[0])
|
295
|
-
exit 1 if account.nil?
|
296
|
-
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the account #{account['name']}?")
|
297
|
-
exit
|
298
|
-
end
|
299
|
-
if options[:dry_run]
|
300
|
-
print_dry_run @accounts_interface.dry.destroy(account['id'])
|
301
|
-
return
|
302
|
-
end
|
303
|
-
json_response = @accounts_interface.destroy(account['id'])
|
304
|
-
if options[:json]
|
305
|
-
print JSON.pretty_generate(json_response)
|
306
|
-
print "\n"
|
307
|
-
else
|
308
|
-
print_green_success "Account #{account['name']} removed"
|
309
|
-
end
|
310
|
-
|
311
|
-
rescue RestClient::Exception => e
|
312
|
-
print_rest_exception(e, options)
|
313
|
-
exit 1
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
private
|
318
|
-
|
319
|
-
def add_account_option_types
|
320
|
-
[
|
321
|
-
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
|
322
|
-
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
|
323
|
-
{'fieldName' => 'role', 'fieldLabel' => 'Base Role', 'type' => 'text', 'displayOrder' => 3},
|
324
|
-
{'fieldName' => 'currency', 'fieldLabel' => 'Currency', 'type' => 'text', 'displayOrder' => 4},
|
325
|
-
{'fieldName' => 'instanceLimits.maxStorage', 'fieldLabel' => 'Max Storage (bytes)', 'type' => 'text', 'displayOrder' => 5},
|
326
|
-
{'fieldName' => 'instanceLimits.maxMemory', 'fieldLabel' => 'Max Memory (bytes)', 'type' => 'text', 'displayOrder' => 6},
|
327
|
-
{'fieldName' => 'instanceLimits.maxCpu', 'fieldLabel' => 'CPU Count', 'type' => 'text', 'displayOrder' => 7},
|
328
|
-
]
|
329
|
-
end
|
330
|
-
|
331
|
-
def update_account_option_types
|
332
|
-
add_account_option_types
|
333
|
-
end
|
334
|
-
|
335
|
-
end
|