morpheus-cli 5.3.4 → 5.4.3
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/account_users_interface.rb +68 -0
- data/lib/morpheus/api/api_client.rb +69 -11
- data/lib/morpheus/api/audit_interface.rb +9 -0
- data/lib/morpheus/api/catalog_item_types_interface.rb +20 -0
- data/lib/morpheus/api/health_interface.rb +37 -3
- data/lib/morpheus/api/instances_interface.rb +49 -0
- data/lib/morpheus/api/load_balancer_monitors_interface.rb +9 -0
- data/lib/morpheus/api/load_balancer_pools_interface.rb +4 -4
- data/lib/morpheus/api/load_balancer_profiles_interface.rb +4 -5
- data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +13 -4
- data/lib/morpheus/api/load_balancers_interface.rb +5 -0
- data/lib/morpheus/api/network_dhcp_relays_interface.rb +36 -0
- data/lib/morpheus/api/network_dhcp_servers_interface.rb +36 -0
- data/lib/morpheus/api/network_edge_clusters_interface.rb +26 -0
- data/lib/morpheus/api/network_routers_interface.rb +9 -0
- data/lib/morpheus/api/network_servers_interface.rb +68 -12
- data/lib/morpheus/api/network_static_routes_interface.rb +36 -0
- data/lib/morpheus/api/ping_interface.rb +2 -0
- data/lib/morpheus/api/read_interface.rb +4 -3
- data/lib/morpheus/api/rest_interface.rb +3 -3
- data/lib/morpheus/api/roles_interface.rb +7 -0
- data/lib/morpheus/api/secondary_read_interface.rb +1 -1
- data/lib/morpheus/api/secondary_rest_interface.rb +19 -19
- data/lib/morpheus/api/setup_interface.rb +4 -0
- data/lib/morpheus/api/snapshots_interface.rb +19 -0
- data/lib/morpheus/api/storage_server_types_interface.rb +14 -0
- data/lib/morpheus/api/storage_servers_interface.rb +9 -0
- data/lib/morpheus/api/storage_volume_types_interface.rb +9 -0
- data/lib/morpheus/api/storage_volumes_interface.rb +9 -0
- data/lib/morpheus/api/users_interface.rb +16 -63
- data/lib/morpheus/cli/cli_command.rb +260 -13
- data/lib/morpheus/cli/cli_registry.rb +2 -1
- data/lib/morpheus/cli/{access_token_command.rb → commands/access_token_command.rb} +1 -1
- data/lib/morpheus/cli/{account_groups_command.rb → commands/account_groups_command.rb} +0 -8
- data/lib/morpheus/cli/{activity_command.rb → commands/activity_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/alias_command.rb → alias_command.rb} +1 -4
- data/lib/morpheus/cli/{appliance_settings_command.rb → commands/appliance_settings_command.rb} +0 -0
- data/lib/morpheus/cli/{approvals_command.rb → commands/approvals_command.rb} +0 -0
- data/lib/morpheus/cli/{apps.rb → commands/apps.rb} +14 -87
- data/lib/morpheus/cli/{archives_command.rb → commands/archives_command.rb} +0 -6
- data/lib/morpheus/cli/commands/audit.rb +188 -0
- data/lib/morpheus/cli/{backup_jobs_command.rb → commands/backup_jobs_command.rb} +0 -0
- data/lib/morpheus/cli/{backup_settings_command.rb → commands/backup_settings_command.rb} +0 -0
- data/lib/morpheus/cli/{backups_command.rb → commands/backups_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/benchmark_command.rb → benchmark_command.rb} +0 -3
- data/lib/morpheus/cli/{blueprints_command.rb → commands/blueprints_command.rb} +1 -1
- data/lib/morpheus/cli/{boot_scripts_command.rb → commands/boot_scripts_command.rb} +0 -3
- data/lib/morpheus/cli/{budgets_command.rb → commands/budgets_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/cat_command.rb → cat_command.rb} +0 -0
- data/lib/morpheus/cli/{catalog_item_types_command.rb → commands/catalog_item_types_command.rb} +88 -0
- data/lib/morpheus/cli/{certificates_command.rb → commands/certificates_command.rb} +0 -0
- data/lib/morpheus/cli/commands/change_password_command.rb +132 -0
- data/lib/morpheus/cli/{cloud_datastores_command.rb → commands/cloud_datastores_command.rb} +0 -4
- data/lib/morpheus/cli/{cloud_folders_command.rb → commands/cloud_folders_command.rb} +0 -4
- data/lib/morpheus/cli/{cloud_resource_pools_command.rb → commands/cloud_resource_pools_command.rb} +0 -4
- data/lib/morpheus/cli/{clouds.rb → commands/clouds.rb} +0 -7
- data/lib/morpheus/cli/{clusters.rb → commands/clusters.rb} +96 -64
- data/lib/morpheus/cli/commands/{standard/coloring_command.rb → coloring_command.rb} +0 -2
- data/lib/morpheus/cli/{containers_command.rb → commands/containers_command.rb} +0 -7
- data/lib/morpheus/cli/commands/{standard/curl_command.rb → curl_command.rb} +0 -3
- data/lib/morpheus/cli/{cypher_command.rb → commands/cypher_command.rb} +0 -1
- data/lib/morpheus/cli/{dashboard_command.rb → commands/dashboard_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/debug_command.rb → debug_command.rb} +0 -1
- data/lib/morpheus/cli/{deploy.rb → commands/deploy.rb} +0 -1
- data/lib/morpheus/cli/{deployments.rb → commands/deployments.rb} +0 -0
- data/lib/morpheus/cli/{deploys.rb → commands/deploys.rb} +0 -1
- data/lib/morpheus/cli/{doc.rb → commands/doc.rb} +1 -1
- data/lib/morpheus/cli/commands/{standard/echo_command.rb → echo_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/edit_profile_command.rb → edit_profile_command.rb} +15 -4
- data/lib/morpheus/cli/commands/{standard/edit_rc_command.rb → edit_rc_command.rb} +19 -3
- data/lib/morpheus/cli/{environments_command.rb → commands/environments_command.rb} +0 -5
- data/lib/morpheus/cli/{execute_schedules_command.rb → commands/execute_schedules_command.rb} +0 -0
- data/lib/morpheus/cli/{execution_request_command.rb → commands/execution_request_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/exit_command.rb → exit_command.rb} +0 -2
- data/lib/morpheus/cli/{file_copy_request_command.rb → commands/file_copy_request_command.rb} +0 -4
- data/lib/morpheus/cli/{forgot_password.rb → commands/forgot_password.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/get_prompt_command.rb → get_prompt_command.rb} +0 -3
- data/lib/morpheus/cli/{groups.rb → commands/groups.rb} +0 -7
- data/lib/morpheus/cli/{guidance_command.rb → commands/guidance_command.rb} +1 -1
- data/lib/morpheus/cli/{health_command.rb → commands/health_command.rb} +104 -19
- data/lib/morpheus/cli/commands/{standard/history_command.rb → history_command.rb} +0 -3
- data/lib/morpheus/cli/{hosts.rb → commands/hosts.rb} +27 -24
- data/lib/morpheus/cli/{image_builder_command.rb → commands/image_builder_command.rb} +6 -16
- data/lib/morpheus/cli/{instance_types.rb → commands/instance_types.rb} +0 -3
- data/lib/morpheus/cli/{instances.rb → commands/instances.rb} +359 -7
- data/lib/morpheus/cli/{integrations_command.rb → commands/integrations_command.rb} +1 -12
- data/lib/morpheus/cli/{invoices_command.rb → commands/invoices_command.rb} +1 -1
- data/lib/morpheus/cli/{jobs_command.rb → commands/jobs_command.rb} +0 -0
- data/lib/morpheus/cli/{key_pairs.rb → commands/key_pairs.rb} +0 -6
- data/lib/morpheus/cli/{library_cluster_layouts_command.rb → commands/library_cluster_layouts_command.rb} +0 -4
- data/lib/morpheus/cli/{library_container_scripts_command.rb → commands/library_container_scripts_command.rb} +0 -0
- data/lib/morpheus/cli/{library_container_templates_command.rb → commands/library_container_templates_command.rb} +0 -1
- data/lib/morpheus/cli/{library_container_types_command.rb → commands/library_container_types_command.rb} +0 -4
- data/lib/morpheus/cli/{library_instance_types_command.rb → commands/library_instance_types_command.rb} +3 -4
- data/lib/morpheus/cli/{library_layouts_command.rb → commands/library_layouts_command.rb} +0 -4
- data/lib/morpheus/cli/{library_option_lists_command.rb → commands/library_option_lists_command.rb} +0 -4
- data/lib/morpheus/cli/{library_option_types_command.rb → commands/library_option_types_command.rb} +0 -4
- data/lib/morpheus/cli/{library_spec_templates_command.rb → commands/library_spec_templates_command.rb} +0 -1
- data/lib/morpheus/cli/{library_upgrades_command.rb → commands/library_upgrades_command.rb} +0 -4
- data/lib/morpheus/cli/{license.rb → commands/license.rb} +0 -3
- data/lib/morpheus/cli/commands/load_balancer_monitors.rb +70 -0
- data/lib/morpheus/cli/commands/load_balancer_pools.rb +90 -0
- data/lib/morpheus/cli/commands/load_balancer_profiles.rb +64 -0
- data/lib/morpheus/cli/{load_balancer_types.rb → commands/load_balancer_types.rb} +9 -8
- data/lib/morpheus/cli/{load_balancer_virtual_servers.rb → commands/load_balancer_virtual_servers.rb} +69 -58
- data/lib/morpheus/cli/commands/load_balancers.rb +192 -0
- data/lib/morpheus/cli/commands/{standard/log_level_command.rb → log_level_command.rb} +0 -3
- data/lib/morpheus/cli/{log_settings_command.rb → commands/log_settings_command.rb} +0 -0
- data/lib/morpheus/cli/{login.rb → commands/login.rb} +0 -5
- data/lib/morpheus/cli/commands/logout.rb +63 -0
- data/lib/morpheus/cli/{logs_command.rb → commands/logs_command.rb} +0 -3
- data/lib/morpheus/cli/commands/{standard/man_command.rb → man_command.rb} +0 -2
- data/lib/morpheus/cli/{monitoring_alerts_command.rb → commands/monitoring_alerts_command.rb} +0 -7
- data/lib/morpheus/cli/{monitoring_apps_command.rb → commands/monitoring_apps_command.rb} +0 -1
- data/lib/morpheus/cli/{monitoring_checks_command.rb → commands/monitoring_checks_command.rb} +0 -1
- data/lib/morpheus/cli/{monitoring_contacts_command.rb → commands/monitoring_contacts_command.rb} +0 -7
- data/lib/morpheus/cli/{monitoring_groups_command.rb → commands/monitoring_groups_command.rb} +0 -1
- data/lib/morpheus/cli/{monitoring_incidents_command.rb → commands/monitoring_incidents_command.rb} +0 -1
- data/lib/morpheus/cli/commands/network_dhcp_relays_command.rb +416 -0
- data/lib/morpheus/cli/commands/network_dhcp_servers_command.rb +407 -0
- data/lib/morpheus/cli/{network_domains_command.rb → commands/network_domains_command.rb} +0 -4
- data/lib/morpheus/cli/commands/network_edge_clusters_command.rb +329 -0
- data/lib/morpheus/cli/commands/network_firewalls_command.rb +823 -0
- data/lib/morpheus/cli/{network_groups_command.rb → commands/network_groups_command.rb} +0 -4
- data/lib/morpheus/cli/{network_pool_servers_command.rb → commands/network_pool_servers_command.rb} +0 -4
- data/lib/morpheus/cli/{network_pools_command.rb → commands/network_pools_command.rb} +0 -4
- data/lib/morpheus/cli/{network_proxies_command.rb → commands/network_proxies_command.rb} +0 -4
- data/lib/morpheus/cli/{network_routers_command.rb → commands/network_routers_command.rb} +96 -50
- data/lib/morpheus/cli/{network_services_command.rb → commands/network_services_command.rb} +0 -4
- data/lib/morpheus/cli/commands/network_static_routes_command.rb +451 -0
- data/lib/morpheus/cli/{network_scopes_command.rb → commands/network_transport_zones_command.rb} +102 -92
- data/lib/morpheus/cli/{networks_command.rb → commands/networks_command.rb} +20 -20
- data/lib/morpheus/cli/commands/open_command.rb +30 -0
- data/lib/morpheus/cli/commands/options.rb +98 -0
- data/lib/morpheus/cli/{packages_command.rb → commands/packages_command.rb} +0 -2
- data/lib/morpheus/cli/{ping.rb → commands/ping.rb} +3 -12
- data/lib/morpheus/cli/{policies_command.rb → commands/policies_command.rb} +2 -9
- data/lib/morpheus/cli/{power_schedules_command.rb → commands/power_schedules_command.rb} +0 -0
- data/lib/morpheus/cli/{preseed_scripts_command.rb → commands/preseed_scripts_command.rb} +0 -3
- data/lib/morpheus/cli/{price_sets_command.rb → commands/price_sets_command.rb} +0 -0
- data/lib/morpheus/cli/{prices_command.rb → commands/prices_command.rb} +7 -7
- data/lib/morpheus/cli/{processes_command.rb → commands/processes_command.rb} +0 -1
- data/lib/morpheus/cli/{projects_command.rb → commands/projects_command.rb} +0 -0
- data/lib/morpheus/cli/{provisioning_licenses_command.rb → commands/provisioning_licenses_command.rb} +0 -0
- data/lib/morpheus/cli/{provisioning_settings_command.rb → commands/provisioning_settings_command.rb} +1 -0
- data/lib/morpheus/cli/{recent_activity_command.rb → commands/recent_activity_command.rb} +0 -0
- data/lib/morpheus/cli/{remote.rb → commands/remote.rb} +21 -19
- data/lib/morpheus/cli/{reports_command.rb → commands/reports_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/rm_command.rb → rm_command.rb} +0 -0
- data/lib/morpheus/cli/{roles.rb → commands/roles.rb} +245 -40
- data/lib/morpheus/cli/{search_command.rb → commands/search_command.rb} +0 -0
- data/lib/morpheus/cli/{security_group_rules.rb → commands/security_group_rules.rb} +0 -5
- data/lib/morpheus/cli/{security_groups.rb → commands/security_groups.rb} +2 -8
- data/lib/morpheus/cli/{service_catalog_command.rb → commands/service_catalog_command.rb} +0 -0
- data/lib/morpheus/cli/{service_plans_command.rb → commands/service_plans_command.rb} +1 -1
- data/lib/morpheus/cli/commands/{standard/set_prompt_command.rb → set_prompt_command.rb} +0 -3
- data/lib/morpheus/cli/{setup.rb → commands/setup.rb} +1 -1
- data/lib/morpheus/cli/{shell.rb → commands/shell.rb} +4 -105
- data/lib/morpheus/cli/commands/{standard/sleep_command.rb → sleep_command.rb} +0 -2
- data/lib/morpheus/cli/commands/snapshots.rb +139 -0
- data/lib/morpheus/cli/commands/{standard/source_command.rb → source_command.rb} +0 -2
- data/lib/morpheus/cli/commands/{standard/ssl_verification_command.rb → ssl_verification_command.rb} +0 -3
- data/lib/morpheus/cli/{storage_providers_command.rb → commands/storage_providers_command.rb} +0 -4
- data/lib/morpheus/cli/commands/storage_server_types.rb +50 -0
- data/lib/morpheus/cli/commands/storage_servers.rb +122 -0
- data/lib/morpheus/cli/commands/storage_volume_types.rb +50 -0
- data/lib/morpheus/cli/commands/storage_volumes.rb +103 -0
- data/lib/morpheus/cli/{subnets_command.rb → commands/subnets_command.rb} +0 -4
- data/lib/morpheus/cli/{tasks.rb → commands/tasks.rb} +5 -9
- data/lib/morpheus/cli/commands/{standard/tee_command.rb → tee_command.rb} +0 -0
- data/lib/morpheus/cli/{tenants_command.rb → commands/tenants_command.rb} +1 -8
- data/lib/morpheus/cli/commands/{standard/update_command.rb → update_command.rb} +0 -1
- data/lib/morpheus/cli/{usage_command.rb → commands/usage_command.rb} +0 -0
- data/lib/morpheus/cli/{user_groups_command.rb → commands/user_groups_command.rb} +1 -2
- data/lib/morpheus/cli/{user_settings_command.rb → commands/user_settings_command.rb} +3 -2
- data/lib/morpheus/cli/{user_sources_command.rb → commands/user_sources_command.rb} +1 -2
- data/lib/morpheus/cli/{users.rb → commands/users.rb} +28 -35
- data/lib/morpheus/cli/{vdi_allocations_command.rb → commands/vdi_allocations_command.rb} +0 -0
- data/lib/morpheus/cli/{vdi_apps_command.rb → commands/vdi_apps_command.rb} +0 -0
- data/lib/morpheus/cli/{vdi_command.rb → commands/vdi_command.rb} +0 -0
- data/lib/morpheus/cli/{vdi_gateways_command.rb → commands/vdi_gateways_command.rb} +0 -0
- data/lib/morpheus/cli/{vdi_pools_command.rb → commands/vdi_pools_command.rb} +0 -0
- data/lib/morpheus/cli/commands/{standard/version_command.rb → version_command.rb} +0 -0
- data/lib/morpheus/cli/commands/view.rb +102 -0
- data/lib/morpheus/cli/{virtual_images.rb → commands/virtual_images.rb} +4 -5
- data/lib/morpheus/cli/{whitelabel_settings_command.rb → commands/whitelabel_settings_command.rb} +0 -1
- data/lib/morpheus/cli/{whoami.rb → commands/whoami.rb} +0 -4
- data/lib/morpheus/cli/{wiki_command.rb → commands/wiki_command.rb} +0 -5
- data/lib/morpheus/cli/{workflows.rb → commands/workflows.rb} +0 -3
- data/lib/morpheus/cli/mixins/accounts_helper.rb +5 -5
- data/lib/morpheus/cli/mixins/load_balancers_helper.rb +24 -4
- data/lib/morpheus/cli/mixins/logs_helper.rb +1 -1
- data/lib/morpheus/cli/mixins/print_helper.rb +51 -18
- data/lib/morpheus/cli/mixins/processes_helper.rb +1 -2
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +96 -6
- data/lib/morpheus/cli/mixins/rest_command.rb +222 -62
- data/lib/morpheus/cli/mixins/secondary_rest_command.rb +249 -70
- data/lib/morpheus/cli/mixins/storage_servers_helper.rb +156 -0
- data/lib/morpheus/cli/mixins/storage_volumes_helper.rb +119 -0
- data/lib/morpheus/cli/option_types.rb +150 -46
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli.rb +5 -135
- data/lib/morpheus/ext/string.rb +29 -6
- data/lib/morpheus/routes.rb +238 -0
- data/lib/morpheus/terminal.rb +5 -6
- data/lib/morpheus/util.rb +6 -1
- metadata +174 -144
- data/lib/morpheus/cli/change_password_command.rb +0 -147
- data/lib/morpheus/cli/library.rb +0 -1
- data/lib/morpheus/cli/load_balancer_pools.rb +0 -111
- data/lib/morpheus/cli/load_balancers.rb +0 -90
- data/lib/morpheus/cli/logout.rb +0 -81
|
@@ -57,9 +57,9 @@ module Morpheus::Cli::ProvisioningHelper
|
|
|
57
57
|
@api_client.accounts
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
def get_available_groups(refresh=false)
|
|
60
|
+
def get_available_groups(params = {}, refresh=false)
|
|
61
61
|
if !@available_groups || refresh
|
|
62
|
-
option_results = options_interface.options_for_source('groups',
|
|
62
|
+
option_results = options_interface.options_for_source('groups', params)
|
|
63
63
|
@available_groups = option_results['data'].collect {|it|
|
|
64
64
|
{"id" => it["value"], "name" => it["name"], "value" => it["value"]}
|
|
65
65
|
}
|
|
@@ -68,9 +68,9 @@ module Morpheus::Cli::ProvisioningHelper
|
|
|
68
68
|
return @available_groups
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
def get_available_clouds(group_id, refresh=false)
|
|
71
|
+
def get_available_clouds(group_id, params = {}, refresh=false)
|
|
72
72
|
if !group_id
|
|
73
|
-
option_results = options_interface.options_for_source('clouds', {'default' => 'false'})
|
|
73
|
+
option_results = options_interface.options_for_source('clouds', params.merge({'default' => 'false'}))
|
|
74
74
|
return option_results['data'].collect {|it|
|
|
75
75
|
{"id" => it["value"], "name" => it["name"], "value" => it["value"], "zoneTypeId" => it["zoneTypeId"]}
|
|
76
76
|
}
|
|
@@ -80,7 +80,7 @@ module Morpheus::Cli::ProvisioningHelper
|
|
|
80
80
|
return []
|
|
81
81
|
end
|
|
82
82
|
if !group["clouds"] || refresh
|
|
83
|
-
option_results = options_interface.options_for_source('clouds', {groupId: group_id})
|
|
83
|
+
option_results = options_interface.options_for_source('clouds', params.merge({groupId: group_id}))
|
|
84
84
|
group["clouds"] = option_results['data'].collect {|it|
|
|
85
85
|
{"id" => it["value"], "name" => it["name"], "value" => it["value"], "zoneTypeId" => it["zoneTypeId"]}
|
|
86
86
|
}
|
|
@@ -484,7 +484,7 @@ module Morpheus::Cli::ProvisioningHelper
|
|
|
484
484
|
if options[:instance_type_code]
|
|
485
485
|
instance_type_code = options[:instance_type_code]
|
|
486
486
|
else
|
|
487
|
-
instance_type_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => 'Type', 'optionSource' => 'instanceTypes', 'required' => true, 'description' => 'Select Instance Type.'}],options[:options],api_client,{groupId: group_id}, no_prompt, true)
|
|
487
|
+
instance_type_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => 'Type', 'optionSource' => 'instanceTypes', 'required' => true, 'description' => 'Select Instance Type.'}],options[:options],api_client,{groupId: group_id, cloudId: cloud_id, restrictProvisionType:true}, no_prompt, true)
|
|
488
488
|
instance_type_code = instance_type_prompt['type']
|
|
489
489
|
end
|
|
490
490
|
if instance_type_code.to_s =~ /\A\d{1,}\Z/
|
|
@@ -870,6 +870,12 @@ module Morpheus::Cli::ProvisioningHelper
|
|
|
870
870
|
end
|
|
871
871
|
end
|
|
872
872
|
|
|
873
|
+
# plan customizations
|
|
874
|
+
plan_opts = prompt_service_plan_options(service_plan, options, api_client, {zoneId: cloud_id, layoutId: layout['id'], siteId: group_id})
|
|
875
|
+
if plan_opts && !plan_opts.empty?
|
|
876
|
+
payload['servicePlanOptions'] = plan_opts
|
|
877
|
+
end
|
|
878
|
+
|
|
873
879
|
# prompt networks
|
|
874
880
|
if locked_fields.include?('networks')
|
|
875
881
|
# payload['networkInterfaces'] = options[:options]['networkInterfaces'] if options[:options]['networkInterfaces']
|
|
@@ -942,6 +948,7 @@ module Morpheus::Cli::ProvisioningHelper
|
|
|
942
948
|
# prompt for option types
|
|
943
949
|
api_params['config'] = payload['config'] if payload['config']
|
|
944
950
|
api_params['poolId'] = payload['config']['resourcePoolId'] if payload['config'] && payload['config']['resourcePoolId']
|
|
951
|
+
api_params['resourcePoolId'] = api_params['poolId']
|
|
945
952
|
|
|
946
953
|
# set option type defaults from config
|
|
947
954
|
if options[:default_config]
|
|
@@ -2093,6 +2100,15 @@ module Morpheus::Cli::ProvisioningHelper
|
|
|
2093
2100
|
permissions
|
|
2094
2101
|
end
|
|
2095
2102
|
|
|
2103
|
+
def prompt_permissions_v2(options, excludes = [])
|
|
2104
|
+
perms = prompt_permissions(options, excludes)
|
|
2105
|
+
rtn = {}
|
|
2106
|
+
|
|
2107
|
+
rtn['visibility'] = perms['resourcePool']['visibility'] if !perms['resourcePool'].nil?
|
|
2108
|
+
rtn['tenants'] = ((perms['tenantPermissions'] || {})['accounts'] || []).collect {|it| {'id' => it}}
|
|
2109
|
+
rtn
|
|
2110
|
+
end
|
|
2111
|
+
|
|
2096
2112
|
def print_permissions(permissions, excludes = [])
|
|
2097
2113
|
if permissions.nil?
|
|
2098
2114
|
print_h2 "Permissions"
|
|
@@ -2230,6 +2246,80 @@ module Morpheus::Cli::ProvisioningHelper
|
|
|
2230
2246
|
return ports
|
|
2231
2247
|
end
|
|
2232
2248
|
|
|
2249
|
+
def prompt_service_plan_options(plan_info, options={}, api_client=nil, api_params={}, instance=nil)
|
|
2250
|
+
plan_opts = {}
|
|
2251
|
+
# provisioning with blueprint can lock fields
|
|
2252
|
+
locked_fields = options[:locked_fields] || []
|
|
2253
|
+
if options[:options]['servicePlanOptions']
|
|
2254
|
+
plan_opts = options[:options]['servicePlanOptions']
|
|
2255
|
+
end
|
|
2256
|
+
default_max_cores = plan_info['maxCores'].to_i != 0 ? plan_info['maxCores'] : 1
|
|
2257
|
+
default_cores_per_socket = plan_info['coresPerSocket'].to_i != 0 ? plan_info['coresPerSocket'] : 1
|
|
2258
|
+
default_max_memory = plan_info['maxMemory'].to_i != 0 ? plan_info['maxMemory'] : nil
|
|
2259
|
+
# use defaults from the instance/server
|
|
2260
|
+
if instance
|
|
2261
|
+
default_max_cores = instance["maxCores"] if instance["maxCores"]
|
|
2262
|
+
default_cores_per_socket = instance["coresPerSocket"] if instance["coresPerSocket"]
|
|
2263
|
+
default_max_memory = instance["maxMemory"] if instance["maxMemory"]
|
|
2264
|
+
end
|
|
2265
|
+
# Core Count
|
|
2266
|
+
if plan_info["customCores"]
|
|
2267
|
+
if locked_fields.include?('servicePlanOptions.maxCores')
|
|
2268
|
+
if options[:options]['servicePlanOptions'] && options[:options]['servicePlanOptions']['maxCores']
|
|
2269
|
+
plan_opts['maxCores'] = options[:options]['servicePlanOptions']['maxCores'].to_i
|
|
2270
|
+
end
|
|
2271
|
+
else
|
|
2272
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'servicePlanOptions', 'fieldName' => 'maxCores', 'type' => 'number', 'fieldLabel' => "Core Count", 'required' => true, 'defaultValue' => default_max_cores, 'description' => "Customize service plan options Core Count"}], options[:options])
|
|
2273
|
+
if v_prompt['servicePlanOptions'] && v_prompt['servicePlanOptions']['maxCores']
|
|
2274
|
+
plan_opts['maxCores'] = v_prompt['servicePlanOptions']['maxCores'].to_i
|
|
2275
|
+
end
|
|
2276
|
+
end
|
|
2277
|
+
end
|
|
2278
|
+
# Cores Per Socket
|
|
2279
|
+
if plan_info["customCoresPerSocket"]
|
|
2280
|
+
if locked_fields.include?('servicePlanOptions.coresPerSocket')
|
|
2281
|
+
if options[:options]['servicePlanOptions'] && options[:options]['servicePlanOptions']['coresPerSocket']
|
|
2282
|
+
plan_opts['coresPerSocket'] = options[:options]['servicePlanOptions']['coresPerSocket'].to_i
|
|
2283
|
+
end
|
|
2284
|
+
else
|
|
2285
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'servicePlanOptions', 'fieldName' => 'coresPerSocket', 'type' => 'number', 'fieldLabel' => "Cores Per Socket", 'required' => true, 'defaultValue' => default_cores_per_socket, 'description' => "Customize service plan options Cores Per Socket"}], options[:options])
|
|
2286
|
+
if v_prompt['servicePlanOptions'] && v_prompt['servicePlanOptions']['coresPerSocket']
|
|
2287
|
+
plan_opts['coresPerSocket'] = v_prompt['servicePlanOptions']['coresPerSocket'].to_i
|
|
2288
|
+
end
|
|
2289
|
+
end
|
|
2290
|
+
end
|
|
2291
|
+
# Memory
|
|
2292
|
+
if plan_info["customMaxMemory"]
|
|
2293
|
+
if locked_fields.include?('servicePlanOptions.maxMemory')
|
|
2294
|
+
if options[:options]['servicePlanOptions'] && options[:options]['servicePlanOptions']['maxMemory']
|
|
2295
|
+
plan_opts['maxMemory'] = options[:options]['servicePlanOptions']['maxMemory'].to_i
|
|
2296
|
+
end
|
|
2297
|
+
else
|
|
2298
|
+
if options[:options]['servicePlanOptions'] && options[:options]['servicePlanOptions']['maxMemory']
|
|
2299
|
+
plan_opts['maxMemory'] = options[:options]['servicePlanOptions']['maxMemory'].to_i
|
|
2300
|
+
else
|
|
2301
|
+
# prompt for "memoryMB" field as MB or "memoryGB" in GB
|
|
2302
|
+
# always convert maxMemory to bytes
|
|
2303
|
+
if plan_info["memorySizeType"] == "MB" || options[:options]["memoryMB"]
|
|
2304
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'memoryMB', 'type' => 'text', 'fieldLabel' => "Memory (MB)", 'required' => true, 'defaultValue' => default_max_memory / (1024 * 1024), 'description' => "Customize service plan options Memory (MB). Value is in megabytes."}], options[:options])
|
|
2305
|
+
if v_prompt['memoryMB'].to_s != ""
|
|
2306
|
+
plan_opts['maxMemory'] = v_prompt['memoryMB'].to_i * 1024 * 1024
|
|
2307
|
+
end
|
|
2308
|
+
else
|
|
2309
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'memoryGB', 'type' => 'text', 'fieldLabel' => "Memory (GB)", 'required' => true, 'defaultValue' => default_max_memory / (1024 * 1024 * 1024), 'description' => "Customize service plan options Memory (GB). Value is in gigabytes."}], options[:options])
|
|
2310
|
+
if v_prompt['memoryGB'].to_s != ""
|
|
2311
|
+
plan_opts['maxMemory'] = v_prompt['memoryGB'].to_i * 1024 * 1024 * 1024
|
|
2312
|
+
end
|
|
2313
|
+
end
|
|
2314
|
+
# remove transient memory field just used for prompting for MB or GB
|
|
2315
|
+
plan_opts.delete("memoryMB")
|
|
2316
|
+
plan_opts.delete("memoryGB")
|
|
2317
|
+
end
|
|
2318
|
+
end
|
|
2319
|
+
end
|
|
2320
|
+
return plan_opts
|
|
2321
|
+
end
|
|
2322
|
+
|
|
2233
2323
|
def format_instance_status(instance, return_color=cyan)
|
|
2234
2324
|
out = ""
|
|
2235
2325
|
status_string = instance['status'].to_s
|
|
@@ -39,7 +39,7 @@ module Morpheus::Cli::RestCommand
|
|
|
39
39
|
|
|
40
40
|
module ClassMethods
|
|
41
41
|
|
|
42
|
-
# rest_name is the plural name of the
|
|
42
|
+
# rest_name is the plural name of the resource eg. NeatThings would be "neat_things"
|
|
43
43
|
# It is used to derive all other default rest settings key, label, etc.
|
|
44
44
|
# The default name the command name with underscores `_` instead of dashes `-`.
|
|
45
45
|
def rest_name
|
|
@@ -86,6 +86,22 @@ module Morpheus::Cli::RestCommand
|
|
|
86
86
|
|
|
87
87
|
alias :set_rest_arg :rest_arg=
|
|
88
88
|
|
|
89
|
+
# rest_has_name indicates a resource has a name and can be retrieved by name or id
|
|
90
|
+
# true by default, set to false for lookups by only id
|
|
91
|
+
def rest_has_name
|
|
92
|
+
@rest_has_name != nil ? @rest_has_name : default_rest_has_name
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def default_rest_has_name
|
|
96
|
+
true
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def rest_has_name=(v)
|
|
100
|
+
@rest_has_name = !!v
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
alias :set_rest_has_name :rest_has_name=
|
|
104
|
+
|
|
89
105
|
# rest_label is the capitalized resource label eg. "Neat Thing"
|
|
90
106
|
def rest_label
|
|
91
107
|
@rest_label || default_rest_label
|
|
@@ -297,6 +313,10 @@ module Morpheus::Cli::RestCommand
|
|
|
297
313
|
self.class.rest_arg
|
|
298
314
|
end
|
|
299
315
|
|
|
316
|
+
def rest_has_name
|
|
317
|
+
self.class.rest_has_name
|
|
318
|
+
end
|
|
319
|
+
|
|
300
320
|
def rest_label
|
|
301
321
|
self.class.rest_label
|
|
302
322
|
end
|
|
@@ -316,23 +336,37 @@ module Morpheus::Cli::RestCommand
|
|
|
316
336
|
end
|
|
317
337
|
|
|
318
338
|
def rest_object_key
|
|
319
|
-
|
|
339
|
+
send("#{rest_key}_object_key")
|
|
320
340
|
end
|
|
321
341
|
|
|
322
342
|
def rest_list_key
|
|
323
|
-
|
|
343
|
+
send("#{rest_key}_list_key")
|
|
324
344
|
end
|
|
325
345
|
|
|
326
|
-
def rest_column_definitions
|
|
327
|
-
|
|
346
|
+
def rest_column_definitions(options)
|
|
347
|
+
send("#{rest_key}_column_definitions", options)
|
|
328
348
|
end
|
|
329
349
|
|
|
330
|
-
def rest_list_column_definitions
|
|
331
|
-
|
|
350
|
+
def rest_list_column_definitions(options)
|
|
351
|
+
send("#{rest_key}_list_column_definitions", options)
|
|
332
352
|
end
|
|
333
353
|
|
|
334
|
-
def rest_find_by_name_or_id(
|
|
335
|
-
|
|
354
|
+
def rest_find_by_name_or_id(val)
|
|
355
|
+
# use explicitly defined finders
|
|
356
|
+
# else default to new generic CliCommand method to find anything by type (singular underscore)
|
|
357
|
+
if rest_has_name
|
|
358
|
+
if respond_to?("find_#{rest_key}_by_name_or_id", true)
|
|
359
|
+
send("find_#{rest_key}_by_name_or_id", val)
|
|
360
|
+
else
|
|
361
|
+
find_by_name_or_id(rest_key, val)
|
|
362
|
+
end
|
|
363
|
+
else
|
|
364
|
+
if respond_to?("find_#{rest_key}_by_id", true)
|
|
365
|
+
send("find_#{rest_key}_by_id", val)
|
|
366
|
+
else
|
|
367
|
+
find_by_id(rest_key, val)
|
|
368
|
+
end
|
|
369
|
+
end
|
|
336
370
|
end
|
|
337
371
|
|
|
338
372
|
def rest_has_type
|
|
@@ -353,6 +387,10 @@ module Morpheus::Cli::RestCommand
|
|
|
353
387
|
self.class.rest_type_arg
|
|
354
388
|
end
|
|
355
389
|
|
|
390
|
+
def rest_has_name
|
|
391
|
+
self.class.rest_type_arg
|
|
392
|
+
end
|
|
393
|
+
|
|
356
394
|
def rest_type_label
|
|
357
395
|
self.class.rest_type_label
|
|
358
396
|
end
|
|
@@ -370,23 +408,29 @@ module Morpheus::Cli::RestCommand
|
|
|
370
408
|
end
|
|
371
409
|
|
|
372
410
|
def rest_type_object_key
|
|
373
|
-
|
|
411
|
+
send("#{rest_type_key}_object_key")
|
|
374
412
|
end
|
|
375
413
|
|
|
376
414
|
def rest_type_list_key
|
|
377
|
-
|
|
415
|
+
send("#{rest_type_key}_list_key")
|
|
378
416
|
end
|
|
379
417
|
|
|
380
|
-
def rest_type_column_definitions
|
|
381
|
-
|
|
418
|
+
def rest_type_column_definitions(options)
|
|
419
|
+
send("#{rest_type_key}_column_definitions", options)
|
|
382
420
|
end
|
|
383
421
|
|
|
384
|
-
def rest_type_list_column_definitions
|
|
385
|
-
|
|
422
|
+
def rest_type_list_column_definitions(options)
|
|
423
|
+
send("#{rest_type_key}_list_column_definitions", options)
|
|
386
424
|
end
|
|
387
425
|
|
|
388
|
-
def rest_type_find_by_name_or_id(
|
|
389
|
-
|
|
426
|
+
def rest_type_find_by_name_or_id(val)
|
|
427
|
+
# use explicately defined finders
|
|
428
|
+
# else default to new generic CliCommand method to find anything by type (singular underscore)
|
|
429
|
+
if respond_to?("find_#{rest_type_key}_by_name_or_id", true)
|
|
430
|
+
send("find_#{rest_type_key}_by_name_or_id", val)
|
|
431
|
+
else
|
|
432
|
+
find_by_name_or_id(rest_type_key, val)
|
|
433
|
+
end
|
|
390
434
|
end
|
|
391
435
|
|
|
392
436
|
def registered_interfaces
|
|
@@ -417,18 +461,15 @@ module Morpheus::Cli::RestCommand
|
|
|
417
461
|
options = {}
|
|
418
462
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
419
463
|
opts.banner = subcommand_usage("[search]")
|
|
420
|
-
|
|
421
|
-
|
|
464
|
+
build_list_options(opts, options, params)
|
|
465
|
+
opts.footer = <<-EOT
|
|
422
466
|
List #{rest_label_plural.downcase}.
|
|
423
467
|
[search] is optional. This is a search phrase to filter the results.
|
|
424
468
|
EOT
|
|
425
469
|
end
|
|
426
470
|
optparse.parse!(args)
|
|
427
471
|
connect(options)
|
|
428
|
-
|
|
429
|
-
options[:phrase] = args.join(" ")
|
|
430
|
-
end
|
|
431
|
-
params.merge!(parse_list_options(options))
|
|
472
|
+
parse_list_options!(args, options, params)
|
|
432
473
|
rest_interface.setopts(options)
|
|
433
474
|
if options[:dry_run]
|
|
434
475
|
print_dry_run rest_interface.dry.list(params)
|
|
@@ -441,7 +482,7 @@ EOT
|
|
|
441
482
|
if records.nil? || records.empty?
|
|
442
483
|
print cyan,"No #{rest_label_plural.downcase} found.",reset,"\n"
|
|
443
484
|
else
|
|
444
|
-
print as_pretty_table(records, rest_list_column_definitions.upcase_keys!, options)
|
|
485
|
+
print as_pretty_table(records, rest_list_column_definitions(options).upcase_keys!, options)
|
|
445
486
|
print_results_pagination(json_response) if json_response['meta']
|
|
446
487
|
end
|
|
447
488
|
print reset,"\n"
|
|
@@ -454,27 +495,25 @@ EOT
|
|
|
454
495
|
options = {}
|
|
455
496
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
456
497
|
opts.banner = subcommand_usage("[#{rest_arg}]")
|
|
457
|
-
|
|
498
|
+
build_get_options(opts, options, params)
|
|
458
499
|
opts.footer = <<-EOT
|
|
459
500
|
Get details about #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
460
|
-
[#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
501
|
+
[#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
461
502
|
EOT
|
|
462
503
|
end
|
|
463
504
|
optparse.parse!(args)
|
|
464
505
|
verify_args!(args:args, optparse:optparse, min:1)
|
|
465
506
|
connect(options)
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
_get(arg, params, options)
|
|
470
|
-
end
|
|
507
|
+
parse_get_options!(args, options, params)
|
|
508
|
+
id = args.join(" ")
|
|
509
|
+
_get(id, params, options)
|
|
471
510
|
end
|
|
472
511
|
|
|
473
512
|
def _get(id, params, options)
|
|
474
|
-
if id !~ /\A\d{1,}\Z/
|
|
513
|
+
if id !~ /\A\d{1,}\Z/ && rest_has_name
|
|
475
514
|
record = rest_find_by_name_or_id(id)
|
|
476
515
|
if record.nil?
|
|
477
|
-
|
|
516
|
+
return 1, "#{rest_label} not found for '#{id}'"
|
|
478
517
|
end
|
|
479
518
|
id = record['id']
|
|
480
519
|
end
|
|
@@ -493,8 +532,14 @@ EOT
|
|
|
493
532
|
record = json_response[rest_object_key]
|
|
494
533
|
print_h1 rest_label, [], options
|
|
495
534
|
print cyan
|
|
496
|
-
print_description_list(rest_column_definitions, record, options)
|
|
497
|
-
# show config
|
|
535
|
+
print_description_list(rest_column_definitions(options), record, options)
|
|
536
|
+
# # could always show config eh? or maybe only with --config if that is nicer.
|
|
537
|
+
# # config = record['config'].is_a?(Hash) && !record['config'].empty?
|
|
538
|
+
# if config && !config.empty?
|
|
539
|
+
# print_h2 "Configuration"
|
|
540
|
+
# print_description_list(config.keys, config)
|
|
541
|
+
# end
|
|
542
|
+
# Option Types
|
|
498
543
|
if record['optionTypes'] && record['optionTypes'].size > 0
|
|
499
544
|
print_h2 "Option Types", options
|
|
500
545
|
print format_option_types_table(record['optionTypes'], options, rest_object_key)
|
|
@@ -504,45 +549,52 @@ EOT
|
|
|
504
549
|
end
|
|
505
550
|
|
|
506
551
|
def add(args)
|
|
552
|
+
record_type = nil
|
|
507
553
|
record_type_id = nil
|
|
508
554
|
options = {}
|
|
555
|
+
option_types = respond_to?("add_#{rest_key}_option_types", true) ? send("add_#{rest_key}_option_types") : []
|
|
556
|
+
advanced_option_types = respond_to?("add_#{rest_key}_advanced_option_types", true) ? send("add_#{rest_key}_advanced_option_types") : []
|
|
557
|
+
type_option_type = option_types.find {|it| it['fieldName'] == 'type'}
|
|
509
558
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
510
|
-
|
|
511
|
-
|
|
559
|
+
opts.banner = subcommand_usage("[#{rest_arg}]")
|
|
560
|
+
if rest_has_type && type_option_type.nil?
|
|
512
561
|
opts.on( '-t', "--#{rest_type_arg} TYPE", "#{rest_type_label}" ) do |val|
|
|
513
562
|
record_type_id = val
|
|
514
563
|
end
|
|
515
|
-
else
|
|
516
|
-
opts.banner = subcommand_usage("[#{rest_arg}]")
|
|
517
564
|
end
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
# end
|
|
565
|
+
build_option_type_options(opts, options, option_types)
|
|
566
|
+
build_option_type_options(opts, options, advanced_option_types)
|
|
521
567
|
build_standard_add_options(opts, options)
|
|
522
568
|
opts.footer = <<-EOT
|
|
523
569
|
Create a new #{rest_label.downcase}.
|
|
524
570
|
[#{rest_arg}] is required. This is the name of the new #{rest_label.downcase}.
|
|
525
571
|
EOT
|
|
572
|
+
opts.footer += send "add_#{rest_key}_footer_addn" if respond_to?("add_#{rest_key}_footer_addn", true)
|
|
526
573
|
end
|
|
527
574
|
optparse.parse!(args)
|
|
528
575
|
# todo: make supporting args[0] optional and more flexible
|
|
529
576
|
# for now args[0] is assumed to be the 'name'
|
|
530
577
|
record_name = nil
|
|
531
|
-
if
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
verify_args!(args:args, optparse:optparse, min:0, max: 1)
|
|
535
|
-
# todo: maybe need a flag to make this required, it could be an option type too, so
|
|
536
|
-
if rest_has_type
|
|
537
|
-
if record_type_id.nil?
|
|
538
|
-
raise_command_error "#{rest_type_label} is required.\n#{optparse}"
|
|
578
|
+
if rest_has_name
|
|
579
|
+
if args.count > 0
|
|
580
|
+
record_name = args.join(" ")
|
|
539
581
|
end
|
|
582
|
+
verify_args!(args:args, optparse:optparse, min:0, max: 1)
|
|
583
|
+
else
|
|
584
|
+
verify_args!(args:args, optparse:optparse, count: 0)
|
|
540
585
|
end
|
|
541
586
|
connect(options)
|
|
542
|
-
|
|
587
|
+
# load or prompt for type
|
|
588
|
+
if rest_has_type && type_option_type.nil?
|
|
589
|
+
if record_type_id.nil?
|
|
590
|
+
#raise_command_error "#{rest_type_label} is required.\n#{optparse}"
|
|
591
|
+
type_list = rest_type_interface.list({max:10000, creatable:true})[rest_type_list_key]
|
|
592
|
+
type_dropdown_options = respond_to?("#{rest_key}_type_list_to_options", true) ? send("#{rest_key}_type_list_to_options", type_list) : type_list.collect {|it| {'name' => it['name'], 'value' => it['code']} }
|
|
593
|
+
record_type_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'fieldLabel' => rest_type_label, 'type' => 'select', 'selectOptions' => type_dropdown_options, 'required' => true}], options[:options], @api_client)['type']
|
|
594
|
+
end
|
|
543
595
|
record_type = rest_type_find_by_name_or_id(record_type_id)
|
|
544
596
|
if record_type.nil?
|
|
545
|
-
|
|
597
|
+
return 1, "#{rest_type_label} not found for '#{record_type_id}"
|
|
546
598
|
end
|
|
547
599
|
end
|
|
548
600
|
passed_options = parse_passed_options(options)
|
|
@@ -557,13 +609,40 @@ EOT
|
|
|
557
609
|
options[:options]['name'] = record_name # injected for prompt
|
|
558
610
|
end
|
|
559
611
|
if rest_has_type && record_type
|
|
560
|
-
#
|
|
612
|
+
# inject type to options for prompting
|
|
561
613
|
record_payload['type'] = record_type['code']
|
|
562
|
-
options[:options]['type'] = record_type['code']
|
|
614
|
+
options[:options]['type'] = record_type['code']
|
|
615
|
+
# initialize params for loading optionSource data
|
|
616
|
+
options[:params] ||= {}
|
|
617
|
+
options[:params]['type'] = record_type['code']
|
|
563
618
|
end
|
|
564
619
|
record_payload.deep_merge!(passed_options)
|
|
620
|
+
if option_types && !option_types.empty?
|
|
621
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
|
|
622
|
+
v_prompt.deep_compact!
|
|
623
|
+
v_prompt.booleanize! # 'on' => true
|
|
624
|
+
record_payload.deep_merge!(v_prompt)
|
|
625
|
+
end
|
|
565
626
|
# options by type
|
|
566
|
-
|
|
627
|
+
if rest_has_type && record_type.nil?
|
|
628
|
+
type_value = record_payload['type'].is_a?(Hash) ? record_payload['type']['id'] : record_payload['type']
|
|
629
|
+
if type_value
|
|
630
|
+
record_type = rest_type_find_by_name_or_id(type_value)
|
|
631
|
+
if record_type.nil?
|
|
632
|
+
return 1, "#{rest_type_label} not found for '#{type_value}"
|
|
633
|
+
end
|
|
634
|
+
end
|
|
635
|
+
# reload the type by id to get all the details ie. optionTypes
|
|
636
|
+
if record_type && record_type['optionTypes'].nil?
|
|
637
|
+
record_type = rest_type_find_by_name_or_id(record_type['id'])
|
|
638
|
+
end
|
|
639
|
+
end
|
|
640
|
+
my_option_types = nil
|
|
641
|
+
if respond_to?("load_option_types_for_#{rest_key}", true)
|
|
642
|
+
my_option_types = send("load_option_types_for_#{rest_key}", record_type, nil)
|
|
643
|
+
else
|
|
644
|
+
my_option_types = record_type ? record_type['optionTypes'] : nil
|
|
645
|
+
end
|
|
567
646
|
if my_option_types && !my_option_types.empty?
|
|
568
647
|
# remove redundant fieldContext
|
|
569
648
|
my_option_types.each do |option_type|
|
|
@@ -571,7 +650,15 @@ EOT
|
|
|
571
650
|
option_type['fieldContext'] = nil
|
|
572
651
|
end
|
|
573
652
|
end
|
|
574
|
-
|
|
653
|
+
api_params = (options[:params] || {}).merge(record_payload)
|
|
654
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, api_params)
|
|
655
|
+
v_prompt.deep_compact!
|
|
656
|
+
v_prompt.booleanize! # 'on' => true
|
|
657
|
+
record_payload.deep_merge!(v_prompt)
|
|
658
|
+
end
|
|
659
|
+
# advanced options (uses no_prompt)
|
|
660
|
+
if advanced_option_types && !advanced_option_types.empty?
|
|
661
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
|
|
575
662
|
v_prompt.deep_compact!
|
|
576
663
|
v_prompt.booleanize! # 'on' => true
|
|
577
664
|
record_payload.deep_merge!(v_prompt)
|
|
@@ -594,28 +681,101 @@ EOT
|
|
|
594
681
|
|
|
595
682
|
def update(args)
|
|
596
683
|
id = args[0]
|
|
684
|
+
record_type = nil
|
|
685
|
+
record_type_id = nil
|
|
597
686
|
options = {}
|
|
598
|
-
|
|
599
|
-
|
|
687
|
+
option_types = respond_to?("update_#{rest_key}_option_types", true) ? send("update_#{rest_key}_option_types") : []
|
|
688
|
+
advanced_option_types = respond_to?("update_#{rest_key}_advanced_option_types", true) ? send("update_#{rest_key}_advanced_option_types") : []
|
|
600
689
|
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
|
601
690
|
opts.banner = subcommand_usage("[#{rest_arg}] [options]")
|
|
691
|
+
build_option_type_options(opts, options, option_types)
|
|
692
|
+
build_option_type_options(opts, options, advanced_option_types)
|
|
602
693
|
build_standard_update_options(opts, options)
|
|
603
694
|
opts.footer = <<-EOT
|
|
604
695
|
Update an existing #{rest_label.downcase}.
|
|
605
|
-
[#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
696
|
+
[#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
606
697
|
EOT
|
|
698
|
+
opts.footer += send "update_#{rest_key}_footer_addn" if respond_to?("update_#{rest_key}_footer_addn", true)
|
|
607
699
|
end
|
|
608
700
|
optparse.parse!(args)
|
|
609
701
|
verify_args!(args:args, optparse:optparse, count:1)
|
|
610
702
|
connect(options)
|
|
611
703
|
record = rest_find_by_name_or_id(id)
|
|
704
|
+
if record.nil?
|
|
705
|
+
return 1, "#{rest_name} not found for '#{id}'"
|
|
706
|
+
end
|
|
707
|
+
# load type so we can prompt for those option types
|
|
708
|
+
if rest_has_type
|
|
709
|
+
record_type_id = record['type']['id']
|
|
710
|
+
record_type = rest_type_find_by_name_or_id(record_type_id)
|
|
711
|
+
if record_type.nil?
|
|
712
|
+
return 1, "#{rest_type_label} not found for '#{record_type_id}"
|
|
713
|
+
end
|
|
714
|
+
# reload the type by id to get all the details ie. optionTypes
|
|
715
|
+
if record_type['optionTypes'].nil?
|
|
716
|
+
record_type = rest_type_find_by_name_or_id(record_type['id'])
|
|
717
|
+
end
|
|
718
|
+
end
|
|
612
719
|
passed_options = parse_passed_options(options)
|
|
613
|
-
payload =
|
|
720
|
+
payload = {}
|
|
614
721
|
if options[:payload]
|
|
615
722
|
payload = options[:payload]
|
|
616
723
|
payload.deep_merge!({rest_object_key => passed_options}) unless passed_options.empty?
|
|
617
724
|
else
|
|
618
725
|
record_payload = passed_options
|
|
726
|
+
if rest_has_type && record_type
|
|
727
|
+
# inject type to options for prompting
|
|
728
|
+
# record_payload['type'] = record_type['code']
|
|
729
|
+
# options[:options]['type'] = record_type['code']
|
|
730
|
+
# initialize params for loading optionSource data
|
|
731
|
+
options[:params] ||= {}
|
|
732
|
+
options[:params]['type'] = record_type['code']
|
|
733
|
+
end
|
|
734
|
+
# update options without prompting by default
|
|
735
|
+
if option_types && !option_types.empty?
|
|
736
|
+
api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
|
|
737
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(option_types, options[:options], @api_client, api_params)
|
|
738
|
+
v_prompt.deep_compact!
|
|
739
|
+
v_prompt.booleanize! # 'on' => true
|
|
740
|
+
record_payload.deep_merge!(v_prompt)
|
|
741
|
+
end
|
|
742
|
+
# options by type
|
|
743
|
+
my_option_types = nil
|
|
744
|
+
if respond_to?("load_option_types_for_#{rest_key}", true)
|
|
745
|
+
my_option_types = send("load_option_types_for_#{rest_key}", record_type, nil)
|
|
746
|
+
else
|
|
747
|
+
my_option_types = record_type ? record_type['optionTypes'] : nil
|
|
748
|
+
end
|
|
749
|
+
if my_option_types && !my_option_types.empty?
|
|
750
|
+
# remove redundant fieldContext
|
|
751
|
+
# make them optional for updates
|
|
752
|
+
# todo: use current value as default instead of just making things optioanl
|
|
753
|
+
# maybe new prompt() options like {:mode => :edit, :object => storage_server} or something
|
|
754
|
+
my_option_types.each do |option_type|
|
|
755
|
+
if option_type['fieldContext'] == rest_object_key
|
|
756
|
+
option_type['fieldContext'] = nil
|
|
757
|
+
end
|
|
758
|
+
option_type.delete('required')
|
|
759
|
+
option_type.delete('defaultValue')
|
|
760
|
+
end
|
|
761
|
+
api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
|
|
762
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(my_option_types, options[:options], @api_client, api_params)
|
|
763
|
+
v_prompt.deep_compact!
|
|
764
|
+
v_prompt.booleanize! # 'on' => true
|
|
765
|
+
record_payload.deep_merge!(v_prompt)
|
|
766
|
+
end
|
|
767
|
+
# advanced options
|
|
768
|
+
if advanced_option_types && !advanced_option_types.empty?
|
|
769
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
|
|
770
|
+
v_prompt.deep_compact!
|
|
771
|
+
v_prompt.booleanize! # 'on' => true
|
|
772
|
+
record_payload.deep_merge!(v_prompt)
|
|
773
|
+
end
|
|
774
|
+
# remove empty config, compact could hanlde this
|
|
775
|
+
if record_payload['config'] && record_payload['config'].empty?
|
|
776
|
+
record_payload.delete('config')
|
|
777
|
+
end
|
|
778
|
+
# prevent updating with empty payload
|
|
619
779
|
if record_payload.empty?
|
|
620
780
|
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
|
621
781
|
end
|
|
@@ -643,7 +803,7 @@ EOT
|
|
|
643
803
|
build_standard_remove_options(opts, options)
|
|
644
804
|
opts.footer = <<-EOT
|
|
645
805
|
Delete an existing #{rest_label.downcase}.
|
|
646
|
-
[#{rest_arg}] is required. This is the name or id of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
806
|
+
[#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
647
807
|
EOT
|
|
648
808
|
end
|
|
649
809
|
optparse.parse!(args)
|
|
@@ -659,7 +819,7 @@ EOT
|
|
|
659
819
|
end
|
|
660
820
|
rest_interface.setopts(options)
|
|
661
821
|
if options[:dry_run]
|
|
662
|
-
print_dry_run rest_interface.dry.destroy(record['id'])
|
|
822
|
+
print_dry_run rest_interface.dry.destroy(record['id'], params)
|
|
663
823
|
return 0, nil
|
|
664
824
|
end
|
|
665
825
|
json_response = rest_interface.destroy(record['id'], params)
|