morpheus-cli 5.5.3.2 → 6.0.1
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 +8 -0
- data/lib/morpheus/api/cloud_resource_pools_interface.rb +28 -3
- data/lib/morpheus/api/containers_interface.rb +10 -0
- data/lib/morpheus/api/doc_interface.rb +1 -10
- data/lib/morpheus/api/jobs_interface.rb +2 -2
- data/lib/morpheus/api/key_pairs_interface.rb +9 -0
- data/lib/morpheus/api/network_floating_ips_interface.rb +37 -0
- data/lib/morpheus/api/resource_pool_groups_interface.rb +51 -0
- data/lib/morpheus/cli/cli_command.rb +17 -11
- data/lib/morpheus/cli/commands/appliance_settings_command.rb +5 -0
- data/lib/morpheus/cli/commands/apps.rb +12 -6
- data/lib/morpheus/cli/commands/catalog_item_types_command.rb +44 -12
- data/lib/morpheus/cli/commands/clusters.rb +23 -2
- data/lib/morpheus/cli/commands/containers_command.rb +129 -4
- data/lib/morpheus/cli/commands/doc.rb +14 -13
- data/lib/morpheus/cli/commands/hosts.rb +2 -0
- data/lib/morpheus/cli/commands/instances.rb +9 -3
- data/lib/morpheus/cli/commands/jobs_command.rb +50 -3
- data/lib/morpheus/cli/commands/key_pairs.rb +94 -33
- data/lib/morpheus/cli/commands/network_floating_ips.rb +109 -0
- data/lib/morpheus/cli/commands/reports_command.rb +8 -1
- data/lib/morpheus/cli/commands/resource_pool_groups_command.rb +586 -0
- data/lib/morpheus/cli/commands/roles.rb +10 -10
- data/lib/morpheus/cli/commands/service_catalog_command.rb +40 -2
- data/lib/morpheus/cli/commands/service_plans_command.rb +51 -22
- data/lib/morpheus/cli/commands/shell.rb +1 -1
- data/lib/morpheus/cli/commands/tasks.rb +130 -35
- data/lib/morpheus/cli/commands/workflows.rb +109 -23
- data/lib/morpheus/cli/mixins/infrastructure_helper.rb +148 -0
- data/lib/morpheus/cli/mixins/jobs_helper.rb +30 -3
- data/lib/morpheus/cli/mixins/processes_helper.rb +2 -26
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +2 -1
- data/lib/morpheus/cli/option_types.rb +2 -2
- data/lib/morpheus/cli/version.rb +1 -1
- data/test/cli/doc_test.rb +1 -1
- metadata +6 -2
@@ -0,0 +1,586 @@
|
|
1
|
+
require 'morpheus/cli/cli_command'
|
2
|
+
|
3
|
+
class Morpheus::Cli::ResourcePoolGroupsCommand
|
4
|
+
include Morpheus::Cli::CliCommand
|
5
|
+
include Morpheus::Cli::InfrastructureHelper
|
6
|
+
|
7
|
+
set_command_name :'resource-pool-groups'
|
8
|
+
|
9
|
+
register_subcommands :list, :get, :add, :update, :remove
|
10
|
+
|
11
|
+
# set_default_subcommand :list
|
12
|
+
|
13
|
+
def initialize()
|
14
|
+
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
15
|
+
end
|
16
|
+
|
17
|
+
def connect(opts)
|
18
|
+
@api_client = establish_remote_appliance_connection(opts)
|
19
|
+
@resource_pool_groups_interface = @api_client.resource_pool_groups
|
20
|
+
@cloud_resource_pools_interface = @api_client.cloud_resource_pools
|
21
|
+
@clouds_interface = @api_client.clouds
|
22
|
+
@options_interface = @api_client.options
|
23
|
+
end
|
24
|
+
|
25
|
+
def handle(args)
|
26
|
+
handle_subcommand(args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def list(args)
|
30
|
+
options = {}
|
31
|
+
params = {}
|
32
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
33
|
+
opts.banner = subcommand_usage()
|
34
|
+
build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
|
35
|
+
opts.footer = "List resource pool groups."
|
36
|
+
end
|
37
|
+
optparse.parse!(args)
|
38
|
+
connect(options)
|
39
|
+
begin
|
40
|
+
params.merge!(parse_list_options(options))
|
41
|
+
@resource_pool_groups_interface.setopts(options)
|
42
|
+
if options[:dry_run]
|
43
|
+
print_dry_run @resource_pool_groups_interface.dry.list(params)
|
44
|
+
return
|
45
|
+
end
|
46
|
+
json_response = @resource_pool_groups_interface.list(params)
|
47
|
+
resource_pool_groups = json_response["resourcePoolGroups"]
|
48
|
+
if options[:json]
|
49
|
+
puts as_json(json_response, options, "resourcePoolGroups")
|
50
|
+
return 0
|
51
|
+
elsif options[:yaml]
|
52
|
+
puts as_yaml(json_response, options, "resourcePoolGroups")
|
53
|
+
return 0
|
54
|
+
elsif options[:csv]
|
55
|
+
puts records_as_csv(resource_pool_groups, options)
|
56
|
+
return 0
|
57
|
+
end
|
58
|
+
title = "Morpheus Resource Pool Groups"
|
59
|
+
subtitles = []
|
60
|
+
subtitles += parse_list_subtitles(options)
|
61
|
+
print_h1 title, subtitles
|
62
|
+
if resource_pool_groups.empty?
|
63
|
+
print cyan,"No resource pool groups found.",reset,"\n"
|
64
|
+
else
|
65
|
+
rows = resource_pool_groups.collect {|resource_pool_group|
|
66
|
+
row = {
|
67
|
+
id: resource_pool_group['id'],
|
68
|
+
name: resource_pool_group['name'],
|
69
|
+
description: resource_pool_group['description'],
|
70
|
+
mode: resource_pool_group['mode'],
|
71
|
+
pools: resource_pool_group['pools'] ? resource_pool_group['pools'].size : 0,
|
72
|
+
visibility: resource_pool_group['visibility'].to_s.capitalize,
|
73
|
+
tenants: resource_pool_group['tenants'] ? resource_pool_group['tenants'].collect {|it| it['name'] }.uniq.join(', ') : ''
|
74
|
+
}
|
75
|
+
row
|
76
|
+
}
|
77
|
+
columns = [:id, :name, :description, :mode, :pools, :visibility, :tenants]
|
78
|
+
if options[:include_fields]
|
79
|
+
columns = options[:include_fields]
|
80
|
+
end
|
81
|
+
print cyan
|
82
|
+
print as_pretty_table(rows, columns, options)
|
83
|
+
print reset
|
84
|
+
print_results_pagination(json_response, {:label => "resource pool group", :n_label => "resource pool groups"})
|
85
|
+
end
|
86
|
+
print reset,"\n"
|
87
|
+
return 0
|
88
|
+
rescue RestClient::Exception => e
|
89
|
+
print_rest_exception(e, options)
|
90
|
+
exit 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def get(args)
|
95
|
+
options = {}
|
96
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
97
|
+
opts.banner = subcommand_usage("[resource-pool-group]")
|
98
|
+
build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
|
99
|
+
opts.footer = "Get details about a resource pool group." + "\n" +
|
100
|
+
"[resource-pool-group] is required. This is the name or id of a resource pool group."
|
101
|
+
end
|
102
|
+
optparse.parse!(args)
|
103
|
+
if args.count != 1
|
104
|
+
print_error Morpheus::Terminal.angry_prompt
|
105
|
+
puts_error "#{command_name} missing argument: [resource-pool-group]\n#{optparse}"
|
106
|
+
return 1
|
107
|
+
end
|
108
|
+
connect(options)
|
109
|
+
exit_code, err = 0, nil
|
110
|
+
begin
|
111
|
+
resource_pool_group_id = nil
|
112
|
+
if args[0].to_s =~ /\A\d{1,}\Z/
|
113
|
+
resource_pool_group_id = args[0].to_i
|
114
|
+
else
|
115
|
+
resource_pool_group = find_resource_pool_group_by_name(args[0])
|
116
|
+
return 1, "Resource Pool Group not found" if resource_pool_group.nil?
|
117
|
+
resource_pool_group_id = resource_pool_group['id']
|
118
|
+
end
|
119
|
+
@resource_pool_groups_interface.setopts(options)
|
120
|
+
if options[:dry_run]
|
121
|
+
print_dry_run @resource_pool_groups_interface.dry.get(resource_pool_group_id)
|
122
|
+
return exit_code, err
|
123
|
+
end
|
124
|
+
json_response = @resource_pool_groups_interface.get(resource_pool_group_id)
|
125
|
+
render_result = render_with_format(json_response, options, 'resourcePoolGroup')
|
126
|
+
return exit_code, err if render_result
|
127
|
+
|
128
|
+
resource_pool_group = json_response['resourcePoolGroup']
|
129
|
+
pools = json_response['pools']
|
130
|
+
|
131
|
+
print_h1 "Resource Pool Group Details"
|
132
|
+
print cyan
|
133
|
+
description_cols = {
|
134
|
+
"ID" => 'id',
|
135
|
+
"Name" => 'name',
|
136
|
+
"Description" => 'description',
|
137
|
+
"Mode" => 'mode',
|
138
|
+
"Pools" => lambda {|it| it['pools'].size rescue 'n/a' },
|
139
|
+
"Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
|
140
|
+
"Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|it| it['name'] }.uniq.join(', ') : '' },
|
141
|
+
}
|
142
|
+
print_description_list(description_cols, resource_pool_group)
|
143
|
+
|
144
|
+
if pools.empty?
|
145
|
+
# print cyan,"No pools found.",reset,"\n"
|
146
|
+
else
|
147
|
+
print_h2 "Pools"
|
148
|
+
pool_columns = {
|
149
|
+
"ID" => 'id',
|
150
|
+
"Name" => 'name',
|
151
|
+
#"Description" => 'description',
|
152
|
+
"Cloud" => lambda {|it| it['zone']['name'] rescue it['zone'] },
|
153
|
+
"Default" => lambda {|it| it['defaultPool'] },
|
154
|
+
"Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
|
155
|
+
"Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|it| it['name'] }.uniq.join(', ') : '' },
|
156
|
+
}
|
157
|
+
print cyan
|
158
|
+
print as_pretty_table(pools, pool_columns)
|
159
|
+
print reset,"\n"
|
160
|
+
end
|
161
|
+
|
162
|
+
if resource_pool_group['resourcePermission'].nil?
|
163
|
+
print "\n", "No group access found", "\n"
|
164
|
+
else
|
165
|
+
print_h2 "Group Access"
|
166
|
+
rows = []
|
167
|
+
if resource_pool_group['resourcePermission']['all']
|
168
|
+
rows.push({"name" => 'All'})
|
169
|
+
end
|
170
|
+
if resource_pool_group['resourcePermission']['sites']
|
171
|
+
resource_pool_group['resourcePermission']['sites'].each do |site|
|
172
|
+
rows.push(site)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
rows = rows.collect do |site|
|
176
|
+
{group: site['name'], default: site['default'] ? 'Yes' : ''}
|
177
|
+
end
|
178
|
+
columns = [:group, :default]
|
179
|
+
print cyan
|
180
|
+
print as_pretty_table(rows, columns)
|
181
|
+
print reset,"\n"
|
182
|
+
end
|
183
|
+
|
184
|
+
return 0
|
185
|
+
rescue RestClient::Exception => e
|
186
|
+
print_rest_exception(e, options)
|
187
|
+
return 1
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
#AC HERE
|
192
|
+
def add(args)
|
193
|
+
options = {}
|
194
|
+
tenants = nil
|
195
|
+
group_access_all = nil
|
196
|
+
group_access_list = nil
|
197
|
+
group_defaults_list = nil
|
198
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
199
|
+
opts.banner = subcommand_usage("--pools [id,id,id]")
|
200
|
+
opts.on('--name VALUE', String, "Name for this resource pool group") do |val|
|
201
|
+
options['name'] = val
|
202
|
+
end
|
203
|
+
opts.on('--description VALUE', String, "Description of resource pool group") do |val|
|
204
|
+
options['description'] = val
|
205
|
+
end
|
206
|
+
opts.on('--mode VALUE', String, "Pool selection mode for the resource pool group. Can be roundrobin or availablecapacity") do |val|
|
207
|
+
options['mode'] = val
|
208
|
+
end
|
209
|
+
opts.on('--pools LIST', Array, "Pools in the group, comma separated list of pool names or IDs") do |list|
|
210
|
+
if list.size == 1 && ('[]' == list[0]) # clear array
|
211
|
+
options['pools'] = []
|
212
|
+
else
|
213
|
+
options['pools'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
214
|
+
end
|
215
|
+
end
|
216
|
+
opts.on('--group-access-all [on|off]', String, "Toggle Access for all groups.") do |val|
|
217
|
+
group_access_all = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
218
|
+
end
|
219
|
+
opts.on('--group-access LIST', Array, "Group Access, comma separated list of group IDs.") do |list|
|
220
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
221
|
+
group_access_list = []
|
222
|
+
else
|
223
|
+
group_access_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
224
|
+
end
|
225
|
+
end
|
226
|
+
opts.on('--group-defaults LIST', Array, "Group Default Selection, comma separated list of group IDs") do |list|
|
227
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
228
|
+
group_defaults_list = []
|
229
|
+
else
|
230
|
+
group_defaults_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
231
|
+
end
|
232
|
+
end
|
233
|
+
opts.on('--tenants LIST', Array, "Tenant Access, comma separated list of account IDs") do |list|
|
234
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
235
|
+
options['tenants'] = []
|
236
|
+
else
|
237
|
+
options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
238
|
+
end
|
239
|
+
end
|
240
|
+
opts.on('--accounts LIST', Array, "alias for --tenants") do |list|
|
241
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
242
|
+
options['tenants'] = []
|
243
|
+
else
|
244
|
+
options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
245
|
+
end
|
246
|
+
end
|
247
|
+
opts.on('--visibility [private|public]', String, "Visibility") do |val|
|
248
|
+
options['visibility'] = val
|
249
|
+
end
|
250
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
|
251
|
+
opts.footer = "Create a new resource pool group." + "\n" +
|
252
|
+
"[name] is required and can be passed as --name instead."
|
253
|
+
end
|
254
|
+
optparse.parse!(args)
|
255
|
+
if args.count > 1
|
256
|
+
print_error Morpheus::Terminal.angry_prompt
|
257
|
+
puts_error "wrong number of arguments, expected 0-1 and got #{args.count}\n#{optparse}"
|
258
|
+
return 1
|
259
|
+
end
|
260
|
+
connect(options)
|
261
|
+
begin
|
262
|
+
# merge -O options into normally parsed options
|
263
|
+
options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
264
|
+
|
265
|
+
# support [name] as first argument
|
266
|
+
if args[0]
|
267
|
+
options['name'] = args[0]
|
268
|
+
end
|
269
|
+
|
270
|
+
# construct payload
|
271
|
+
payload = nil
|
272
|
+
if options[:payload]
|
273
|
+
payload = options[:payload]
|
274
|
+
else
|
275
|
+
# prompt for resource pool group options
|
276
|
+
payload = {
|
277
|
+
'resourcePoolGroup' => {
|
278
|
+
# 'config' => {}
|
279
|
+
}
|
280
|
+
}
|
281
|
+
|
282
|
+
# allow arbitrary -O options
|
283
|
+
payload['resourcePoolGroup'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
284
|
+
|
285
|
+
# Name
|
286
|
+
if options['name']
|
287
|
+
payload['resourcePoolGroup']['name'] = options['name']
|
288
|
+
else
|
289
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name for this resource pool group.'}], options)
|
290
|
+
payload['resourcePoolGroup']['name'] = v_prompt['name']
|
291
|
+
end
|
292
|
+
|
293
|
+
# Mode
|
294
|
+
if options['mode']
|
295
|
+
payload['resourcePoolGroup']['mode'] = options['mode']
|
296
|
+
else
|
297
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'mode', 'fieldLabel' => 'Mode', 'type' => 'text', 'required' => true, 'description' => 'Pool selection mode for the resource pool group. Can be roundrobin or availablecapacity.', 'defaultValue' => 'roundrobin'}], options)
|
298
|
+
payload['resourcePoolGroup']['mode'] = v_prompt['mode']
|
299
|
+
end
|
300
|
+
|
301
|
+
# Description
|
302
|
+
if options['description']
|
303
|
+
payload['resourcePoolGroup']['description'] = options['description']
|
304
|
+
else
|
305
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false, 'description' => 'Description of resource pool group.'}], options)
|
306
|
+
payload['resourcePoolGroup']['description'] = v_prompt['description']
|
307
|
+
end
|
308
|
+
|
309
|
+
# Pools
|
310
|
+
prompt_results = prompt_for_pools(options, options, @api_client)
|
311
|
+
if prompt_results[:success]
|
312
|
+
payload['resourcePoolGroup']['pools'] = prompt_results[:data] unless prompt_results[:data].nil?
|
313
|
+
else
|
314
|
+
return 1, "Pools prompt failed."
|
315
|
+
end
|
316
|
+
|
317
|
+
# Group Access
|
318
|
+
if group_access_all != nil
|
319
|
+
payload['resourcePermissions'] ||= {}
|
320
|
+
payload['resourcePermissions']['all'] = group_access_all
|
321
|
+
end
|
322
|
+
if group_access_list != nil
|
323
|
+
payload['resourcePermissions'] ||= {}
|
324
|
+
payload['resourcePermissions']['sites'] = group_access_list.collect do |site_id|
|
325
|
+
site = {"id" => site_id.to_i}
|
326
|
+
if group_defaults_list && group_defaults_list.include?(site_id)
|
327
|
+
site["default"] = true
|
328
|
+
end
|
329
|
+
site
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
# Tenants
|
334
|
+
if options['tenants']
|
335
|
+
payload['tenantPermissions'] = {}
|
336
|
+
payload['tenantPermissions']['accounts'] = options['tenants']
|
337
|
+
end
|
338
|
+
|
339
|
+
# Visibility
|
340
|
+
if options['visibility'] != nil
|
341
|
+
payload['resourcePoolGroup']['visibility'] = options['visibility']
|
342
|
+
end
|
343
|
+
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
@resource_pool_groups_interface.setopts(options)
|
348
|
+
if options[:dry_run]
|
349
|
+
print_dry_run @resource_pool_groups_interface.dry.create(payload)
|
350
|
+
return
|
351
|
+
end
|
352
|
+
json_response = @resource_pool_groups_interface.create(payload)
|
353
|
+
if options[:json]
|
354
|
+
print JSON.pretty_generate(json_response)
|
355
|
+
print "\n"
|
356
|
+
elsif !options[:quiet]
|
357
|
+
resource_pool_group = json_response['resourcePoolGroup']
|
358
|
+
print_green_success "Added resource pool group #{resource_pool_group['name']}"
|
359
|
+
get([resource_pool_group['id']])
|
360
|
+
end
|
361
|
+
return 0
|
362
|
+
rescue RestClient::Exception => e
|
363
|
+
print_rest_exception(e, options)
|
364
|
+
exit 1
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
def update(args)
|
369
|
+
options = {}
|
370
|
+
tenants = nil
|
371
|
+
group_access_all = nil
|
372
|
+
group_access_list = nil
|
373
|
+
group_defaults_list = nil
|
374
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
375
|
+
opts.banner = subcommand_usage("[resource-pool-group] [options]")
|
376
|
+
opts.on('--name VALUE', String, "Name for this resource pool group") do |val|
|
377
|
+
options['name'] = val
|
378
|
+
end
|
379
|
+
opts.on('--description VALUE', String, "Description of resource pool group") do |val|
|
380
|
+
options['description'] = val
|
381
|
+
end
|
382
|
+
opts.on('--mode VALUE', String, "Pool selection mode for the resource pool group. Can be roundrobin or availablecapacity") do |val|
|
383
|
+
options['mode'] = val
|
384
|
+
end
|
385
|
+
opts.on('--pools LIST', Array, "Pools in the group, comma separated list of pool IDs") do |list|
|
386
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
387
|
+
options['pools'] = []
|
388
|
+
else
|
389
|
+
options['pools'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
390
|
+
end
|
391
|
+
end
|
392
|
+
opts.on('--group-access-all [on|off]', String, "Toggle Access for all groups.") do |val|
|
393
|
+
group_access_all = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
394
|
+
end
|
395
|
+
opts.on('--group-access LIST', Array, "Group Access, comma separated list of group IDs.") do |list|
|
396
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
397
|
+
group_access_list = []
|
398
|
+
else
|
399
|
+
group_access_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
400
|
+
end
|
401
|
+
end
|
402
|
+
opts.on('--group-defaults LIST', Array, "Group Default Selection, comma separated list of group IDs") do |list|
|
403
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
404
|
+
group_defaults_list = []
|
405
|
+
else
|
406
|
+
group_defaults_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
407
|
+
end
|
408
|
+
end
|
409
|
+
opts.on('--tenants LIST', Array, "Tenant Access, comma separated list of account IDs") do |list|
|
410
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
411
|
+
options['tenants'] = []
|
412
|
+
else
|
413
|
+
options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
414
|
+
end
|
415
|
+
end
|
416
|
+
opts.on('--accounts LIST', Array, "alias for --tenants") do |list|
|
417
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
418
|
+
options['tenants'] = []
|
419
|
+
else
|
420
|
+
options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
421
|
+
end
|
422
|
+
end
|
423
|
+
opts.on('--visibility [private|public]', String, "Visibility") do |val|
|
424
|
+
options['visibility'] = val
|
425
|
+
end
|
426
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
427
|
+
opts.footer = "Update a resource pool group." + "\n" +
|
428
|
+
"[resource-pool-group] is required. This is the id of a resource pool group."
|
429
|
+
end
|
430
|
+
optparse.parse!(args)
|
431
|
+
if args.count != 1
|
432
|
+
print_error Morpheus::Terminal.angry_prompt
|
433
|
+
puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
|
434
|
+
return 1
|
435
|
+
end
|
436
|
+
connect(options)
|
437
|
+
|
438
|
+
begin
|
439
|
+
resource_pool_group = find_resource_pool_group_by_name_or_id(args[0])
|
440
|
+
return 1 if resource_pool_group.nil?
|
441
|
+
|
442
|
+
# merge -O options into normally parsed options
|
443
|
+
options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
444
|
+
|
445
|
+
# construct payload
|
446
|
+
payload = nil
|
447
|
+
if options[:payload]
|
448
|
+
payload = options[:payload]
|
449
|
+
else
|
450
|
+
# prompt for resource pool group options
|
451
|
+
payload = {
|
452
|
+
'resourcePoolGroup' => {
|
453
|
+
}
|
454
|
+
}
|
455
|
+
|
456
|
+
# allow arbitrary -O options
|
457
|
+
payload['resourcePoolGroup'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
458
|
+
|
459
|
+
# Name
|
460
|
+
if options['name']
|
461
|
+
payload['resourcePoolGroup']['name'] = options['name']
|
462
|
+
end
|
463
|
+
|
464
|
+
|
465
|
+
# Description
|
466
|
+
if options['description']
|
467
|
+
payload['resourcePoolGroup']['description'] = options['description']
|
468
|
+
end
|
469
|
+
|
470
|
+
# Description
|
471
|
+
if options['mode']
|
472
|
+
payload['resourcePoolGroup']['mode'] = options['mode']
|
473
|
+
end
|
474
|
+
|
475
|
+
# Pools
|
476
|
+
if options['pools']
|
477
|
+
prompt_results = prompt_for_pools(options, options, @api_client)
|
478
|
+
if prompt_results[:success]
|
479
|
+
payload['resourcePoolGroup']['pools'] = prompt_results[:data] unless prompt_results[:data].nil?
|
480
|
+
else
|
481
|
+
return 1, "Pools prompt failed."
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
# Group Access
|
486
|
+
if group_access_all != nil
|
487
|
+
payload['resourcePermissions'] ||= {}
|
488
|
+
payload['resourcePermissions']['all'] = group_access_all
|
489
|
+
end
|
490
|
+
if group_access_list != nil
|
491
|
+
payload['resourcePermissions'] ||= {}
|
492
|
+
payload['resourcePermissions']['sites'] = group_access_list.collect do |site_id|
|
493
|
+
site = {"id" => site_id.to_i}
|
494
|
+
if group_defaults_list && group_defaults_list.include?(site_id)
|
495
|
+
site["default"] = true
|
496
|
+
end
|
497
|
+
site
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
# Tenants
|
502
|
+
if options['tenants']
|
503
|
+
payload['tenantPermissions'] = {}
|
504
|
+
payload['tenantPermissions']['accounts'] = options['tenants']
|
505
|
+
end
|
506
|
+
|
507
|
+
# Visibility
|
508
|
+
if options['visibility'] != nil
|
509
|
+
payload['resourcePoolGroup']['visibility'] = options['visibility']
|
510
|
+
end
|
511
|
+
|
512
|
+
# pre 4.2.1, would error with data not found unless you pass something in here
|
513
|
+
# so pass foo=bar so you can update just resourcePermissions
|
514
|
+
if payload['resourcePoolGroup'] && payload['resourcePoolGroup'].empty? && payload['resourcePermissions']
|
515
|
+
payload['resourcePoolGroup']['foo'] = 'bar'
|
516
|
+
end
|
517
|
+
|
518
|
+
end
|
519
|
+
@resource_pool_groups_interface.setopts(options)
|
520
|
+
if options[:dry_run]
|
521
|
+
print_dry_run @resource_pool_groups_interface.dry.update(resource_pool_group["id"], payload)
|
522
|
+
return
|
523
|
+
end
|
524
|
+
json_response = @resource_pool_groups_interface.update(resource_pool_group["id"], payload)
|
525
|
+
if options[:json]
|
526
|
+
puts as_json(json_response)
|
527
|
+
else
|
528
|
+
resource_pool_group = json_response['resourcePoolGroup']
|
529
|
+
print_green_success "Updated resource pool group #{resource_pool_group['name']}"
|
530
|
+
get([resource_pool_group['id']])
|
531
|
+
end
|
532
|
+
return 0
|
533
|
+
rescue RestClient::Exception => e
|
534
|
+
print_rest_exception(e, options)
|
535
|
+
return 1
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
def remove(args)
|
540
|
+
options = {}
|
541
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
542
|
+
opts.banner = subcommand_usage("[resource-pool-group]")
|
543
|
+
build_common_options(opts, options, [:account, :auto_confirm, :json, :dry_run, :remote])
|
544
|
+
opts.footer = "Delete a resource pool group." + "\n" +
|
545
|
+
"[resource-pool-group] is required. This is the name or id of a resource pool group."
|
546
|
+
end
|
547
|
+
optparse.parse!(args)
|
548
|
+
|
549
|
+
if args.count < 1
|
550
|
+
print_error Morpheus::Terminal.angry_prompt
|
551
|
+
puts_error "#{command_name} missing argument: [resource-pool-group]\n#{optparse}"
|
552
|
+
return 1
|
553
|
+
end
|
554
|
+
|
555
|
+
connect(options)
|
556
|
+
begin
|
557
|
+
resource_pool_group = find_resource_pool_group_by_name_or_id(args[0])
|
558
|
+
return 1 if resource_pool_group.nil?
|
559
|
+
|
560
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the resource pool group: #{resource_pool_group['name']}?")
|
561
|
+
return 9, "aborted command"
|
562
|
+
end
|
563
|
+
@resource_pool_groups_interface.setopts(options)
|
564
|
+
if options[:dry_run]
|
565
|
+
print_dry_run @resource_pool_groups_interface.dry.destroy(resource_pool_group['id'])
|
566
|
+
return 0
|
567
|
+
end
|
568
|
+
json_response = @resource_pool_groups_interface.destroy(resource_pool_group['id'])
|
569
|
+
if options[:json]
|
570
|
+
print JSON.pretty_generate(json_response)
|
571
|
+
print "\n"
|
572
|
+
else
|
573
|
+
print_green_success "Removed resource pool group #{resource_pool_group['name']}"
|
574
|
+
# list([])
|
575
|
+
end
|
576
|
+
return 0
|
577
|
+
rescue RestClient::Exception => e
|
578
|
+
print_rest_exception(e, options)
|
579
|
+
return 1
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
private
|
584
|
+
|
585
|
+
|
586
|
+
end
|
@@ -1429,7 +1429,7 @@ EOT
|
|
1429
1429
|
end
|
1430
1430
|
name = args[0]
|
1431
1431
|
access_value = args[1].to_s.downcase
|
1432
|
-
if !['full', 'read', 'none'].include?(access_value)
|
1432
|
+
if !['full', 'read', 'none', 'custom'].include?(access_value)
|
1433
1433
|
puts optparse
|
1434
1434
|
exit 1
|
1435
1435
|
end
|
@@ -1582,7 +1582,7 @@ EOT
|
|
1582
1582
|
end
|
1583
1583
|
name = args[0]
|
1584
1584
|
access_value = args[1].to_s.downcase
|
1585
|
-
if !['full', 'read', 'none'].include?(access_value)
|
1585
|
+
if !['full', 'read', 'none', 'custom'].include?(access_value)
|
1586
1586
|
puts optparse
|
1587
1587
|
exit 1
|
1588
1588
|
end
|
@@ -1733,7 +1733,7 @@ EOT
|
|
1733
1733
|
end
|
1734
1734
|
name = args[0]
|
1735
1735
|
access_value = args[1].to_s.downcase
|
1736
|
-
if !['full', 'none'].include?(access_value)
|
1736
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
1737
1737
|
puts optparse
|
1738
1738
|
exit 1
|
1739
1739
|
end
|
@@ -1881,7 +1881,7 @@ EOT
|
|
1881
1881
|
end
|
1882
1882
|
name = args[0]
|
1883
1883
|
access_value = args[1].to_s.downcase
|
1884
|
-
if !['full', 'none'].include?(access_value)
|
1884
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
1885
1885
|
puts optparse
|
1886
1886
|
exit 1
|
1887
1887
|
end
|
@@ -2043,7 +2043,7 @@ EOT
|
|
2043
2043
|
end
|
2044
2044
|
name = args[0]
|
2045
2045
|
access_value = args[1].to_s.downcase
|
2046
|
-
if !['full', 'none'].include?(access_value)
|
2046
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
2047
2047
|
puts optparse
|
2048
2048
|
exit 1
|
2049
2049
|
end
|
@@ -2198,7 +2198,7 @@ Update default persona access for a role.
|
|
2198
2198
|
end
|
2199
2199
|
name = args[0]
|
2200
2200
|
access_value = args[1].to_s.downcase
|
2201
|
-
if !['full', 'none'].include?(access_value)
|
2201
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
2202
2202
|
puts optparse
|
2203
2203
|
exit 1
|
2204
2204
|
end
|
@@ -2341,7 +2341,7 @@ EOT
|
|
2341
2341
|
verify_args!(args:args, optparse:optparse, count: 2)
|
2342
2342
|
name = args[0]
|
2343
2343
|
access_value = args[1].to_s.downcase
|
2344
|
-
if !['full', 'none'].include?(access_value)
|
2344
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
2345
2345
|
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
2346
2346
|
end
|
2347
2347
|
|
@@ -2496,7 +2496,7 @@ EOT
|
|
2496
2496
|
verify_args!(args:args, optparse:optparse, count: 2)
|
2497
2497
|
name = args[0]
|
2498
2498
|
access_value = args[1].to_s.downcase
|
2499
|
-
if !['full', 'none'].include?(access_value)
|
2499
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
2500
2500
|
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
2501
2501
|
end
|
2502
2502
|
|
@@ -2652,7 +2652,7 @@ Update default task access for a role.
|
|
2652
2652
|
verify_args!(args:args, optparse:optparse, count: 2)
|
2653
2653
|
name = args[0]
|
2654
2654
|
access_value = args[1].to_s.downcase
|
2655
|
-
if !['full', 'none'].include?(access_value)
|
2655
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
2656
2656
|
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
2657
2657
|
end
|
2658
2658
|
|
@@ -2805,7 +2805,7 @@ Update default workflow access for a role.
|
|
2805
2805
|
verify_args!(args:args, optparse:optparse, count: 2)
|
2806
2806
|
name = args[0]
|
2807
2807
|
access_value = args[1].to_s.downcase
|
2808
|
-
if !['full', 'none'].include?(access_value)
|
2808
|
+
if !['full', 'none', 'custom'].include?(access_value)
|
2809
2809
|
raise_command_error("invalid access value: #{args[1]}", args, optparse)
|
2810
2810
|
end
|
2811
2811
|
|