morpheus-cli 5.3.2.1 → 5.3.4
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 +12 -0
- data/lib/morpheus/api/clouds_interface.rb +4 -11
- data/lib/morpheus/api/instances_interface.rb +18 -5
- data/lib/morpheus/api/load_balancer_pools_interface.rb +4 -4
- data/lib/morpheus/api/load_balancer_profiles_interface.rb +10 -0
- data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +4 -4
- data/lib/morpheus/api/network_routers_interface.rb +21 -0
- data/lib/morpheus/api/network_servers_interface.rb +42 -0
- data/lib/morpheus/api/rest_interface.rb +2 -1
- data/lib/morpheus/api/virtual_images_interface.rb +23 -2
- data/lib/morpheus/api/virtual_servers_interface.rb +9 -0
- data/lib/morpheus/cli/apps.rb +3 -2
- data/lib/morpheus/cli/cli_command.rb +14 -6
- data/lib/morpheus/cli/cli_registry.rb +55 -2
- data/lib/morpheus/cli/cloud_resource_pools_command.rb +170 -134
- data/lib/morpheus/cli/clouds.rb +22 -40
- data/lib/morpheus/cli/clusters.rb +51 -33
- data/lib/morpheus/cli/hosts.rb +0 -1
- data/lib/morpheus/cli/instances.rb +372 -150
- data/lib/morpheus/cli/invoices_command.rb +117 -133
- data/lib/morpheus/cli/library_cluster_layouts_command.rb +20 -0
- data/lib/morpheus/cli/library_option_lists_command.rb +3 -3
- data/lib/morpheus/cli/load_balancer_pools.rb +111 -0
- data/lib/morpheus/cli/load_balancer_virtual_servers.rb +136 -0
- data/lib/morpheus/cli/load_balancers.rb +0 -155
- data/lib/morpheus/cli/mixins/load_balancers_helper.rb +2 -2
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +155 -112
- data/lib/morpheus/cli/mixins/rest_command.rb +53 -37
- data/lib/morpheus/cli/mixins/secondary_rest_command.rb +488 -0
- data/lib/morpheus/cli/monitoring_checks_command.rb +2 -0
- data/lib/morpheus/cli/network_routers_command.rb +291 -7
- data/lib/morpheus/cli/network_scopes_command.rb +442 -0
- data/lib/morpheus/cli/networks_command.rb +3 -3
- data/lib/morpheus/cli/option_parser.rb +25 -17
- data/lib/morpheus/cli/option_types.rb +42 -15
- data/lib/morpheus/cli/subnets_command.rb +7 -2
- data/lib/morpheus/cli/tasks.rb +25 -2
- data/lib/morpheus/cli/vdi_pools_command.rb +4 -1
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +251 -29
- data/lib/morpheus/cli.rb +9 -1
- data/morpheus-cli.gemspec +1 -1
- metadata +11 -4
@@ -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
|
-
|
333
|
-
|
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
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
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
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
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
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
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
|
-
|
388
|
-
|
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'] =
|
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
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
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
|
-
|
410
|
-
|
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'] =
|
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
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
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
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
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
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
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
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
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
|
-
|
485
|
-
|
486
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -783,7 +819,7 @@ class Morpheus::Cli::CloudResourcePoolsCommand
|
|
783
819
|
print_red_alert "Resource Pool not found by name #{name}"
|
784
820
|
return nil
|
785
821
|
elsif resource_pools.size > 1
|
786
|
-
matching_resource_pools =
|
822
|
+
matching_resource_pools = resource_pools.select { |it| name && (it['name'] == name || it['externalId'] == name) }
|
787
823
|
if matching_resource_pools.size == 1
|
788
824
|
return matching_resource_pools[0]
|
789
825
|
end
|
data/lib/morpheus/cli/clouds.rb
CHANGED
@@ -27,8 +27,6 @@ class Morpheus::Cli::Clouds
|
|
27
27
|
@clouds_interface = @api_client.clouds
|
28
28
|
@groups_interface = @api_client.groups
|
29
29
|
@active_group_id = Morpheus::Cli::Groups.active_groups[@appliance_name]
|
30
|
-
# preload stuff
|
31
|
-
get_available_cloud_types()
|
32
30
|
end
|
33
31
|
|
34
32
|
def handle(args)
|
@@ -134,38 +132,36 @@ class Morpheus::Cli::Clouds
|
|
134
132
|
|
135
133
|
def get(args)
|
136
134
|
options = {}
|
135
|
+
params = {}
|
137
136
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
138
137
|
opts.banner = subcommand_usage("[name]")
|
139
|
-
|
138
|
+
build_standard_list_options(opts, options)
|
140
139
|
opts.footer = "Get details about a cloud.\n" +
|
141
140
|
"[name] is required. This is the name or id of a cloud."
|
142
141
|
end
|
143
142
|
optparse.parse!(args)
|
144
|
-
|
145
|
-
puts optparse
|
146
|
-
exit 1
|
147
|
-
end
|
143
|
+
verify_args!(args:args, optparse:optparse, min:1)
|
148
144
|
connect(options)
|
145
|
+
params.merge!(parse_query_options(options))
|
149
146
|
id_list = parse_id_list(args)
|
150
147
|
return run_command_for_each_arg(id_list) do |arg|
|
151
|
-
_get(arg, options)
|
148
|
+
_get(arg, params, options)
|
152
149
|
end
|
153
150
|
end
|
154
151
|
|
155
|
-
def _get(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
json_response = @clouds_interface.get(cloud['id'])
|
152
|
+
def _get(id, params, options={})
|
153
|
+
cloud = nil
|
154
|
+
if id.to_s !~ /\A\d{1,}\Z/
|
155
|
+
cloud = find_cloud_by_name_or_id(id)
|
156
|
+
id = cloud['id']
|
157
|
+
end
|
158
|
+
@clouds_interface.setopts(options)
|
159
|
+
if options[:dry_run]
|
160
|
+
print_dry_run @clouds_interface.dry.get(id.to_i, params)
|
161
|
+
return
|
162
|
+
end
|
163
|
+
json_response = @clouds_interface.get(id, params)
|
164
|
+
render_response(json_response, options, 'zone') do
|
169
165
|
cloud = json_response['zone']
|
170
166
|
cloud_stats = cloud['stats']
|
171
167
|
# serverCounts moved to zone.stats.serverCounts
|
@@ -175,17 +171,6 @@ class Morpheus::Cli::Clouds
|
|
175
171
|
else
|
176
172
|
server_counts = json_response['serverCounts'] # legacy
|
177
173
|
end
|
178
|
-
if options[:json]
|
179
|
-
puts as_json(json_response, options, 'zone')
|
180
|
-
return 0
|
181
|
-
elsif options[:yaml]
|
182
|
-
puts as_yaml(json_response, options, 'zone')
|
183
|
-
return 0
|
184
|
-
end
|
185
|
-
if options[:csv]
|
186
|
-
puts records_as_csv([json_response['zone']], options)
|
187
|
-
return 0
|
188
|
-
end
|
189
174
|
cloud_type = cloud_type_for_id(cloud['zoneTypeId'])
|
190
175
|
print_h1 "Cloud Details"
|
191
176
|
print cyan
|
@@ -195,6 +180,7 @@ class Morpheus::Cli::Clouds
|
|
195
180
|
"Type" => lambda {|it| cloud_type ? cloud_type['name'] : '' },
|
196
181
|
"Code" => 'code',
|
197
182
|
"Location" => 'location',
|
183
|
+
"Region Code" => 'regionCode',
|
198
184
|
"Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
|
199
185
|
"Groups" => lambda {|it| it['groups'].collect {|g| g.instance_of?(Hash) ? g['name'] : g.to_s }.join(', ') },
|
200
186
|
#"Owner" => lambda {|it| it['owner'].instance_of?(Hash) ? it['owner']['name'] : it['ownerId'] },
|
@@ -214,14 +200,9 @@ class Morpheus::Cli::Clouds
|
|
214
200
|
print "Unmanaged: #{server_counts['unmanaged']}".center(20)
|
215
201
|
print "\n"
|
216
202
|
end
|
217
|
-
|
218
203
|
print reset,"\n"
|
219
|
-
|
220
|
-
#puts instance
|
221
|
-
rescue RestClient::Exception => e
|
222
|
-
print_rest_exception(e, options)
|
223
|
-
exit 1
|
224
204
|
end
|
205
|
+
return 0, nil
|
225
206
|
end
|
226
207
|
|
227
208
|
def add(args)
|
@@ -954,13 +935,14 @@ class Morpheus::Cli::Clouds
|
|
954
935
|
name: cloud['name'],
|
955
936
|
type: cloud_type ? cloud_type['name'] : '',
|
956
937
|
location: cloud['location'],
|
938
|
+
"REGION CODE": cloud['regionCode'],
|
957
939
|
groups: (cloud['groups'] || []).collect {|it| it.instance_of?(Hash) ? it['name'] : it.to_s }.join(', '),
|
958
940
|
servers: cloud['serverCount'],
|
959
941
|
status: format_cloud_status(cloud)
|
960
942
|
}
|
961
943
|
end
|
962
944
|
columns = [
|
963
|
-
:id, :name, :type, :location, :groups, :servers, :status
|
945
|
+
:id, :name, :type, :location, "REGION CODE", :groups, :servers, :status
|
964
946
|
]
|
965
947
|
print as_pretty_table(rows, columns, opts)
|
966
948
|
end
|