morpheus-cli 2.10.0 → 2.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/morpheus +27 -32
- data/lib/morpheus/api/accounts_interface.rb +36 -47
- data/lib/morpheus/api/api_client.rb +141 -110
- data/lib/morpheus/api/app_templates_interface.rb +56 -72
- data/lib/morpheus/api/apps_interface.rb +111 -132
- data/lib/morpheus/api/auth_interface.rb +30 -0
- data/lib/morpheus/api/clouds_interface.rb +71 -76
- data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
- data/lib/morpheus/api/dashboard_interface.rb +10 -17
- data/lib/morpheus/api/deploy_interface.rb +60 -72
- data/lib/morpheus/api/deployments_interface.rb +53 -71
- data/lib/morpheus/api/groups_interface.rb +55 -45
- data/lib/morpheus/api/instance_types_interface.rb +19 -23
- data/lib/morpheus/api/instances_interface.rb +179 -177
- data/lib/morpheus/api/key_pairs_interface.rb +11 -17
- data/lib/morpheus/api/license_interface.rb +18 -23
- data/lib/morpheus/api/load_balancers_interface.rb +54 -69
- data/lib/morpheus/api/logs_interface.rb +25 -29
- data/lib/morpheus/api/options_interface.rb +13 -17
- data/lib/morpheus/api/provision_types_interface.rb +19 -22
- data/lib/morpheus/api/roles_interface.rb +75 -94
- data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
- data/lib/morpheus/api/security_groups_interface.rb +39 -51
- data/lib/morpheus/api/servers_interface.rb +113 -115
- data/lib/morpheus/api/setup_interface.rb +31 -0
- data/lib/morpheus/api/task_sets_interface.rb +36 -38
- data/lib/morpheus/api/tasks_interface.rb +56 -69
- data/lib/morpheus/api/users_interface.rb +67 -76
- data/lib/morpheus/api/virtual_images_interface.rb +61 -61
- data/lib/morpheus/api/whoami_interface.rb +12 -15
- data/lib/morpheus/cli.rb +71 -60
- data/lib/morpheus/cli/accounts.rb +254 -315
- data/lib/morpheus/cli/alias_command.rb +219 -0
- data/lib/morpheus/cli/app_templates.rb +264 -272
- data/lib/morpheus/cli/apps.rb +608 -671
- data/lib/morpheus/cli/cli_command.rb +259 -21
- data/lib/morpheus/cli/cli_registry.rb +99 -14
- data/lib/morpheus/cli/clouds.rb +599 -372
- data/lib/morpheus/cli/config_file.rb +126 -0
- data/lib/morpheus/cli/credentials.rb +141 -117
- data/lib/morpheus/cli/dashboard_command.rb +48 -56
- data/lib/morpheus/cli/deployments.rb +254 -268
- data/lib/morpheus/cli/deploys.rb +150 -142
- data/lib/morpheus/cli/error_handler.rb +38 -0
- data/lib/morpheus/cli/groups.rb +551 -179
- data/lib/morpheus/cli/hosts.rb +862 -617
- data/lib/morpheus/cli/instance_types.rb +103 -95
- data/lib/morpheus/cli/instances.rb +1335 -1009
- data/lib/morpheus/cli/key_pairs.rb +82 -90
- data/lib/morpheus/cli/library.rb +498 -499
- data/lib/morpheus/cli/license.rb +83 -101
- data/lib/morpheus/cli/load_balancers.rb +314 -300
- data/lib/morpheus/cli/login.rb +66 -44
- data/lib/morpheus/cli/logout.rb +47 -46
- data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
- data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
- data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
- data/lib/morpheus/cli/option_parser.rb +35 -0
- data/lib/morpheus/cli/option_types.rb +232 -192
- data/lib/morpheus/cli/recent_activity_command.rb +61 -65
- data/lib/morpheus/cli/remote.rb +446 -199
- data/lib/morpheus/cli/roles.rb +884 -906
- data/lib/morpheus/cli/security_group_rules.rb +213 -203
- data/lib/morpheus/cli/security_groups.rb +237 -192
- data/lib/morpheus/cli/shell.rb +338 -231
- data/lib/morpheus/cli/tasks.rb +326 -308
- data/lib/morpheus/cli/users.rb +457 -462
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/version_command.rb +16 -18
- data/lib/morpheus/cli/virtual_images.rb +526 -345
- data/lib/morpheus/cli/whoami.rb +125 -111
- data/lib/morpheus/cli/workflows.rb +338 -185
- data/lib/morpheus/formatters.rb +8 -1
- data/lib/morpheus/logging.rb +1 -1
- data/lib/morpheus/rest_client.rb +17 -8
- metadata +9 -3
- data/lib/morpheus/api/custom_instance_types.rb +0 -55
data/lib/morpheus/cli.rb
CHANGED
@@ -8,65 +8,76 @@ Dir[File.dirname(__FILE__) + "/ext/*.rb"].each {|file| require file }
|
|
8
8
|
|
9
9
|
module Morpheus
|
10
10
|
module Cli
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
11
|
+
|
12
|
+
# the home directory, where morpheus-cli stores things
|
13
|
+
def self.home_directory
|
14
|
+
if ENV['MORPHEUS_CLI_HOME']
|
15
|
+
ENV['MORPHEUS_CLI_HOME']
|
16
|
+
else
|
17
|
+
File.join(Dir.home, ".morpheus")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# the location of your config file
|
22
|
+
# this is not configurable right now.
|
23
|
+
def self.config_filename
|
24
|
+
File.join(self.home_directory, ".morpheusrc")
|
25
|
+
end
|
26
|
+
|
27
|
+
# load all the well known commands and utilties they need
|
28
|
+
def self.load!()
|
29
|
+
# load interfaces
|
30
|
+
require 'morpheus/api/api_client.rb'
|
31
|
+
Dir[File.dirname(__FILE__) + "/api/*.rb"].each {|file| load file }
|
32
|
+
|
33
|
+
# load mixins
|
34
|
+
Dir[File.dirname(__FILE__) + "/cli/mixins/*.rb"].each {|file| load file }
|
35
|
+
|
36
|
+
# load commands
|
37
|
+
# Dir[File.dirname(__FILE__) + "/cli/*.rb"].each {|file| load file }
|
38
|
+
|
39
|
+
# utilites
|
40
|
+
load 'morpheus/cli/credentials.rb'
|
41
|
+
load 'morpheus/cli/cli_command.rb'
|
42
|
+
load 'morpheus/cli/option_types.rb'
|
43
|
+
|
44
|
+
# all the known commands
|
45
|
+
load 'morpheus/cli/remote.rb'
|
46
|
+
load 'morpheus/cli/login.rb'
|
47
|
+
load 'morpheus/cli/logout.rb'
|
48
|
+
load 'morpheus/cli/whoami.rb'
|
49
|
+
load 'morpheus/cli/dashboard_command.rb'
|
50
|
+
load 'morpheus/cli/recent_activity_command.rb'
|
51
|
+
load 'morpheus/cli/groups.rb'
|
52
|
+
load 'morpheus/cli/clouds.rb'
|
53
|
+
load 'morpheus/cli/hosts.rb'
|
54
|
+
load 'morpheus/cli/load_balancers.rb'
|
55
|
+
load 'morpheus/cli/shell.rb'
|
56
|
+
load 'morpheus/cli/tasks.rb'
|
57
|
+
load 'morpheus/cli/workflows.rb'
|
58
|
+
load 'morpheus/cli/deployments.rb'
|
59
|
+
load 'morpheus/cli/instances.rb'
|
60
|
+
load 'morpheus/cli/apps.rb'
|
61
|
+
load 'morpheus/cli/app_templates.rb'
|
62
|
+
load 'morpheus/cli/deploys.rb'
|
63
|
+
load 'morpheus/cli/license.rb'
|
64
|
+
load 'morpheus/cli/instance_types.rb'
|
65
|
+
load 'morpheus/cli/security_groups.rb'
|
66
|
+
load 'morpheus/cli/security_group_rules.rb'
|
67
|
+
load 'morpheus/cli/accounts.rb'
|
68
|
+
load 'morpheus/cli/users.rb'
|
69
|
+
load 'morpheus/cli/roles.rb'
|
70
|
+
load 'morpheus/cli/key_pairs.rb'
|
71
|
+
load 'morpheus/cli/virtual_images.rb'
|
72
|
+
load 'morpheus/cli/library.rb'
|
73
|
+
load 'morpheus/cli/version_command.rb'
|
74
|
+
load 'morpheus/cli/alias_command.rb'
|
75
|
+
# Your new commands goes here...
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
load!
|
80
|
+
|
71
81
|
end
|
82
|
+
|
72
83
|
end
|
@@ -10,320 +10,259 @@ require 'json'
|
|
10
10
|
class Morpheus::Cli::Accounts
|
11
11
|
include Morpheus::Cli::CliCommand
|
12
12
|
include Morpheus::Cli::AccountsHelper
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
print_rest_exception(e, options)
|
268
|
-
exit 1
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
def remove(args)
|
273
|
-
usage = "Usage: morpheus accounts remove [name]"
|
274
|
-
options = {}
|
275
|
-
optparse = OptionParser.new do|opts|
|
276
|
-
opts.banner = usage
|
277
|
-
build_common_options(opts, options, [:auto_confirm, :json])
|
278
|
-
end
|
279
|
-
optparse.parse(args)
|
280
|
-
|
281
|
-
if args.count < 1
|
282
|
-
puts "\n#{usage}\n\n"
|
283
|
-
exit 1
|
284
|
-
end
|
285
|
-
name = args[0]
|
286
|
-
|
287
|
-
connect(options)
|
288
|
-
begin
|
289
|
-
# allow finding by ID since name is not unique!
|
290
|
-
account = ((name.to_s =~ /\A\d{1,}\Z/) ? find_account_by_id(name) : find_account_by_name(name) )
|
291
|
-
exit 1 if account.nil?
|
292
|
-
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the account #{account['name']}?")
|
293
|
-
exit
|
294
|
-
end
|
295
|
-
json_response = @accounts_interface.destroy(account['id'])
|
296
|
-
|
297
|
-
if options[:json]
|
298
|
-
print JSON.pretty_generate(json_response)
|
299
|
-
print "\n"
|
300
|
-
else
|
301
|
-
print_green_success "Account #{account['name']} removed"
|
302
|
-
end
|
303
|
-
|
304
|
-
rescue RestClient::Exception => e
|
305
|
-
print_rest_exception(e, options)
|
306
|
-
exit 1
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
private
|
311
|
-
|
312
|
-
|
313
|
-
def add_account_option_types
|
314
|
-
[
|
315
|
-
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
|
316
|
-
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
|
317
|
-
{'fieldName' => 'role', 'fieldLabel' => 'Base Role', 'type' => 'text', 'displayOrder' => 3},
|
318
|
-
{'fieldName' => 'currency', 'fieldLabel' => 'Currency', 'type' => 'text', 'displayOrder' => 4},
|
319
|
-
{'fieldName' => 'instanceLimits.maxStorage', 'fieldLabel' => 'Max Storage (bytes)', 'type' => 'text', 'displayOrder' => 5},
|
320
|
-
{'fieldName' => 'instanceLimits.maxMemory', 'fieldLabel' => 'Max Memory (bytes)', 'type' => 'text', 'displayOrder' => 6},
|
321
|
-
{'fieldName' => 'instanceLimits.maxCpu', 'fieldLabel' => 'CPU Count', 'type' => 'text', 'displayOrder' => 7},
|
322
|
-
]
|
323
|
-
end
|
324
|
-
|
325
|
-
def update_account_option_types
|
326
|
-
add_account_option_types
|
327
|
-
end
|
13
|
+
register_subcommands :list, :get, :add, :update, :remove
|
14
|
+
alias_subcommand :details, :get
|
15
|
+
set_default_subcommand :list
|
16
|
+
|
17
|
+
def initialize()
|
18
|
+
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
19
|
+
end
|
20
|
+
|
21
|
+
def connect(opts)
|
22
|
+
@api_client = establish_remote_appliance_connection(opts)
|
23
|
+
@users_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).users
|
24
|
+
@accounts_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).accounts
|
25
|
+
@roles_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).roles
|
26
|
+
end
|
27
|
+
|
28
|
+
def handle(args)
|
29
|
+
handle_subcommand(args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def list(args)
|
33
|
+
options = {}
|
34
|
+
optparse = OptionParser.new do|opts|
|
35
|
+
opts.banner = subcommand_usage()
|
36
|
+
build_common_options(opts, options, [:list, :json])
|
37
|
+
end
|
38
|
+
optparse.parse!(args)
|
39
|
+
connect(options)
|
40
|
+
begin
|
41
|
+
params = {}
|
42
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
43
|
+
params[k] = options[k] unless options[k].nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
json_response = @accounts_interface.list(params)
|
47
|
+
accounts = json_response['accounts']
|
48
|
+
if options[:json]
|
49
|
+
print JSON.pretty_generate(json_response)
|
50
|
+
print "\n"
|
51
|
+
else
|
52
|
+
print "\n" ,cyan, bold, "Morpheus Accounts\n","==================", reset, "\n\n"
|
53
|
+
if accounts.empty?
|
54
|
+
puts yellow,"No accounts found.",reset
|
55
|
+
else
|
56
|
+
print_accounts_table(accounts)
|
57
|
+
print_results_pagination(json_response)
|
58
|
+
end
|
59
|
+
print reset,"\n"
|
60
|
+
end
|
61
|
+
rescue RestClient::Exception => e
|
62
|
+
print_rest_exception(e, options)
|
63
|
+
exit 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def get(args)
|
68
|
+
options = {}
|
69
|
+
optparse = OptionParser.new do|opts|
|
70
|
+
opts.banner = subcommand_usage("[name]")
|
71
|
+
build_common_options(opts, options, [:json])
|
72
|
+
end
|
73
|
+
optparse.parse!(args)
|
74
|
+
if args.count < 1
|
75
|
+
puts optparse
|
76
|
+
exit 1
|
77
|
+
end
|
78
|
+
connect(options)
|
79
|
+
begin
|
80
|
+
|
81
|
+
account = find_account_by_name_or_id(args[0])
|
82
|
+
exit 1 if account.nil?
|
83
|
+
|
84
|
+
if options[:json]
|
85
|
+
print JSON.pretty_generate({account: account})
|
86
|
+
print "\n"
|
87
|
+
else
|
88
|
+
print "\n" ,cyan, bold, "Account Details\n","==================", reset, "\n\n"
|
89
|
+
print cyan
|
90
|
+
puts "ID: #{account['id']}"
|
91
|
+
puts "Name: #{account['name']}"
|
92
|
+
puts "Description: #{account['description']}"
|
93
|
+
puts "Currency: #{account['currency']}"
|
94
|
+
# puts "# Users: #{account['usersCount']}"
|
95
|
+
# puts "# Instances: #{account['instancesCount']}"
|
96
|
+
puts "Date Created: #{format_local_dt(account['dateCreated'])}"
|
97
|
+
puts "Last Updated: #{format_local_dt(account['lastUpdated'])}"
|
98
|
+
status_state = nil
|
99
|
+
if account['active']
|
100
|
+
status_state = "#{green}ACTIVE#{cyan}"
|
101
|
+
else
|
102
|
+
status_state = "#{red}INACTIVE#{cyan}"
|
103
|
+
end
|
104
|
+
puts "Status: #{status_state}"
|
105
|
+
print "\n" ,cyan, bold, "Account Instance Limits\n","==================", reset, "\n\n"
|
106
|
+
print cyan
|
107
|
+
puts "Max Storage (bytes): #{account['instanceLimits'] ? account['instanceLimits']['maxStorage'] : 0}"
|
108
|
+
puts "Max Memory (bytes): #{account['instanceLimits'] ? account['instanceLimits']['maxMemory'] : 0}"
|
109
|
+
puts "CPU Count: #{account['instanceLimits'] ? account['instanceLimits']['maxCpu'] : 0}"
|
110
|
+
print reset,"\n"
|
111
|
+
end
|
112
|
+
rescue RestClient::Exception => e
|
113
|
+
print_rest_exception(e, options)
|
114
|
+
exit 1
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def add(args)
|
119
|
+
options = {}
|
120
|
+
optparse = OptionParser.new do|opts|
|
121
|
+
opts.banner = subcommand_usage("[options]")
|
122
|
+
build_common_options(opts, options, [:options, :json])
|
123
|
+
end
|
124
|
+
optparse.parse!(args)
|
125
|
+
connect(options)
|
126
|
+
begin
|
127
|
+
params = Morpheus::Cli::OptionTypes.prompt(add_account_option_types, options[:options], @api_client, options[:params])
|
128
|
+
#puts "parsed params is : #{params.inspect}"
|
129
|
+
account_keys = ['name', 'description', 'currency']
|
130
|
+
account_payload = params.select {|k,v| account_keys.include?(k) }
|
131
|
+
account_payload['currency'] = account_payload['currency'].to_s.empty? ? "USD" : account_payload['currency'].upcase
|
132
|
+
if !account_payload['instanceLimits']
|
133
|
+
account_payload['instanceLimits'] = {}
|
134
|
+
account_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
135
|
+
account_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
136
|
+
account_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
137
|
+
end
|
138
|
+
if params['role'].to_s != ''
|
139
|
+
role = find_role_by_name(nil, params['role'])
|
140
|
+
exit 1 if role.nil?
|
141
|
+
account_payload['role'] = {id: role['id']}
|
142
|
+
end
|
143
|
+
request_payload = {account: account_payload}
|
144
|
+
json_response = @accounts_interface.create(request_payload)
|
145
|
+
if options[:json]
|
146
|
+
print JSON.pretty_generate(json_response)
|
147
|
+
print "\n"
|
148
|
+
else
|
149
|
+
print_green_success "Account #{account_payload['name']} added"
|
150
|
+
get([account_payload["name"]])
|
151
|
+
end
|
152
|
+
|
153
|
+
rescue RestClient::Exception => e
|
154
|
+
print_rest_exception(e, options)
|
155
|
+
exit 1
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def update(args)
|
160
|
+
options = {}
|
161
|
+
optparse = OptionParser.new do|opts|
|
162
|
+
opts.banner = subcommand_usage("[name] [options]")
|
163
|
+
build_common_options(opts, options, [:options, :json])
|
164
|
+
end
|
165
|
+
optparse.parse!(args)
|
166
|
+
if args.count < 1
|
167
|
+
puts optparse
|
168
|
+
exit 1
|
169
|
+
end
|
170
|
+
connect(options)
|
171
|
+
begin
|
172
|
+
account = find_account_by_name_or_id(args[0])
|
173
|
+
exit 1 if account.nil?
|
174
|
+
|
175
|
+
#params = Morpheus::Cli::OptionTypes.prompt(update_account_option_types, options[:options], @api_client, options[:params])
|
176
|
+
params = options[:options] || {}
|
177
|
+
|
178
|
+
if params.empty?
|
179
|
+
puts optparse
|
180
|
+
option_lines = update_account_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n")
|
181
|
+
puts "\nAvailable Options:\n#{option_lines}\n\n"
|
182
|
+
exit 1
|
183
|
+
end
|
184
|
+
|
185
|
+
#puts "parsed params is : #{params.inspect}"
|
186
|
+
account_keys = ['name', 'description', 'currency', 'instanceLimits']
|
187
|
+
account_payload = params.select {|k,v| account_keys.include?(k) }
|
188
|
+
account_payload['currency'] = account_payload['currency'].upcase unless account_payload['currency'].to_s.empty?
|
189
|
+
if !account_payload['instanceLimits']
|
190
|
+
account_payload['instanceLimits'] = {}
|
191
|
+
account_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
|
192
|
+
account_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
|
193
|
+
account_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
|
194
|
+
end
|
195
|
+
if params['role'].to_s != ''
|
196
|
+
role = find_role_by_name(nil, params['role'])
|
197
|
+
exit 1 if role.nil?
|
198
|
+
account_payload['role'] = {id: role['id']}
|
199
|
+
end
|
200
|
+
request_payload = {account: account_payload}
|
201
|
+
json_response = @accounts_interface.update(account['id'], request_payload)
|
202
|
+
|
203
|
+
if options[:json]
|
204
|
+
print JSON.pretty_generate(json_response)
|
205
|
+
print "\n"
|
206
|
+
else
|
207
|
+
account_name = account_payload['name'] || account['name']
|
208
|
+
print_green_success "Account #{account_name} updated"
|
209
|
+
get([account_name])
|
210
|
+
end
|
211
|
+
rescue RestClient::Exception => e
|
212
|
+
print_rest_exception(e, options)
|
213
|
+
exit 1
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def remove(args)
|
218
|
+
options = {}
|
219
|
+
optparse = OptionParser.new do|opts|
|
220
|
+
opts.banner = subcommand_usage("[name]")
|
221
|
+
build_common_options(opts, options, [:auto_confirm, :json])
|
222
|
+
end
|
223
|
+
optparse.parse!(args)
|
224
|
+
if args.count < 1
|
225
|
+
puts optparse
|
226
|
+
exit 1
|
227
|
+
end
|
228
|
+
connect(options)
|
229
|
+
begin
|
230
|
+
# allow finding by ID since name is not unique!
|
231
|
+
account = find_account_by_name_or_id(args[0])
|
232
|
+
exit 1 if account.nil?
|
233
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the account #{account['name']}?")
|
234
|
+
exit
|
235
|
+
end
|
236
|
+
json_response = @accounts_interface.destroy(account['id'])
|
237
|
+
if options[:json]
|
238
|
+
print JSON.pretty_generate(json_response)
|
239
|
+
print "\n"
|
240
|
+
else
|
241
|
+
print_green_success "Account #{account['name']} removed"
|
242
|
+
end
|
243
|
+
|
244
|
+
rescue RestClient::Exception => e
|
245
|
+
print_rest_exception(e, options)
|
246
|
+
exit 1
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
private
|
251
|
+
|
252
|
+
def add_account_option_types
|
253
|
+
[
|
254
|
+
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
|
255
|
+
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
|
256
|
+
{'fieldName' => 'role', 'fieldLabel' => 'Base Role', 'type' => 'text', 'displayOrder' => 3},
|
257
|
+
{'fieldName' => 'currency', 'fieldLabel' => 'Currency', 'type' => 'text', 'displayOrder' => 4},
|
258
|
+
{'fieldName' => 'instanceLimits.maxStorage', 'fieldLabel' => 'Max Storage (bytes)', 'type' => 'text', 'displayOrder' => 5},
|
259
|
+
{'fieldName' => 'instanceLimits.maxMemory', 'fieldLabel' => 'Max Memory (bytes)', 'type' => 'text', 'displayOrder' => 6},
|
260
|
+
{'fieldName' => 'instanceLimits.maxCpu', 'fieldLabel' => 'CPU Count', 'type' => 'text', 'displayOrder' => 7},
|
261
|
+
]
|
262
|
+
end
|
263
|
+
|
264
|
+
def update_account_option_types
|
265
|
+
add_account_option_types
|
266
|
+
end
|
328
267
|
|
329
268
|
end
|