Class: Morpheus::Cli::ResourcePoolGroupsCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand, InfrastructureHelper
Defined in:
lib/morpheus/cli/commands/resource_pool_groups_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from InfrastructureHelper

#cloud_type_for_id, #cloud_type_for_name, #cloud_type_for_name_or_id, #clouds_interface, #find_cloud_by_id, #find_cloud_by_name, #find_cloud_by_name_or_id, #find_group_by_id, #find_group_by_name, #find_group_by_name_or_id, #find_network_by_id, #find_network_by_name, #find_network_by_name_or_id, #find_network_group_by_id, #find_network_group_by_name, #find_network_group_by_name_or_id, #find_network_server_type_by_id, #find_network_server_type_by_name, #find_network_server_type_by_name_or_code, #find_network_server_type_by_name_or_id, #find_network_type_by_id, #find_network_type_by_name, #find_network_type_by_name_or_id, #find_resource_pool_by_id, #find_resource_pool_by_name, #find_resource_pool_by_name_or_id, #find_resource_pool_group_by_id, #find_resource_pool_group_by_name, #find_resource_pool_group_by_name_or_id, #find_subnet_by_id, #find_subnet_by_name, #find_subnet_by_name_or_id, #find_subnet_type_by_id, #find_subnet_type_by_name, #find_subnet_type_by_name_or_id, #format_network_pool_server_status, #get_available_cloud_types, #groups_interface, included, #network_groups_interface, #network_pool_server_column_definitions, #network_pool_server_list_column_definitions, #network_pool_server_type_column_definitions, #network_pool_server_type_list_column_definitions, #network_server_type_column_definitions, #network_server_type_list_column_definitions, #network_types_interface, #networks_interface, #prompt_for_network, #prompt_for_networks, #prompt_for_pools, #prompt_for_subnets, #resource_pool_groups_interface, #resource_pools_interface, #subnet_types_interface, #subnets_interface

Methods included from CliCommand

#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Constructor Details

#initializeResourcePoolGroupsCommand

set_default_subcommand :list



13
14
15
# File 'lib/morpheus/cli/commands/resource_pool_groups_command.rb', line 13

def initialize()
  # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
end

Instance Method Details

#add(args) ⇒ Object

AC HERE



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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/morpheus/cli/commands/resource_pool_groups_command.rb', line 192

def add(args)
  options = {}
  tenants = nil
  group_access_all = nil
  group_access_list = nil
  group_defaults_list = nil
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("--pools [id,id,id]")
    opts.on('--name VALUE', String, "Name for this resource pool group") do |val|
      options['name'] = val
    end
    opts.on('--description VALUE', String, "Description of resource pool group") do |val|
      options['description'] = val
    end
    opts.on('--mode VALUE', String, "Pool selection mode for the resource pool group. Can be roundrobin or availablecapacity") do |val|
      options['mode'] = val
    end
    opts.on('--pools LIST', Array, "Pools in the group, comma separated list of pool names or IDs") do |list|
      if list.size == 1 && ('[]' == list[0]) # clear array
        options['pools'] = []
      else
        options['pools'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--group-access-all [on|off]', String, "Toggle Access for all groups.") do |val|
      group_access_all = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
    end
    opts.on('--group-access LIST', Array, "Group Access, comma separated list of group IDs.") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        group_access_list = []
      else
        group_access_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--group-defaults LIST', Array, "Group Default Selection, comma separated list of group IDs") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        group_defaults_list = []
      else
        group_defaults_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--tenants LIST', Array, "Tenant Access, comma separated list of account IDs") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        options['tenants'] = []
      else
        options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--accounts LIST', Array, "alias for --tenants") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        options['tenants'] = []
      else
        options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--visibility [private|public]', String, "Visibility") do |val|
      options['visibility'] = val
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
    opts.footer = "Create a new resource pool group." + "\n" +
                  "[name] is required and can be passed as --name instead."
  end
  optparse.parse!(args)
  if args.count > 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 0-1 and got #{args.count}\n#{optparse}"
    return 1
  end
  connect(options)
  begin
    # merge -O options into normally parsed options
    options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]

    # support [name] as first argument
    if args[0]
      options['name'] = args[0]
    end

    # construct payload
    payload = nil
    if options[:payload]
      payload = options[:payload]
    else
      # prompt for resource pool group options
      payload = {
        'resourcePoolGroup' => {
          # 'config' => {}
        }
      }
      
      # allow arbitrary -O options
      payload['resourcePoolGroup'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]

      # Name
      if options['name']
        payload['resourcePoolGroup']['name'] = options['name']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name for this resource pool group.'}], options)
        payload['resourcePoolGroup']['name'] = v_prompt['name']
      end

      # Mode
      if options['mode']
        payload['resourcePoolGroup']['mode'] = options['mode']
      else
        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)
        payload['resourcePoolGroup']['mode'] = v_prompt['mode']
      end

      # Description
      if options['description']
        payload['resourcePoolGroup']['description'] = options['description']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false, 'description' => 'Description of resource pool group.'}], options)
        payload['resourcePoolGroup']['description'] = v_prompt['description']
      end
    
      # Pools
      prompt_results = prompt_for_pools(options, options, @api_client)
      if prompt_results[:success]
        payload['resourcePoolGroup']['pools'] = prompt_results[:data] unless prompt_results[:data].nil?
      else
        return 1, "Pools prompt failed."
      end
      
      # Group Access
      if group_access_all != nil
        payload['resourcePermissions'] ||= {}
        payload['resourcePermissions']['all'] = group_access_all
      end
      if group_access_list != nil
        payload['resourcePermissions'] ||= {}
        payload['resourcePermissions']['sites'] = group_access_list.collect do |site_id|
          site = {"id" => site_id.to_i}
          if group_defaults_list && group_defaults_list.include?(site_id)
            site["default"] = true
          end
          site
        end
      end

      # Tenants
      if options['tenants']
        payload['tenantPermissions'] = {}
        payload['tenantPermissions']['accounts'] = options['tenants']
      end
      
      # Visibility
      if options['visibility'] != nil
        payload['resourcePoolGroup']['visibility'] = options['visibility']
      end


    end

    @resource_pool_groups_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @resource_pool_groups_interface.dry.create(payload)
      return
    end
    json_response = @resource_pool_groups_interface.create(payload)
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    elsif !options[:quiet]
      resource_pool_group = json_response['resourcePoolGroup']
      print_green_success "Added resource pool group #{resource_pool_group['name']}"
      get([resource_pool_group['id']])
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#connect(opts) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/morpheus/cli/commands/resource_pool_groups_command.rb', line 17

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @resource_pool_groups_interface = @api_client.resource_pool_groups
  @cloud_resource_pools_interface = @api_client.cloud_resource_pools
  @clouds_interface = @api_client.clouds
  @options_interface = @api_client.options
end

#get(args) ⇒ Object



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
# File 'lib/morpheus/cli/commands/resource_pool_groups_command.rb', line 94

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[resource-pool-group]")
    build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "Get details about a resource pool group." + "\n" +
                  "[resource-pool-group] is required. This is the name or id of a resource pool group."
  end
  optparse.parse!(args)
  if args.count != 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "#{command_name} missing argument: [resource-pool-group]\n#{optparse}"
    return 1
  end
  connect(options)
  exit_code, err = 0, nil
  begin
    resource_pool_group_id = nil
    if args[0].to_s =~ /\A\d{1,}\Z/
      resource_pool_group_id = args[0].to_i
    else
      resource_pool_group = find_resource_pool_group_by_name(args[0])
      return 1, "Resource Pool Group not found" if resource_pool_group.nil?
      resource_pool_group_id = resource_pool_group['id']
    end
    @resource_pool_groups_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @resource_pool_groups_interface.dry.get(resource_pool_group_id)
      return exit_code, err
    end
    json_response = @resource_pool_groups_interface.get(resource_pool_group_id)
    render_result = render_with_format(json_response, options, 'resourcePoolGroup')
    return exit_code, err if render_result

    resource_pool_group = json_response['resourcePoolGroup']
    pools = json_response['pools'] 

    print_h1 "Resource Pool Group Details"
    print cyan
    description_cols = {
      "ID" => 'id',
      "Name" => 'name',
      "Description" => 'description',
      "Mode" => 'mode',
      "Pools" => lambda {|it| it['pools'].size rescue 'n/a' },
      "Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
      "Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|it| it['name'] }.uniq.join(', ') : '' },
    }
    print_description_list(description_cols, resource_pool_group)

    if pools.empty?
      # print cyan,"No pools found.",reset,"\n"
    else
      print_h2 "Pools"
      pool_columns = {
        "ID" => 'id',
        "Name" => 'name',
        #"Description" => 'description',
        "Cloud" => lambda {|it| it['zone']['name'] rescue it['zone'] },
        "Default" => lambda {|it| it['defaultPool'] },
        "Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
        "Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|it| it['name'] }.uniq.join(', ') : '' },
      }
      print cyan
      print as_pretty_table(pools, pool_columns)
      print reset,"\n"
    end

    if resource_pool_group['resourcePermission'].nil?
      print "\n", "No group access found", "\n"
    else
      print_h2 "Group Access"
      rows = []
      if resource_pool_group['resourcePermission']['all']
        rows.push({"name" => 'All'})
      end
      if resource_pool_group['resourcePermission']['sites']
        resource_pool_group['resourcePermission']['sites'].each do |site|
          rows.push(site)
        end
      end
      rows = rows.collect do |site|
        {group: site['name'], default: site['default'] ? 'Yes' : ''}
      end
      columns = [:group, :default]
      print cyan
      print as_pretty_table(rows, columns)
      print reset,"\n"
    end
    
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#handle(args) ⇒ Object



25
26
27
# File 'lib/morpheus/cli/commands/resource_pool_groups_command.rb', line 25

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



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
# File 'lib/morpheus/cli/commands/resource_pool_groups_command.rb', line 29

def list(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
    opts.footer = "List resource pool groups."
  end
  optparse.parse!(args)
  connect(options)
  begin
    params.merge!(parse_list_options(options))
    @resource_pool_groups_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @resource_pool_groups_interface.dry.list(params)
      return
    end
    json_response = @resource_pool_groups_interface.list(params)
    resource_pool_groups = json_response["resourcePoolGroups"]
    if options[:json]
      puts as_json(json_response, options, "resourcePoolGroups")
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "resourcePoolGroups")
      return 0
    elsif options[:csv]
      puts records_as_csv(resource_pool_groups, options)
      return 0
    end
    title = "Morpheus Resource Pool Groups"
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 title, subtitles
    if resource_pool_groups.empty?
      print cyan,"No resource pool groups found.",reset,"\n"
    else
      rows = resource_pool_groups.collect {|resource_pool_group| 
        row = {
          id: resource_pool_group['id'],
          name: resource_pool_group['name'],
          description: resource_pool_group['description'],
          mode: resource_pool_group['mode'],
          pools: resource_pool_group['pools'] ? resource_pool_group['pools'].size : 0,
          visibility: resource_pool_group['visibility'].to_s.capitalize,
          tenants: resource_pool_group['tenants'] ? resource_pool_group['tenants'].collect {|it| it['name'] }.uniq.join(', ') : ''
        }
        row
      }
      columns = [:id, :name, :description, :mode, :pools, :visibility, :tenants]
      if options[:include_fields]
        columns = options[:include_fields]
      end
      print cyan
      print as_pretty_table(rows, columns, options)
      print reset
      print_results_pagination(json_response, {:label => "resource pool group", :n_label => "resource pool groups"})
    end
    print reset,"\n"
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#remove(args) ⇒ Object



539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'lib/morpheus/cli/commands/resource_pool_groups_command.rb', line 539

def remove(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[resource-pool-group]")
    build_common_options(opts, options, [:account, :auto_confirm, :json, :dry_run, :remote])
    opts.footer = "Delete a resource pool group." + "\n" +
                  "[resource-pool-group] is required. This is the name or id of a resource pool group."
  end
  optparse.parse!(args)

  if args.count < 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "#{command_name} missing argument: [resource-pool-group]\n#{optparse}"
    return 1
  end

  connect(options)
  begin
    resource_pool_group = find_resource_pool_group_by_name_or_id(args[0])
    return 1 if resource_pool_group.nil?

    unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the resource pool group: #{resource_pool_group['name']}?")
      return 9, "aborted command"
    end
    @resource_pool_groups_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @resource_pool_groups_interface.dry.destroy(resource_pool_group['id'])
      return 0
    end
    json_response = @resource_pool_groups_interface.destroy(resource_pool_group['id'])
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Removed resource pool group #{resource_pool_group['name']}"
      # list([])
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#update(args) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/morpheus/cli/commands/resource_pool_groups_command.rb', line 368

def update(args)
  options = {}
  tenants = nil
  group_access_all = nil
  group_access_list = nil
  group_defaults_list = nil
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[resource-pool-group] [options]")
    opts.on('--name VALUE', String, "Name for this resource pool group") do |val|
      options['name'] = val
    end
    opts.on('--description VALUE', String, "Description of resource pool group") do |val|
      options['description'] = val
    end
    opts.on('--mode VALUE', String, "Pool selection mode for the resource pool group. Can be roundrobin or availablecapacity") do |val|
      options['mode'] = val
    end
    opts.on('--pools LIST', Array, "Pools in the group, comma separated list of pool IDs") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        options['pools'] = []
      else
        options['pools'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--group-access-all [on|off]', String, "Toggle Access for all groups.") do |val|
      group_access_all = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
    end
    opts.on('--group-access LIST', Array, "Group Access, comma separated list of group IDs.") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        group_access_list = []
      else
        group_access_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--group-defaults LIST', Array, "Group Default Selection, comma separated list of group IDs") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        group_defaults_list = []
      else
        group_defaults_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--tenants LIST', Array, "Tenant Access, comma separated list of account IDs") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        options['tenants'] = []
      else
        options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--accounts LIST', Array, "alias for --tenants") do |list|
      if list.size == 1 && list[0] == 'null' # hacky way to clear it
        options['tenants'] = []
      else
        options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
      end
    end
    opts.on('--visibility [private|public]', String, "Visibility") do |val|
      options['visibility'] = val
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
    opts.footer = "Update a resource pool group." + "\n" +
                  "[resource-pool-group] is required. This is the id of a resource pool group."
  end
  optparse.parse!(args)
  if args.count != 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
    return 1
  end
  connect(options)

  begin
    resource_pool_group = find_resource_pool_group_by_name_or_id(args[0])
    return 1 if resource_pool_group.nil?
    
    # merge -O options into normally parsed options
    options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]

    # construct payload
    payload = nil
    if options[:payload]
      payload = options[:payload]
    else
      # prompt for resource pool group options
      payload = {
        'resourcePoolGroup' => {
        }
      }
      
      # allow arbitrary -O options
      payload['resourcePoolGroup'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]

      # Name
      if options['name']
        payload['resourcePoolGroup']['name'] = options['name']
      end

      
      # Description
      if options['description']
        payload['resourcePoolGroup']['description'] = options['description']
      end

      # Description
      if options['mode']
        payload['resourcePoolGroup']['mode'] = options['mode']
      end

      # Pools
      if options['pools']
        prompt_results = prompt_for_pools(options, options, @api_client)
        if prompt_results[:success]
          payload['resourcePoolGroup']['pools'] = prompt_results[:data] unless prompt_results[:data].nil?
        else
          return 1, "Pools prompt failed."
        end
      end

      # Group Access
      if group_access_all != nil
        payload['resourcePermissions'] ||= {}
        payload['resourcePermissions']['all'] = group_access_all
      end
      if group_access_list != nil
        payload['resourcePermissions'] ||= {}
        payload['resourcePermissions']['sites'] = group_access_list.collect do |site_id|
          site = {"id" => site_id.to_i}
          if group_defaults_list && group_defaults_list.include?(site_id)
            site["default"] = true
          end
          site
        end
      end

      # Tenants
      if options['tenants']
        payload['tenantPermissions'] = {}
        payload['tenantPermissions']['accounts'] = options['tenants']
      end
      
      # Visibility
      if options['visibility'] != nil
        payload['resourcePoolGroup']['visibility'] = options['visibility']
      end
      
      # pre 4.2.1, would error with data not found unless you pass something in here
      # so pass foo=bar so you can update just resourcePermissions
      if payload['resourcePoolGroup'] && payload['resourcePoolGroup'].empty? && payload['resourcePermissions']
        payload['resourcePoolGroup']['foo'] = 'bar'
      end

    end
    @resource_pool_groups_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @resource_pool_groups_interface.dry.update(resource_pool_group["id"], payload)
      return
    end
    json_response = @resource_pool_groups_interface.update(resource_pool_group["id"], payload)
    if options[:json]
      puts as_json(json_response)
    else
      resource_pool_group = json_response['resourcePoolGroup']
      print_green_success "Updated resource pool group #{resource_pool_group['name']}"
      get([resource_pool_group['id']])
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end