morpheus-cli 5.3.2.3 → 5.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fedf8a7443a29dd8ac5097e8f17bec94d481d3d1cadffd16dce033d9cb152f61
4
- data.tar.gz: f1a306e2a42cebcb474371e589c07b2b31f6ed84faee0d47b640813e672d08ce
3
+ metadata.gz: ca7c939828b8f72ee86c663a19d01743a56d5c6c209cecc5e17b44046caeb484
4
+ data.tar.gz: e13fccbf1a45e8980e818e4cc1f0dba98d65e405c79f5d90e13c33341ad2e514
5
5
  SHA512:
6
- metadata.gz: fe7834f3099b3dd5666c9230c8b833ac05a613d58465850d0eaf5e88cdb973a8eec4ac020946d6ba902abb43cd71d705760040e69b243a2e670e2dd8b5295c9b
7
- data.tar.gz: 3cc4909d59ae2fcf99f319e74a13eb4db2261fe475629723b6a091fbf3dd13aa5f92e939ae9262ec44b9817b97591c21d6ac69046c400c41523ed588c9602087
6
+ metadata.gz: 5965b1af85499cadcae249f3109b6fd0ea4bee6af38192196fd6091bdcdb452f75c1f4025f372ec3d5f47ab1531e04acbf5fb2ed17848ba023087c309fdd06ee
7
+ data.tar.gz: 56bc2124de4e6b28c0c4484b5fa40beef19287708edd98ee1fdddbe334bc7854b853153209d1531793502aa8034d1c8ccf9fca643ec13aebf3eb8353cdd1f72e
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.5.1
2
2
 
3
- RUN gem install morpheus-cli -v 5.3.2.3
3
+ RUN gem install morpheus-cli -v 5.3.3
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
@@ -57,11 +57,24 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
57
57
  execute(opts)
58
58
  end
59
59
 
60
- def cancel_removal(id, params = {})
61
- url = "#{@base_url}/api/instances/#{id}/cancel-removal"
62
- headers = {:params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
63
- opts = {method: :put, url: url, headers: headers}
64
- execute(opts)
60
+ def extend_shutdown(id, params={}, payload={}, headers={})
61
+ execute(method: :put, url: "#{base_path}/#{id}/extend-shutdown", params: params, payload: payload, headers: headers)
62
+ end
63
+
64
+ def extend_expiration(id, params={}, payload={}, headers={})
65
+ execute(method: :put, url: "#{base_path}/#{id}/extend-expiration", params: params, payload: payload, headers: headers)
66
+ end
67
+
68
+ def cancel_shutdown(id, params={}, payload={}, headers={})
69
+ execute(method: :put, url: "#{base_path}/#{id}/cancel-shutdown", params: params, payload: payload, headers: headers)
70
+ end
71
+
72
+ def cancel_expiration(id, params={}, payload={}, headers={})
73
+ execute(method: :put, url: "#{base_path}/#{id}/cancel-expiration", params: params, payload: payload, headers: headers)
74
+ end
75
+
76
+ def cancel_removal(id, params={}, payload={}, headers={})
77
+ execute(method: :put, url: "#{base_path}/#{id}/cancel-removal", params: params, payload: payload, headers: headers)
65
78
  end
66
79
 
67
80
  def stop(id, params={})
@@ -45,10 +45,10 @@ class Morpheus::VirtualImagesInterface < Morpheus::APIClient
45
45
  execute(method: :put, url: url, headers: headers, payload: payload.to_json)
46
46
  end
47
47
 
48
- def destroy(id)
48
+ def destroy(id, params={})
49
49
  url = "#{@base_url}/api/virtual-images/#{id}"
50
50
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
51
- execute(method: :delete, url: url, headers: headers)
51
+ execute(method: :delete, url: url, params: params, headers: headers)
52
52
  end
53
53
 
54
54
  # multipart file upload
@@ -165,4 +165,25 @@ class Morpheus::VirtualImagesInterface < Morpheus::APIClient
165
165
  execute(method: :delete, url: url, headers: headers)
166
166
  end
167
167
 
168
+ def location_base_path(resource_id)
169
+ "/api/virtual-images/#{resource_id}/locations"
170
+ end
171
+
172
+ def list_locations(resource_id, params={}, headers={})
173
+ validate_id!(resource_id)
174
+ execute(method: :get, url: "#{location_base_path(resource_id)}", params: params, headers: headers)
175
+ end
176
+
177
+ def get_location(resource_id, id, params={}, headers={})
178
+ validate_id!(resource_id)
179
+ validate_id!(id)
180
+ execute(method: :get, url: "#{location_base_path(resource_id)}/#{id}", params: params, headers: headers)
181
+ end
182
+
183
+ def destroy_location(resource_id, id, params = {}, headers={})
184
+ validate_id!(resource_id)
185
+ validate_id!(id)
186
+ execute(method: :delete, url: "#{location_base_path(resource_id)}/#{id}", params: params, headers: headers)
187
+ end
188
+
168
189
  end
@@ -438,7 +438,7 @@ class Morpheus::Cli::Apps
438
438
  instance_prompt_options[:default_cloud] = cloud ? cloud['name'] : nil
439
439
  instance_prompt_options[:environment] = selected_environment ? selected_environment['code'] : nil
440
440
  instance_prompt_options[:default_security_groups] = scoped_instance_config['securityGroups'] ? scoped_instance_config['securityGroups'] : nil
441
-
441
+
442
442
  instance_prompt_options[:no_prompt] = options[:no_prompt]
443
443
  #instance_prompt_options[:always_prompt] = options[:no_prompt] != true # options[:always_prompt]
444
444
  instance_prompt_options[:options] = scoped_instance_config # meh, actually need to make these default values instead..
@@ -460,8 +460,9 @@ class Morpheus::Cli::Apps
460
460
  instance_prompt_options[:locked_fields] = scoped_instance_config['lockedFields']
461
461
  instance_prompt_options[:for_app] = true
462
462
  # this provisioning helper method handles all (most) of the parsing and prompting
463
+ scoped_instance_config = Marshal.load( Marshal.dump(scoped_instance_config) )
463
464
  instance_config_payload = prompt_new_instance(instance_prompt_options)
464
-
465
+
465
466
  # strip all empty string and nil
466
467
  instance_config_payload.deep_compact!
467
468
  # use the blueprint config as the base
@@ -1202,11 +1202,18 @@ module Morpheus
1202
1202
  # this could go be done in optparse.parse instead perhaps
1203
1203
  def verify_args!(opts={})
1204
1204
  args = opts[:args] || []
1205
- if opts[:count]
1206
- if args.count < opts[:count]
1207
- raise_args_error("not enough arguments, expected #{opts[:count]} and got #{args.count == 0 ? '0' : args.count.to_s + ': '}#{args.join(', ')}", args, opts[:optparse])
1208
- elsif args.count > opts[:count]
1209
- raise_args_error("too many arguments, expected #{opts[:count]} and got #{args.count == 0 ? '0' : args.count.to_s + ': '}#{args.join(', ')}", args, opts[:optparse])
1205
+ count = opts[:count]
1206
+ # simplify output for verify_args!(min:2, max:2) or verify_args!(max:0)
1207
+ if opts[:min] && opts[:max] && opts[:min] == opts[:max]
1208
+ count = opts[:min]
1209
+ elsif opts[:max] == 0
1210
+ count = 0
1211
+ end
1212
+ if count
1213
+ if args.count < count
1214
+ raise_args_error("not enough arguments, expected #{count} and got #{args.count == 0 ? '0' : args.count.to_s + ': '}#{args.join(', ')}", args, opts[:optparse])
1215
+ elsif args.count > count
1216
+ raise_args_error("too many arguments, expected #{count} and got #{args.count == 0 ? '0' : args.count.to_s + ': '}#{args.join(', ')}", args, opts[:optparse])
1210
1217
  end
1211
1218
  else
1212
1219
  if opts[:min]
@@ -77,14 +77,26 @@ module Morpheus
77
77
 
78
78
  def exec_command(command_name, args)
79
79
  #puts "exec_command(#{command_name}, #{args})"
80
- found_alias_command = instance.get_alias(command_name)
81
80
  if has_alias?(command_name)
82
81
  exec_alias(command_name, args)
83
82
  elsif has_command?(command_name)
84
83
  instance.get(command_name).new.handle(args)
85
84
  else
86
85
  # todo: need to just return error instead of raise
87
- raise CommandNotFoundError.new("'#{command_name}' is not a morpheus command.")
86
+ msg = "'#{command_name}' is not a morpheus command."
87
+ suggestions = find_command_suggestions(command_name)
88
+ if suggestions && suggestions.size == 1
89
+ msg += "\nThe most similar command is:\n"
90
+ suggestions.first(5).each do |suggestion|
91
+ msg += "\t" + suggestion + "\n"
92
+ end
93
+ elsif suggestions && suggestions.size > 1
94
+ msg += "\nThe most similar commands are:\n"
95
+ suggestions.first(5).each do |suggestion|
96
+ msg += "\t" + suggestion + "\n"
97
+ end
98
+ end
99
+ raise CommandNotFoundError.new(msg)
88
100
  end
89
101
  end
90
102
 
@@ -269,6 +281,47 @@ module Morpheus
269
281
  return exit_code, err
270
282
  end
271
283
 
284
+ def cached_command_list
285
+ @cached_command_list ||= (all.keys + all_aliases.keys).collect { |it| it.to_s }.sort
286
+ end
287
+
288
+ def clear_cached_command_list
289
+ @cached_command_list = nil
290
+ end
291
+
292
+ # find suggested commands (or aliases) for a name that was not found
293
+ # First this looks for the plural of the original guess
294
+ # Then pop characters off the end looking for partial matches
295
+ # as long as the guess is at least 3 characters
296
+ def find_command_suggestions(command_name)
297
+ every_command = cached_command_list
298
+ guess = command_name
299
+ suggestions = []
300
+ while guess.size >= 3
301
+ plural_guess = guess.pluralize
302
+ if every_command.include?(guess)
303
+ suggestions << guess
304
+ end
305
+ if every_command.include?(plural_guess)
306
+ suggestions << plural_guess
307
+ end
308
+ # if every_command.include?(guess)
309
+ # suggestions << plural_guess
310
+ # else
311
+ guess_regexp = /^#{Regexp.escape(guess)}/i
312
+ every_command.each do |it|
313
+ if it =~ guess_regexp
314
+ suggestions << it
315
+ end
316
+ end
317
+ # end
318
+ guess = guess[0..-2]
319
+ end
320
+ suggestions.uniq!
321
+ suggestions.sort! { |x,y| [x.split('-').size, x] <=> [y.split('-').size, y] }
322
+ return suggestions
323
+ end
324
+
272
325
  end
273
326
 
274
327
  end
@@ -7,6 +7,7 @@ require 'morpheus/cli/mixins/infrastructure_helper'
7
7
  class Morpheus::Cli::CloudResourcePoolsCommand
8
8
  include Morpheus::Cli::CliCommand
9
9
  include Morpheus::Cli::InfrastructureHelper
10
+ include Morpheus::Cli::OptionSourceHelper
10
11
 
11
12
  #set_command_name :'cloud-resource-pools'
12
13
  set_command_name :'resource-pools'
@@ -191,6 +192,12 @@ class Morpheus::Cli::CloudResourcePoolsCommand
191
192
  "Status" => lambda {|it| it['status'].to_s.capitalize },
192
193
  "Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|it| it['name'] }.uniq.join(', ') : '' }
193
194
  }
195
+
196
+ if cloud['zoneType']['code'] == 'openstack'
197
+ role = resource_pool['config']['roleId'] ? load_option_source_data('openstackRoles', {zoneId: cloud['id']}).find {|it| it['value'] == resource_pool['config']['roleId']} : nil
198
+ description_cols['Role'] = lambda {|it| role ? role['name'] : ''}
199
+ end
200
+
194
201
  print_description_list(description_cols, resource_pool)
195
202
 
196
203
  if resource_pool['resourcePermission'].nil?
@@ -329,8 +336,14 @@ class Morpheus::Cli::CloudResourcePoolsCommand
329
336
  opts.on('--default-pool [on|off]', String, "Set resource pool as the default") do |val|
330
337
  options['defaultPool'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
331
338
  end
332
- build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
333
- opts.footer = "Update a resource pool." + "\n" +
339
+ opts.on("--description [TEXT]", String, "Description") do |val|
340
+ options['description'] = val.to_s
341
+ end
342
+ opts.on( '--role ROLE', String, "Role Name or ID (applicable to select resource pools)" ) do |val|
343
+ options[:role] = val
344
+ end
345
+ build_standard_add_options(opts, options)
346
+ opts.footer = "Add a resource pool." + "\n" +
334
347
  "[cloud] is required. This is the name or id of the cloud."
335
348
  end
336
349
  optparse.parse!(args)
@@ -349,151 +362,156 @@ class Morpheus::Cli::CloudResourcePoolsCommand
349
362
 
350
363
  connect(options)
351
364
 
352
- begin
353
- # load cloud
354
- if cloud_id.nil?
355
- puts_error "#{Morpheus::Terminal.angry_prompt}missing required option: [cloud]\n#{optparse}"
356
- return 1
357
- end
358
- cloud = find_cloud_by_name_or_id(cloud_id)
359
- return 1 if cloud.nil?
360
-
361
- # merge -O options into normally parsed options
362
- options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
365
+ # load cloud
366
+ if cloud_id.nil?
367
+ puts_error "#{Morpheus::Terminal.angry_prompt}missing required option: [cloud]\n#{optparse}"
368
+ return 1
369
+ end
370
+ cloud = find_cloud_by_name_or_id(cloud_id)
371
+ return 1 if cloud.nil?
363
372
 
364
- # construct payload
365
- payload = nil
366
- if options[:payload]
367
- payload = options[:payload]
368
- else
369
- # prompt for resource pool options
370
- payload = {
371
- 'resourcePool' => {
372
- }
373
+ # merge -O options into normally parsed options
374
+ options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
375
+
376
+ # construct payload
377
+ payload = nil
378
+ if options[:payload]
379
+ payload = options[:payload]
380
+ else
381
+ # prompt for resource pool options
382
+ payload = {
383
+ 'resourcePool' => {
373
384
  }
374
-
375
- # allow arbitrary -O options
376
- payload['resourcePool'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
385
+ }
377
386
 
387
+ # allow arbitrary -O options
388
+ payload['resourcePool'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
378
389
 
379
- # Name
380
- if options['name']
381
- payload['resourcePool']['name'] = options['name']
382
- else
383
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name'}], options)
384
- payload['resourcePool']['name'] = v_prompt['name']
385
- end
390
+ # Name
391
+ if options['name']
392
+ payload['resourcePool']['name'] = options['name']
393
+ else
394
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name'}], options)
395
+ payload['resourcePool']['name'] = v_prompt['name']
396
+ end
386
397
 
387
- # Group Access
388
- if group_access_all != nil
398
+ # Group Access
399
+ if group_access_all != nil
400
+ payload['resourcePermissions'] ||= {}
401
+ payload['resourcePermissions']['all'] = group_access_all
402
+ else
403
+ # default to all
404
+ if payload['resourcePermissions'].nil? || payload['resourcePermissions']['all'].nil?
389
405
  payload['resourcePermissions'] ||= {}
390
- payload['resourcePermissions']['all'] = group_access_all
391
- else
392
- # default to all
393
- if payload['resourcePermissions'].nil? || payload['resourcePermissions']['all'].nil?
394
- payload['resourcePermissions'] ||= {}
395
- payload['resourcePermissions']['all'] = true
396
- end
406
+ payload['resourcePermissions']['all'] = true
397
407
  end
398
- if group_access_list != nil
399
- payload['resourcePermissions'] ||= {}
400
- payload['resourcePermissions']['sites'] = group_access_list.collect do |site_id|
401
- site = {"id" => site_id.to_i}
402
- if group_defaults_list && group_defaults_list.include?(site_id)
403
- site["default"] = true
404
- end
405
- site
408
+ end
409
+ if group_access_list != nil
410
+ payload['resourcePermissions'] ||= {}
411
+ payload['resourcePermissions']['sites'] = group_access_list.collect do |site_id|
412
+ site = {"id" => site_id.to_i}
413
+ if group_defaults_list && group_defaults_list.include?(site_id)
414
+ site["default"] = true
406
415
  end
416
+ site
407
417
  end
418
+ end
408
419
 
409
- # Service Plan Access
410
- if plan_access_all != nil
420
+ # Service Plan Access
421
+ if plan_access_all != nil
422
+ payload['resourcePermissions'] ||= {}
423
+ payload['resourcePermissions']['allPlans'] = plan_access_all
424
+ else
425
+ # default to all
426
+ if payload['resourcePermissions'].nil? || payload['resourcePermissions']['allPlans'].nil?
411
427
  payload['resourcePermissions'] ||= {}
412
- payload['resourcePermissions']['allPlans'] = plan_access_all
413
- else
414
- # default to all
415
- if payload['resourcePermissions'].nil? || payload['resourcePermissions']['allPlans'].nil?
416
- payload['resourcePermissions'] ||= {}
417
- payload['resourcePermissions']['allPlans'] = true
418
- end
428
+ payload['resourcePermissions']['allPlans'] = true
419
429
  end
420
- if plan_access_list != nil
421
- payload['resourcePermissions'] ||= {}
422
- payload['resourcePermissions']['plans'] = plan_access_list.collect do |site_id|
423
- site = {"id" => site_id.to_i}
424
- if plan_defaults_list && plan_defaults_list.include?(site_id)
425
- site["default"] = true
426
- end
427
- site
430
+ end
431
+ if plan_access_list != nil
432
+ payload['resourcePermissions'] ||= {}
433
+ payload['resourcePermissions']['plans'] = plan_access_list.collect do |site_id|
434
+ site = {"id" => site_id.to_i}
435
+ if plan_defaults_list && plan_defaults_list.include?(site_id)
436
+ site["default"] = true
428
437
  end
438
+ site
429
439
  end
440
+ end
430
441
 
431
- # Tenants
432
- if options['tenants']
433
- payload['tenantPermissions'] = {}
434
- payload['tenantPermissions']['accounts'] = options['tenants']
435
- end
436
-
437
- # Active
438
- if options['active'] != nil
439
- payload['resourcePool']['active'] = options['active']
440
- else
441
- payload['resourcePool']['active'] = true
442
- end
442
+ # Tenants
443
+ if options['tenants']
444
+ payload['tenantPermissions'] = {}
445
+ payload['tenantPermissions']['accounts'] = options['tenants']
446
+ end
443
447
 
444
- # Default
445
- if options['defaultPool'] != nil
446
- payload['resourcePool']['defaultPool'] = options['defaultPool']
447
- end
448
-
449
- # Visibility
450
- if options['visibility'] != nil
451
- payload['resourcePool']['visibility'] = options['visibility']
452
- else
453
- payload['resourcePool']['visibility'] = 'private'
454
- end
455
-
456
-
457
- # Config options depend on type (until api returns these as optionTypes)
458
- zone_type = cloud['zoneType'] ? cloud['zoneType']['code'] : ''
459
- if zone_type == 'amazon'
460
- payload['resourcePool']['config'] ||= {}
461
- # CIDR
462
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'config', 'fieldName' => 'cidrBlock', 'fieldLabel' => 'CIDR', 'type' => 'text', 'required' => true, 'description' => 'Provide the base CIDR Block to use for this VPC (must be between a /16 and /28 Block)'}], options)
463
- payload['resourcePool']['config']['cidrBlock'] = v_prompt['config']['cidrBlock']
464
- # Tenancy
465
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'config', 'fieldName' => 'tenancy', 'fieldLabel' => 'Tenancy', 'type' => 'select', 'selectOptions' => [{'name' => 'Default', 'value' => 'default'}, {'name' => 'Dedicated', 'value' => 'dedicated'}], 'defaultValue' => 'default'}], options)
466
- payload['resourcePool']['config']['tenancy'] = v_prompt['config']['tenancy']
467
-
468
- elsif zone_type == 'azure'
469
- # no options
470
- elsif zone_type == 'cloudFoundry' || zone_type == 'bluemixCloudFoundry'
471
-
472
- elsif zone_type == 'standard'
473
- # no options
474
- else
475
- #raise_command_error "Cloud type '#{zone_type}' does not allow creating resource pools"
476
- end
448
+ # Active
449
+ if options['active'] != nil
450
+ payload['resourcePool']['active'] = options['active']
451
+ else
452
+ payload['resourcePool']['active'] = true
453
+ end
477
454
 
455
+ # Default
456
+ if options['defaultPool'] != nil
457
+ payload['resourcePool']['defaultPool'] = options['defaultPool']
478
458
  end
479
- @cloud_resource_pools_interface.setopts(options)
480
- if options[:dry_run]
481
- print_dry_run @cloud_resource_pools_interface.dry.create(cloud['id'], payload)
482
- return
459
+
460
+ # Visibility
461
+ if options['visibility'] != nil
462
+ payload['resourcePool']['visibility'] = options['visibility']
463
+ else
464
+ payload['resourcePool']['visibility'] = 'private'
483
465
  end
484
- json_response = @cloud_resource_pools_interface.create(cloud['id'], payload)
485
- if options[:json]
486
- puts as_json(json_response)
466
+
467
+
468
+ # Config options depend on type (until api returns these as optionTypes)
469
+ zone_type = cloud['zoneType'] ? cloud['zoneType']['code'] : ''
470
+ if zone_type == 'amazon'
471
+ payload['resourcePool']['config'] ||= {}
472
+ # CIDR
473
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'config', 'fieldName' => 'cidrBlock', 'fieldLabel' => 'CIDR', 'type' => 'text', 'required' => true, 'description' => 'Provide the base CIDR Block to use for this VPC (must be between a /16 and /28 Block)'}], options)
474
+ payload['resourcePool']['config']['cidrBlock'] = v_prompt['config']['cidrBlock']
475
+ # Tenancy
476
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'config', 'fieldName' => 'tenancy', 'fieldLabel' => 'Tenancy', 'type' => 'select', 'selectOptions' => [{'name' => 'Default', 'value' => 'default'}, {'name' => 'Dedicated', 'value' => 'dedicated'}], 'defaultValue' => 'default'}], options)
477
+ payload['resourcePool']['config']['tenancy'] = v_prompt['config']['tenancy']
478
+
479
+ elsif zone_type == 'azure'
480
+ # no options
481
+ elsif zone_type == 'cloudFoundry' || zone_type == 'bluemixCloudFoundry'
482
+
483
+ elsif zone_type == 'openstack'
484
+ payload['resourcePool']['config'] ||= {}
485
+ # Description
486
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text'}], options)
487
+ payload['resourcePool']['description'] = v_prompt['description']
488
+ # Role
489
+ role_options = load_option_source_data('openstackRoles', {zoneId: cloud['id']})
490
+ if role = options[:role] ? role_options.find {|it| [it['name'], it['value']].include?(options[:role])} : nil
491
+ payload['resourcePool']['config']['roleId'] = role['value']
492
+ else
493
+ v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'config', 'fieldName' => 'roleId', 'fieldLabel' => 'Role', 'type' => 'select', 'selectOptions' => role_options, 'required' => true}], options, @api_client,{zoneId: cloud['id']})
494
+ payload['resourcePool']['config']['roleId'] = v_prompt['config']['roleId']
495
+ end
496
+ elsif zone_type == 'standard'
497
+ # no options
487
498
  else
488
- resource_pool = json_response['resourcePool']
489
- print_green_success "Created resource pool #{resource_pool['name']}"
490
- get([cloud['id'].to_s, resource_pool['id'].to_s])
499
+ #raise_command_error "Cloud type '#{zone_type}' does not allow creating resource pools"
491
500
  end
492
- return 0
493
- rescue RestClient::Exception => e
494
- print_rest_exception(e, options)
495
- return 1
496
501
  end
502
+
503
+ @cloud_resource_pools_interface.setopts(options)
504
+ if options[:dry_run]
505
+ print_dry_run @cloud_resource_pools_interface.dry.create(cloud['id'], payload)
506
+ return
507
+ end
508
+ json_response = @cloud_resource_pools_interface.create(cloud['id'], payload)
509
+ render_response(json_response, options, 'resourcePool') do
510
+ resource_pool = json_response['resourcePool']
511
+ print_green_success "Created resource pool #{resource_pool['name']}"
512
+ get([cloud['id'].to_s, resource_pool['id'].to_s])
513
+ end
514
+ return 0, nil
497
515
  end
498
516
 
499
517
  def update(args)
@@ -563,6 +581,12 @@ class Morpheus::Cli::CloudResourcePoolsCommand
563
581
  opts.on('--default-pool [on|off]', String, "Set resource pool as the default") do |val|
564
582
  options['defaultPool'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
565
583
  end
584
+ opts.on("--description [TEXT]", String, "Description") do |val|
585
+ options['description'] = val.to_s
586
+ end
587
+ opts.on( '--role ROLE', String, "Role Name or ID (applicable to select resource pools)" ) do |val|
588
+ options['role'] = val
589
+ end
566
590
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
567
591
  opts.footer = "Update a resource pool." + "\n" +
568
592
  "[cloud] is required. This is the name or id of the cloud." + "\n"
@@ -591,7 +615,7 @@ class Morpheus::Cli::CloudResourcePoolsCommand
591
615
 
592
616
  resource_pool = find_resource_pool_by_name_or_id(cloud['id'], resource_pool_id)
593
617
  return 1 if resource_pool.nil?
594
-
618
+
595
619
  # merge -O options into normally parsed options
596
620
  options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
597
621
 
@@ -605,11 +629,11 @@ class Morpheus::Cli::CloudResourcePoolsCommand
605
629
  'resourcePool' => {
606
630
  }
607
631
  }
608
-
632
+
609
633
  # allow arbitrary -O options
610
634
  payload['resourcePool'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
611
635
 
612
-
636
+
613
637
  # Group Access
614
638
  if group_access_all != nil
615
639
  payload['resourcePermissions'] ||= {}
@@ -657,12 +681,26 @@ class Morpheus::Cli::CloudResourcePoolsCommand
657
681
  if options['defaultPool'] != nil
658
682
  payload['resourcePool']['defaultPool'] = options['defaultPool']
659
683
  end
660
-
684
+
661
685
  # Visibility
662
686
  if options['visibility'] != nil
663
687
  payload['resourcePool']['visibility'] = options['visibility']
664
688
  end
665
689
 
690
+ # Description
691
+ if options['description'] != nil
692
+ payload['resourcePool']['description'] = options['description']
693
+ end
694
+
695
+ # Role
696
+ if options['role'] != nil
697
+ role_options = load_option_source_data('openstackRoles', {zoneId: cloud['id']})
698
+ if role = role_options.find {|it| [it['name'], it['value']].include?(options['role'])}
699
+ payload['resourcePool']['config'] ||= {}
700
+ payload['resourcePool']['config']['roleId'] = role['value']
701
+ end
702
+ end
703
+
666
704
  if payload['resourcePool'].empty? && payload['resourcePermissions'].nil? && payload['tenantPermissions'].nil?
667
705
  raise_command_error "Specify at least one option to update.\n#{optparse}"
668
706
  end
@@ -674,14 +712,12 @@ class Morpheus::Cli::CloudResourcePoolsCommand
674
712
  return
675
713
  end
676
714
  json_response = @cloud_resource_pools_interface.update(cloud['id'], resource_pool["id"], payload)
677
- if options[:json]
678
- puts as_json(json_response)
679
- else
715
+ render_response(json_response, options, 'resourcePool') do
680
716
  resource_pool = json_response['resourcePool']
681
717
  print_green_success "Updated resource pool #{resource_pool['name']}"
682
718
  get([cloud['id'].to_s, resource_pool['id'].to_s])
683
719
  end
684
- return 0
720
+ return 0, nil
685
721
  rescue RestClient::Exception => e
686
722
  print_rest_exception(e, options)
687
723
  return 1