mtncloud-cli 1.0.0
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 +7 -0
- data/.dockerignore +20 -0
- data/.github/pull_request_template.md +14 -0
- data/.github/workflows/ci.yml +56 -0
- data/.github/workflows/release.yml +46 -0
- data/.gitignore +25 -0
- data/CLAUDE.md +24 -0
- data/CONTRIBUTING.md +91 -0
- data/Dockerfile +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +187 -0
- data/Rakefile +26 -0
- data/bin/mcs +3 -0
- data/bin/mtncloud +27 -0
- data/lib/mtncloud/api/account_groups_interface.rb +48 -0
- data/lib/mtncloud/api/account_users_interface.rb +68 -0
- data/lib/mtncloud/api/accounts_interface.rb +9 -0
- data/lib/mtncloud/api/activity_interface.rb +9 -0
- data/lib/mtncloud/api/affinity_groups_interface.rb +46 -0
- data/lib/mtncloud/api/api_client.rb +1091 -0
- data/lib/mtncloud/api/appliance_settings_interface.rb +49 -0
- data/lib/mtncloud/api/approvals_interface.rb +32 -0
- data/lib/mtncloud/api/apps_interface.rb +180 -0
- data/lib/mtncloud/api/archive_buckets_interface.rb +116 -0
- data/lib/mtncloud/api/archive_files_interface.rb +173 -0
- data/lib/mtncloud/api/audit_interface.rb +9 -0
- data/lib/mtncloud/api/auth_interface.rb +58 -0
- data/lib/mtncloud/api/backup_jobs_interface.rb +13 -0
- data/lib/mtncloud/api/backup_restores_interface.rb +27 -0
- data/lib/mtncloud/api/backup_results_interface.rb +32 -0
- data/lib/mtncloud/api/backup_service_types_interface.rb +9 -0
- data/lib/mtncloud/api/backup_services_interface.rb +9 -0
- data/lib/mtncloud/api/backup_settings_interface.rb +20 -0
- data/lib/mtncloud/api/backup_types_interface.rb +9 -0
- data/lib/mtncloud/api/backups_interface.rb +21 -0
- data/lib/mtncloud/api/billing_interface.rb +34 -0
- data/lib/mtncloud/api/blueprints_interface.rb +70 -0
- data/lib/mtncloud/api/body_io.rb +22 -0
- data/lib/mtncloud/api/budgets_interface.rb +48 -0
- data/lib/mtncloud/api/catalog_item_types_interface.rb +29 -0
- data/lib/mtncloud/api/certificate_types_interface.rb +14 -0
- data/lib/mtncloud/api/certificates_interface.rb +9 -0
- data/lib/mtncloud/api/clients_interface.rb +41 -0
- data/lib/mtncloud/api/cloud_datastores_interface.rb +48 -0
- data/lib/mtncloud/api/cloud_folders_interface.rb +41 -0
- data/lib/mtncloud/api/cloud_policies_interface.rb +41 -0
- data/lib/mtncloud/api/cloud_resource_pools_interface.rb +66 -0
- data/lib/mtncloud/api/clouds_interface.rb +217 -0
- data/lib/mtncloud/api/clusters_interface.rb +471 -0
- data/lib/mtncloud/api/containers_interface.rb +145 -0
- data/lib/mtncloud/api/credential_types_interface.rb +9 -0
- data/lib/mtncloud/api/credentials_interface.rb +9 -0
- data/lib/mtncloud/api/custom_instance_types_interface.rb +99 -0
- data/lib/mtncloud/api/cypher_interface.rb +51 -0
- data/lib/mtncloud/api/dashboard_interface.rb +14 -0
- data/lib/mtncloud/api/datastores_interface.rb +21 -0
- data/lib/mtncloud/api/deploy_interface.rb +44 -0
- data/lib/mtncloud/api/deployments_interface.rb +79 -0
- data/lib/mtncloud/api/distributed_workers_interface.rb +41 -0
- data/lib/mtncloud/api/email_templates_interface.rb +53 -0
- data/lib/mtncloud/api/environments_interface.rb +48 -0
- data/lib/mtncloud/api/execute_schedules_interface.rb +71 -0
- data/lib/mtncloud/api/execution_request_interface.rb +27 -0
- data/lib/mtncloud/api/file_copy_request_interface.rb +68 -0
- data/lib/mtncloud/api/forgot_password_interface.rb +17 -0
- data/lib/mtncloud/api/group_policies_interface.rb +41 -0
- data/lib/mtncloud/api/groups_interface.rb +73 -0
- data/lib/mtncloud/api/guidance_interface.rb +44 -0
- data/lib/mtncloud/api/guidance_settings_interface.rb +17 -0
- data/lib/mtncloud/api/health_interface.rb +100 -0
- data/lib/mtncloud/api/host_vm_groups_interface.rb +37 -0
- data/lib/mtncloud/api/hub_interface.rb +25 -0
- data/lib/mtncloud/api/image_builder_boot_scripts_interface.rb +41 -0
- data/lib/mtncloud/api/image_builder_image_builds_interface.rb +73 -0
- data/lib/mtncloud/api/image_builder_interface.rb +20 -0
- data/lib/mtncloud/api/image_builder_preseed_scripts_interface.rb +41 -0
- data/lib/mtncloud/api/instance_types_interface.rb +20 -0
- data/lib/mtncloud/api/instances_interface.rb +453 -0
- data/lib/mtncloud/api/integration_types_interface.rb +14 -0
- data/lib/mtncloud/api/integrations_interface.rb +74 -0
- data/lib/mtncloud/api/invoice_line_items_interface.rb +9 -0
- data/lib/mtncloud/api/invoices_interface.rb +28 -0
- data/lib/mtncloud/api/jobs_interface.rb +83 -0
- data/lib/mtncloud/api/key_pairs_interface.rb +57 -0
- data/lib/mtncloud/api/library_cluster_layouts_interface.rb +47 -0
- data/lib/mtncloud/api/library_cluster_packages_interface.rb +60 -0
- data/lib/mtncloud/api/library_container_scripts_interface.rb +43 -0
- data/lib/mtncloud/api/library_container_templates_interface.rb +43 -0
- data/lib/mtncloud/api/library_container_types_interface.rb +59 -0
- data/lib/mtncloud/api/library_container_upgrades_interface.rb +60 -0
- data/lib/mtncloud/api/library_instance_types_interface.rb +74 -0
- data/lib/mtncloud/api/library_layouts_interface.rb +69 -0
- data/lib/mtncloud/api/library_operating_systems_interface.rb +63 -0
- data/lib/mtncloud/api/library_spec_template_types_interface.rb +43 -0
- data/lib/mtncloud/api/library_spec_templates_interface.rb +43 -0
- data/lib/mtncloud/api/license_interface.rb +30 -0
- data/lib/mtncloud/api/load_balancer_monitors_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_pool_nodes_interface.rb +8 -0
- data/lib/mtncloud/api/load_balancer_pools_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_pools_secondary_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_profiles_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_types_interface.rb +9 -0
- data/lib/mtncloud/api/load_balancer_virtual_servers_interface.rb +18 -0
- data/lib/mtncloud/api/load_balancers_interface.rb +14 -0
- data/lib/mtncloud/api/log_settings_interface.rb +44 -0
- data/lib/mtncloud/api/logs_interface.rb +37 -0
- data/lib/mtncloud/api/migrations_interface.rb +49 -0
- data/lib/mtncloud/api/monitoring_alerts_interface.rb +39 -0
- data/lib/mtncloud/api/monitoring_apps_interface.rb +69 -0
- data/lib/mtncloud/api/monitoring_checks_interface.rb +103 -0
- data/lib/mtncloud/api/monitoring_contacts_interface.rb +41 -0
- data/lib/mtncloud/api/monitoring_groups_interface.rb +77 -0
- data/lib/mtncloud/api/monitoring_incidents_interface.rb +107 -0
- data/lib/mtncloud/api/monitoring_interface.rb +35 -0
- data/lib/mtncloud/api/monitoring_settings_interface.rb +21 -0
- data/lib/mtncloud/api/network_dhcp_relays_interface.rb +36 -0
- data/lib/mtncloud/api/network_dhcp_servers_interface.rb +36 -0
- data/lib/mtncloud/api/network_domain_records_interface.rb +41 -0
- data/lib/mtncloud/api/network_domains_interface.rb +41 -0
- data/lib/mtncloud/api/network_edge_clusters_interface.rb +26 -0
- data/lib/mtncloud/api/network_floating_ips_interface.rb +40 -0
- data/lib/mtncloud/api/network_groups_interface.rb +41 -0
- data/lib/mtncloud/api/network_pool_ips_interface.rb +41 -0
- data/lib/mtncloud/api/network_pool_server_types_interface.rb +9 -0
- data/lib/mtncloud/api/network_pool_servers_interface.rb +48 -0
- data/lib/mtncloud/api/network_pools_interface.rb +41 -0
- data/lib/mtncloud/api/network_proxies_interface.rb +41 -0
- data/lib/mtncloud/api/network_routers_interface.rb +181 -0
- data/lib/mtncloud/api/network_security_server_types_interface.rb +9 -0
- data/lib/mtncloud/api/network_security_servers_interface.rb +27 -0
- data/lib/mtncloud/api/network_server_groups_interface.rb +7 -0
- data/lib/mtncloud/api/network_server_types_interface.rb +9 -0
- data/lib/mtncloud/api/network_servers_interface.rb +102 -0
- data/lib/mtncloud/api/network_services_interface.rb +63 -0
- data/lib/mtncloud/api/network_static_routes_interface.rb +36 -0
- data/lib/mtncloud/api/network_subnets_interface.rb +42 -0
- data/lib/mtncloud/api/network_types_interface.rb +20 -0
- data/lib/mtncloud/api/networks_interface.rb +48 -0
- data/lib/mtncloud/api/option_type_forms_interface.rb +9 -0
- data/lib/mtncloud/api/option_type_lists_interface.rb +53 -0
- data/lib/mtncloud/api/option_types_interface.rb +41 -0
- data/lib/mtncloud/api/options_interface.rb +17 -0
- data/lib/mtncloud/api/packages_interface.rb +112 -0
- data/lib/mtncloud/api/ping_interface.rb +22 -0
- data/lib/mtncloud/api/plugins_interface.rb +22 -0
- data/lib/mtncloud/api/policies_interface.rb +56 -0
- data/lib/mtncloud/api/power_schedules_interface.rb +71 -0
- data/lib/mtncloud/api/price_sets_interface.rb +39 -0
- data/lib/mtncloud/api/prices_interface.rb +71 -0
- data/lib/mtncloud/api/processes_interface.rb +40 -0
- data/lib/mtncloud/api/projects_interface.rb +33 -0
- data/lib/mtncloud/api/provision_types_interface.rb +24 -0
- data/lib/mtncloud/api/provisioning_license_types_interface.rb +31 -0
- data/lib/mtncloud/api/provisioning_licenses_interface.rb +60 -0
- data/lib/mtncloud/api/provisioning_settings_interface.rb +26 -0
- data/lib/mtncloud/api/read_interface.rb +24 -0
- data/lib/mtncloud/api/reports_interface.rb +70 -0
- data/lib/mtncloud/api/resource_pool_groups_interface.rb +51 -0
- data/lib/mtncloud/api/rest_interface.rb +37 -0
- data/lib/mtncloud/api/roles_interface.rb +151 -0
- data/lib/mtncloud/api/scale_thresholds_interface.rb +9 -0
- data/lib/mtncloud/api/search_interface.rb +13 -0
- data/lib/mtncloud/api/secondary_read_interface.rb +25 -0
- data/lib/mtncloud/api/secondary_rest_interface.rb +42 -0
- data/lib/mtncloud/api/security_group_rules_interface.rb +35 -0
- data/lib/mtncloud/api/security_groups_interface.rb +56 -0
- data/lib/mtncloud/api/security_package_types_interface.rb +9 -0
- data/lib/mtncloud/api/security_packages_interface.rb +9 -0
- data/lib/mtncloud/api/security_scans_interface.rb +9 -0
- data/lib/mtncloud/api/server_devices_interface.rb +30 -0
- data/lib/mtncloud/api/server_types_interface.rb +20 -0
- data/lib/mtncloud/api/servers_interface.rb +230 -0
- data/lib/mtncloud/api/service_catalog_interface.rb +89 -0
- data/lib/mtncloud/api/service_plans_interface.rb +62 -0
- data/lib/mtncloud/api/setup_interface.rb +46 -0
- data/lib/mtncloud/api/snapshots_interface.rb +19 -0
- data/lib/mtncloud/api/storage_datastores_interface.rb +44 -0
- data/lib/mtncloud/api/storage_providers_interface.rb +151 -0
- data/lib/mtncloud/api/storage_server_types_interface.rb +14 -0
- data/lib/mtncloud/api/storage_servers_interface.rb +9 -0
- data/lib/mtncloud/api/storage_volume_types_interface.rb +9 -0
- data/lib/mtncloud/api/storage_volumes_interface.rb +24 -0
- data/lib/mtncloud/api/subnet_types_interface.rb +20 -0
- data/lib/mtncloud/api/subnets_interface.rb +41 -0
- data/lib/mtncloud/api/support_bundles_interface.rb +46 -0
- data/lib/mtncloud/api/system_types_interface.rb +13 -0
- data/lib/mtncloud/api/systems_interface.rb +55 -0
- data/lib/mtncloud/api/task_sets_interface.rb +52 -0
- data/lib/mtncloud/api/tasks_interface.rb +66 -0
- data/lib/mtncloud/api/tokens_interface.rb +39 -0
- data/lib/mtncloud/api/usage_interface.rb +18 -0
- data/lib/mtncloud/api/user_groups_interface.rb +59 -0
- data/lib/mtncloud/api/user_settings_interface.rb +90 -0
- data/lib/mtncloud/api/user_sources_interface.rb +99 -0
- data/lib/mtncloud/api/users_interface.rb +33 -0
- data/lib/mtncloud/api/vdi_allocations_interface.rb +9 -0
- data/lib/mtncloud/api/vdi_apps_interface.rb +9 -0
- data/lib/mtncloud/api/vdi_gateways_interface.rb +9 -0
- data/lib/mtncloud/api/vdi_interface.rb +28 -0
- data/lib/mtncloud/api/vdi_pools_interface.rb +19 -0
- data/lib/mtncloud/api/virtual_images_interface.rb +210 -0
- data/lib/mtncloud/api/virtual_servers_interface.rb +9 -0
- data/lib/mtncloud/api/virtual_switches_interface.rb +9 -0
- data/lib/mtncloud/api/whitelabel_settings_interface.rb +57 -0
- data/lib/mtncloud/api/whoami_interface.rb +13 -0
- data/lib/mtncloud/api/wiki_interface.rb +48 -0
- data/lib/mtncloud/api.rb +12 -0
- data/lib/mtncloud/benchmarking.rb +259 -0
- data/lib/mtncloud/cli/cli_command.rb +2281 -0
- data/lib/mtncloud/cli/cli_registry.rb +337 -0
- data/lib/mtncloud/cli/commands/access_token_command.rb +201 -0
- data/lib/mtncloud/cli/commands/account_groups_command.rb +530 -0
- data/lib/mtncloud/cli/commands/activity_command.rb +149 -0
- data/lib/mtncloud/cli/commands/affinity_groups_command.rb +554 -0
- data/lib/mtncloud/cli/commands/alias_command.rb +278 -0
- data/lib/mtncloud/cli/commands/appliance_settings_command.rb +382 -0
- data/lib/mtncloud/cli/commands/approvals_command.rb +236 -0
- data/lib/mtncloud/cli/commands/apps.rb +2549 -0
- data/lib/mtncloud/cli/commands/archives_command.rb +2161 -0
- data/lib/mtncloud/cli/commands/audit.rb +188 -0
- data/lib/mtncloud/cli/commands/backup_jobs_command.rb +366 -0
- data/lib/mtncloud/cli/commands/backup_restores_command.rb +144 -0
- data/lib/mtncloud/cli/commands/backup_results_command.rb +149 -0
- data/lib/mtncloud/cli/commands/backup_services_command.rb +44 -0
- data/lib/mtncloud/cli/commands/backup_settings_command.rb +184 -0
- data/lib/mtncloud/cli/commands/backup_types_command.rb +53 -0
- data/lib/mtncloud/cli/commands/backups_command.rb +674 -0
- data/lib/mtncloud/cli/commands/benchmark_command.rb +458 -0
- data/lib/mtncloud/cli/commands/blueprints_command.rb +2297 -0
- data/lib/mtncloud/cli/commands/boot_scripts_command.rb +379 -0
- data/lib/mtncloud/cli/commands/budgets_command.rb +754 -0
- data/lib/mtncloud/cli/commands/cat_command.rb +45 -0
- data/lib/mtncloud/cli/commands/catalog_item_types_command.rb +858 -0
- data/lib/mtncloud/cli/commands/certificates_command.rb +575 -0
- data/lib/mtncloud/cli/commands/change_password_command.rb +132 -0
- data/lib/mtncloud/cli/commands/clients_command.rb +331 -0
- data/lib/mtncloud/cli/commands/cloud_datastores_command.rb +543 -0
- data/lib/mtncloud/cli/commands/cloud_folders_command.rb +512 -0
- data/lib/mtncloud/cli/commands/cloud_resource_pools_command.rb +870 -0
- data/lib/mtncloud/cli/commands/clouds.rb +2037 -0
- data/lib/mtncloud/cli/commands/clouds_types.rb +140 -0
- data/lib/mtncloud/cli/commands/cluster_types.rb +179 -0
- data/lib/mtncloud/cli/commands/clusters.rb +5855 -0
- data/lib/mtncloud/cli/commands/coloring_command.rb +82 -0
- data/lib/mtncloud/cli/commands/containers_command.rb +967 -0
- data/lib/mtncloud/cli/commands/credential_types_command.rb +36 -0
- data/lib/mtncloud/cli/commands/credentials_command.rb +124 -0
- data/lib/mtncloud/cli/commands/curl_command.rb +168 -0
- data/lib/mtncloud/cli/commands/cypher_command.rb +587 -0
- data/lib/mtncloud/cli/commands/dashboard_command.rb +300 -0
- data/lib/mtncloud/cli/commands/debug_command.rb +75 -0
- data/lib/mtncloud/cli/commands/deploy.rb +485 -0
- data/lib/mtncloud/cli/commands/deployments.rb +923 -0
- data/lib/mtncloud/cli/commands/deploys.rb +485 -0
- data/lib/mtncloud/cli/commands/distributed_workers_command.rb +282 -0
- data/lib/mtncloud/cli/commands/echo_command.rb +61 -0
- data/lib/mtncloud/cli/commands/edit_profile_command.rb +57 -0
- data/lib/mtncloud/cli/commands/edit_rc_command.rb +77 -0
- data/lib/mtncloud/cli/commands/email_templates_command.rb +373 -0
- data/lib/mtncloud/cli/commands/environments_command.rb +401 -0
- data/lib/mtncloud/cli/commands/execute_schedules_command.rb +735 -0
- data/lib/mtncloud/cli/commands/execution_request_command.rb +333 -0
- data/lib/mtncloud/cli/commands/exit_command.rb +34 -0
- data/lib/mtncloud/cli/commands/file_copy_request_command.rb +352 -0
- data/lib/mtncloud/cli/commands/forgot_password.rb +133 -0
- data/lib/mtncloud/cli/commands/get_prompt_command.rb +36 -0
- data/lib/mtncloud/cli/commands/groups.rb +818 -0
- data/lib/mtncloud/cli/commands/guidance_command.rb +529 -0
- data/lib/mtncloud/cli/commands/guidance_settings.rb +148 -0
- data/lib/mtncloud/cli/commands/health_command.rb +1046 -0
- data/lib/mtncloud/cli/commands/history_command.rb +60 -0
- data/lib/mtncloud/cli/commands/host_vm_groups_command.rb +423 -0
- data/lib/mtncloud/cli/commands/hosts.rb +2986 -0
- data/lib/mtncloud/cli/commands/hub.rb +215 -0
- data/lib/mtncloud/cli/commands/image_builder_command.rb +1197 -0
- data/lib/mtncloud/cli/commands/instance_types.rb +163 -0
- data/lib/mtncloud/cli/commands/instances.rb +5813 -0
- data/lib/mtncloud/cli/commands/integrations_command.rb +1412 -0
- data/lib/mtncloud/cli/commands/invoices_command.rb +1151 -0
- data/lib/mtncloud/cli/commands/jobs_command.rb +998 -0
- data/lib/mtncloud/cli/commands/key_pairs.rb +470 -0
- data/lib/mtncloud/cli/commands/library_cluster_layouts_command.rb +901 -0
- data/lib/mtncloud/cli/commands/library_cluster_packages_command.rb +552 -0
- data/lib/mtncloud/cli/commands/library_container_scripts_command.rb +446 -0
- data/lib/mtncloud/cli/commands/library_container_templates_command.rb +526 -0
- data/lib/mtncloud/cli/commands/library_container_types_command.rb +698 -0
- data/lib/mtncloud/cli/commands/library_forms_command.rb +625 -0
- data/lib/mtncloud/cli/commands/library_instance_types_command.rb +668 -0
- data/lib/mtncloud/cli/commands/library_layouts_command.rb +849 -0
- data/lib/mtncloud/cli/commands/library_operating_systems_command.rb +671 -0
- data/lib/mtncloud/cli/commands/library_option_lists_command.rb +503 -0
- data/lib/mtncloud/cli/commands/library_option_types_command.rb +329 -0
- data/lib/mtncloud/cli/commands/library_spec_templates_command.rb +547 -0
- data/lib/mtncloud/cli/commands/library_upgrades_command.rb +596 -0
- data/lib/mtncloud/cli/commands/license.rb +475 -0
- data/lib/mtncloud/cli/commands/load_balancer_monitors.rb +70 -0
- data/lib/mtncloud/cli/commands/load_balancer_pool_nodes.rb +87 -0
- data/lib/mtncloud/cli/commands/load_balancer_pools.rb +129 -0
- data/lib/mtncloud/cli/commands/load_balancer_profiles.rb +64 -0
- data/lib/mtncloud/cli/commands/load_balancer_types.rb +38 -0
- data/lib/mtncloud/cli/commands/load_balancer_virtual_servers.rb +147 -0
- data/lib/mtncloud/cli/commands/load_balancers.rb +189 -0
- data/lib/mtncloud/cli/commands/log_level_command.rb +54 -0
- data/lib/mtncloud/cli/commands/log_settings_command.rb +443 -0
- data/lib/mtncloud/cli/commands/login.rb +148 -0
- data/lib/mtncloud/cli/commands/logout.rb +63 -0
- data/lib/mtncloud/cli/commands/logs_command.rb +140 -0
- data/lib/mtncloud/cli/commands/man_command.rb +409 -0
- data/lib/mtncloud/cli/commands/migrations.rb +453 -0
- data/lib/mtncloud/cli/commands/monitoring_alerts_command.rb +791 -0
- data/lib/mtncloud/cli/commands/monitoring_apps_command.rb +716 -0
- data/lib/mtncloud/cli/commands/monitoring_checks_command.rb +766 -0
- data/lib/mtncloud/cli/commands/monitoring_contacts_command.rb +339 -0
- data/lib/mtncloud/cli/commands/monitoring_groups_command.rb +674 -0
- data/lib/mtncloud/cli/commands/monitoring_incidents_command.rb +835 -0
- data/lib/mtncloud/cli/commands/monitoring_settings.rb +212 -0
- data/lib/mtncloud/cli/commands/network_dhcp_relays_command.rb +375 -0
- data/lib/mtncloud/cli/commands/network_dhcp_servers_command.rb +366 -0
- data/lib/mtncloud/cli/commands/network_domains_command.rb +896 -0
- data/lib/mtncloud/cli/commands/network_edge_clusters_command.rb +288 -0
- data/lib/mtncloud/cli/commands/network_firewalls_command.rb +783 -0
- data/lib/mtncloud/cli/commands/network_floating_ips.rb +147 -0
- data/lib/mtncloud/cli/commands/network_groups_command.rb +654 -0
- data/lib/mtncloud/cli/commands/network_pool_server_types.rb +20 -0
- data/lib/mtncloud/cli/commands/network_pool_servers_command.rb +318 -0
- data/lib/mtncloud/cli/commands/network_pools_command.rb +903 -0
- data/lib/mtncloud/cli/commands/network_proxies_command.rb +578 -0
- data/lib/mtncloud/cli/commands/network_routers_command.rb +2628 -0
- data/lib/mtncloud/cli/commands/network_security_server_types.rb +20 -0
- data/lib/mtncloud/cli/commands/network_server_groups_command.rb +222 -0
- data/lib/mtncloud/cli/commands/network_server_types_command.rb +20 -0
- data/lib/mtncloud/cli/commands/network_servers_command.rb +398 -0
- data/lib/mtncloud/cli/commands/network_services_command.rb +198 -0
- data/lib/mtncloud/cli/commands/network_static_routes_command.rb +451 -0
- data/lib/mtncloud/cli/commands/network_transport_zones_command.rb +412 -0
- data/lib/mtncloud/cli/commands/networks_command.rb +1692 -0
- data/lib/mtncloud/cli/commands/open_command.rb +30 -0
- data/lib/mtncloud/cli/commands/options.rb +231 -0
- data/lib/mtncloud/cli/commands/packages_command.rb +822 -0
- data/lib/mtncloud/cli/commands/ping.rb +242 -0
- data/lib/mtncloud/cli/commands/plugins.rb +214 -0
- data/lib/mtncloud/cli/commands/policies_command.rb +990 -0
- data/lib/mtncloud/cli/commands/power_schedules_command.rb +731 -0
- data/lib/mtncloud/cli/commands/preseed_scripts_command.rb +378 -0
- data/lib/mtncloud/cli/commands/price_sets_command.rb +557 -0
- data/lib/mtncloud/cli/commands/prices_command.rb +692 -0
- data/lib/mtncloud/cli/commands/processes_command.rb +469 -0
- data/lib/mtncloud/cli/commands/projects_command.rb +537 -0
- data/lib/mtncloud/cli/commands/provisioning_licenses_command.rb +509 -0
- data/lib/mtncloud/cli/commands/provisioning_settings_command.rb +238 -0
- data/lib/mtncloud/cli/commands/recent_activity_command.rb +171 -0
- data/lib/mtncloud/cli/commands/remote.rb +1818 -0
- data/lib/mtncloud/cli/commands/reports_command.rb +724 -0
- data/lib/mtncloud/cli/commands/resource_pool_groups_command.rb +586 -0
- data/lib/mtncloud/cli/commands/rm_command.rb +14 -0
- data/lib/mtncloud/cli/commands/roles.rb +3120 -0
- data/lib/mtncloud/cli/commands/scale_thresholds.rb +103 -0
- data/lib/mtncloud/cli/commands/search_command.rb +184 -0
- data/lib/mtncloud/cli/commands/security_group_rules.rb +230 -0
- data/lib/mtncloud/cli/commands/security_groups.rb +1294 -0
- data/lib/mtncloud/cli/commands/security_package_types.rb +32 -0
- data/lib/mtncloud/cli/commands/security_packages.rb +84 -0
- data/lib/mtncloud/cli/commands/security_scans.rb +107 -0
- data/lib/mtncloud/cli/commands/self_service_command.rb +17 -0
- data/lib/mtncloud/cli/commands/server_devices_command.rb +207 -0
- data/lib/mtncloud/cli/commands/service_catalog_command.rb +1528 -0
- data/lib/mtncloud/cli/commands/service_plans_command.rb +895 -0
- data/lib/mtncloud/cli/commands/set_prompt_command.rb +51 -0
- data/lib/mtncloud/cli/commands/setup.rb +423 -0
- data/lib/mtncloud/cli/commands/shell.rb +717 -0
- data/lib/mtncloud/cli/commands/sleep_command.rb +43 -0
- data/lib/mtncloud/cli/commands/snapshots.rb +156 -0
- data/lib/mtncloud/cli/commands/source_command.rb +30 -0
- data/lib/mtncloud/cli/commands/ssl_verification_command.rb +47 -0
- data/lib/mtncloud/cli/commands/storage_datastores.rb +457 -0
- data/lib/mtncloud/cli/commands/storage_providers_command.rb +1401 -0
- data/lib/mtncloud/cli/commands/storage_server_types.rb +45 -0
- data/lib/mtncloud/cli/commands/storage_servers.rb +116 -0
- data/lib/mtncloud/cli/commands/storage_volume_types.rb +45 -0
- data/lib/mtncloud/cli/commands/storage_volumes.rb +236 -0
- data/lib/mtncloud/cli/commands/subnets_command.rb +819 -0
- data/lib/mtncloud/cli/commands/support_bundles_command.rb +606 -0
- data/lib/mtncloud/cli/commands/systems.rb +1203 -0
- data/lib/mtncloud/cli/commands/tasks.rb +1391 -0
- data/lib/mtncloud/cli/commands/tee_command.rb +14 -0
- data/lib/mtncloud/cli/commands/tenants_command.rb +315 -0
- data/lib/mtncloud/cli/commands/tokens_command.rb +391 -0
- data/lib/mtncloud/cli/commands/update_command.rb +46 -0
- data/lib/mtncloud/cli/commands/usage_command.rb +203 -0
- data/lib/mtncloud/cli/commands/user_groups_command.rb +512 -0
- data/lib/mtncloud/cli/commands/user_settings_command.rb +849 -0
- data/lib/mtncloud/cli/commands/user_sources_command.rb +1065 -0
- data/lib/mtncloud/cli/commands/users.rb +897 -0
- data/lib/mtncloud/cli/commands/vdi_allocations_command.rb +159 -0
- data/lib/mtncloud/cli/commands/vdi_apps_command.rb +317 -0
- data/lib/mtncloud/cli/commands/vdi_command.rb +359 -0
- data/lib/mtncloud/cli/commands/vdi_gateways_command.rb +290 -0
- data/lib/mtncloud/cli/commands/vdi_pools_command.rb +574 -0
- data/lib/mtncloud/cli/commands/version_command.rb +38 -0
- data/lib/mtncloud/cli/commands/view.rb +107 -0
- data/lib/mtncloud/cli/commands/virtual_images.rb +1362 -0
- data/lib/mtncloud/cli/commands/virtual_switches_command.rb +336 -0
- data/lib/mtncloud/cli/commands/whitelabel_settings_command.rb +653 -0
- data/lib/mtncloud/cli/commands/whoami.rb +323 -0
- data/lib/mtncloud/cli/commands/wiki_command.rb +448 -0
- data/lib/mtncloud/cli/commands/workflows.rb +1022 -0
- data/lib/mtncloud/cli/credentials.rb +482 -0
- data/lib/mtncloud/cli/dot_file.rb +180 -0
- data/lib/mtncloud/cli/error_handler.rb +307 -0
- data/lib/mtncloud/cli/errors.rb +53 -0
- data/lib/mtncloud/cli/expression_parser.rb +153 -0
- data/lib/mtncloud/cli/mixins/accounts_helper.rb +484 -0
- data/lib/mtncloud/cli/mixins/affinity_helper.rb +118 -0
- data/lib/mtncloud/cli/mixins/backups_helper.rb +200 -0
- data/lib/mtncloud/cli/mixins/deployments_helper.rb +163 -0
- data/lib/mtncloud/cli/mixins/execution_request_helper.rb +50 -0
- data/lib/mtncloud/cli/mixins/infrastructure_helper.rb +966 -0
- data/lib/mtncloud/cli/mixins/jobs_helper.rb +202 -0
- data/lib/mtncloud/cli/mixins/library_helper.rb +539 -0
- data/lib/mtncloud/cli/mixins/load_balancers_helper.rb +176 -0
- data/lib/mtncloud/cli/mixins/logs_helper.rb +131 -0
- data/lib/mtncloud/cli/mixins/monitoring_helper.rb +876 -0
- data/lib/mtncloud/cli/mixins/networks_helper.rb +62 -0
- data/lib/mtncloud/cli/mixins/operations_helper.rb +41 -0
- data/lib/mtncloud/cli/mixins/option_source_helper.rb +254 -0
- data/lib/mtncloud/cli/mixins/print_helper.rb +1631 -0
- data/lib/mtncloud/cli/mixins/processes_helper.rb +286 -0
- data/lib/mtncloud/cli/mixins/prompt_helper.rb +136 -0
- data/lib/mtncloud/cli/mixins/provisioning_helper.rb +2963 -0
- data/lib/mtncloud/cli/mixins/remote_helper.rb +139 -0
- data/lib/mtncloud/cli/mixins/rest_command.rb +994 -0
- data/lib/mtncloud/cli/mixins/secondary_rest_command.rb +700 -0
- data/lib/mtncloud/cli/mixins/storage_servers_helper.rb +93 -0
- data/lib/mtncloud/cli/mixins/storage_volumes_helper.rb +76 -0
- data/lib/mtncloud/cli/mixins/vdi_helper.rb +246 -0
- data/lib/mtncloud/cli/mixins/whoami_helper.rb +73 -0
- data/lib/mtncloud/cli/option_parser.rb +127 -0
- data/lib/mtncloud/cli/option_types.rb +1622 -0
- data/lib/mtncloud/cli/version.rb +6 -0
- data/lib/mtncloud/cli.rb +105 -0
- data/lib/mtncloud/currency.rb +184 -0
- data/lib/mtncloud/ext/hash.rb +109 -0
- data/lib/mtncloud/ext/nil_class.rb +5 -0
- data/lib/mtncloud/ext/rest_client.rb +37 -0
- data/lib/mtncloud/ext/string.rb +66 -0
- data/lib/mtncloud/formatters.rb +511 -0
- data/lib/mtncloud/logging.rb +185 -0
- data/lib/mtncloud/morpkg.rb +119 -0
- data/lib/mtncloud/rest_client.rb +104 -0
- data/lib/mtncloud/routes.rb +304 -0
- data/lib/mtncloud/terminal.rb +528 -0
- data/lib/mtncloud/util.rb +29 -0
- data/lib/mtncloud.rb +5 -0
- data/mtncloud-cli.gemspec +38 -0
- data/test/api/affinity_groups_interface_test.rb +43 -0
- data/test/api/clients_interface_test.rb +23 -0
- data/test/api/clouds_interface_test.rb +67 -0
- data/test/api/containers_interface_test.rb +68 -0
- data/test/api/host_vm_groups_interface_test.rb +35 -0
- data/test/api/instances_interface_test.rb +22 -0
- data/test/api/network_routers_interface_test.rb +22 -0
- data/test/api/systems_interface_test.rb +26 -0
- data/test/api/whoami_interface_test.rb +14 -0
- data/test/branding_test.rb +160 -0
- data/test/cli/access_token_test.rb +36 -0
- data/test/cli/affinity_groups_cloud_cluster_scope_test.rb +270 -0
- data/test/cli/affinity_groups_cluster_scope_test.rb +171 -0
- data/test/cli/affinity_groups_test.rb +57 -0
- data/test/cli/affinity_groups_violations_scope_test.rb +141 -0
- data/test/cli/affinity_helper_test.rb +367 -0
- data/test/cli/auth_test.rb +88 -0
- data/test/cli/backups_test.rb +212 -0
- data/test/cli/cli_test.rb +48 -0
- data/test/cli/clients_test.rb +45 -0
- data/test/cli/clusters_uuid_test.rb +146 -0
- data/test/cli/containers_test.rb +92 -0
- data/test/cli/distributed_workers_test.rb +68 -0
- data/test/cli/help_test.rb +25 -0
- data/test/cli/host_vm_groups_cluster_scope_test.rb +187 -0
- data/test/cli/host_vm_groups_test.rb +63 -0
- data/test/cli/infrastructure_helper_cluster_resolver_test.rb +250 -0
- data/test/cli/instances_test.rb +37 -0
- data/test/cli/man_test.rb +14 -0
- data/test/cli/migrations_test.rb +39 -0
- data/test/cli/network_routers_test.rb +65 -0
- data/test/cli/remote_test.rb +89 -0
- data/test/cli/roles_test.rb +47 -0
- data/test/cli/shell_test.rb +81 -0
- data/test/cli/storage_volumes_test.rb +79 -0
- data/test/cli/systems_test.rb +206 -0
- data/test/cli/version_test.rb +23 -0
- data/test/cli/view_test.rb +55 -0
- data/test/cli/whoami_test.rb +17 -0
- data/test/mtncloud_test.rb +16 -0
- data/test/test_case.rb +342 -0
- data/test/test_config.rb +137 -0
- data/test/test_data_helper.rb +97 -0
- metadata +807 -0
|
@@ -0,0 +1,994 @@
|
|
|
1
|
+
# RestCommand is a mixin for MtnCloud::Cli command classes.
|
|
2
|
+
# Provides basic CRUD commands: list, get, add, update, remove
|
|
3
|
+
# Currently the command class must also include MtnCloud::Cli::CliCommand
|
|
4
|
+
# The command class can define a few variables to dictate what the resource
|
|
5
|
+
# is called and the the api interface used to fetch the records. The command class
|
|
6
|
+
# or helper must also provide several methods to provide the default behavior.
|
|
7
|
+
# In the example below, the command (helper) defines the following methods:
|
|
8
|
+
# * load_balancer_object_key() - Key name of object returned by the "get" api endpoint.
|
|
9
|
+
# * load_balancer_list_key() - Key name of array of records returned by the "list" api endpoint.
|
|
10
|
+
# * load_balancer_column_definitions() - Column definitions for the "get" command display output.
|
|
11
|
+
# * load_balancer_list_column_definitions() - Column definitions for the "list" command display output.
|
|
12
|
+
#
|
|
13
|
+
# Example of a RestCommand for `mtncloud load-balancers`.
|
|
14
|
+
#
|
|
15
|
+
# class MtnCloud::Cli::LoadBalancers
|
|
16
|
+
#
|
|
17
|
+
# include MtnCloud::Cli::CliCommand
|
|
18
|
+
# include MtnCloud::Cli::RestCommand
|
|
19
|
+
# include MtnCloud::Cli::LoadBalancersHelper
|
|
20
|
+
#
|
|
21
|
+
# # All of the example settings below are redundant
|
|
22
|
+
# # and would be the default values if not set.
|
|
23
|
+
# set_rest_name :load_balancers
|
|
24
|
+
# set_rest_label "Load Balancer"
|
|
25
|
+
# set_rest_label_plural "Load Balancers"
|
|
26
|
+
# set_rest_object_key "load_balancer"
|
|
27
|
+
# set_rest_has_type true
|
|
28
|
+
# set_rest_type "load_balancer_types"
|
|
29
|
+
# register_interfaces :load_balancers, :load_balancer_types
|
|
30
|
+
#
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
module MtnCloud::Cli::RestCommand
|
|
34
|
+
def self.included(base)
|
|
35
|
+
#puts "including RestCommand for #{base}"
|
|
36
|
+
#base.send :include, MtnCloud::Cli::CliCommand
|
|
37
|
+
base.extend ClassMethods
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module ClassMethods
|
|
41
|
+
|
|
42
|
+
# rest_name is the plural name of the resource eg. NeatThings would be "neat_things"
|
|
43
|
+
# It is used to derive all other default rest settings key, label, etc.
|
|
44
|
+
# The default name the command name with underscores `_` instead of dashes `-`.
|
|
45
|
+
def rest_name
|
|
46
|
+
defined?(@rest_name) ? @rest_name : default_rest_name
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def default_rest_name
|
|
50
|
+
self.command_name.to_s.gsub("-", "_")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def rest_name=(v)
|
|
54
|
+
@rest_name = v.to_s
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
alias :set_rest_name :rest_name=
|
|
58
|
+
|
|
59
|
+
# rest_key is the singular name of the resource eg. "neat_thing"
|
|
60
|
+
def rest_key
|
|
61
|
+
defined?(@rest_key) ? @rest_key : default_rest_key
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def default_rest_key
|
|
65
|
+
rest_name.to_s.chomp("s")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def rest_key=(v)
|
|
69
|
+
@rest_key = v.to_s
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
alias :set_rest_key :rest_key=
|
|
73
|
+
|
|
74
|
+
# rest_arg is a label for the arg in the command usage eg. "thing" gets displayed as [thing]
|
|
75
|
+
def rest_arg
|
|
76
|
+
defined?(@rest_arg) ? @rest_arg : default_rest_arg
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def default_rest_arg
|
|
80
|
+
rest_key.gsub("_", " ") # "[" + rest_key.gsub("_", " ") + "]"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def rest_arg=(v)
|
|
84
|
+
@rest_arg = v.to_s
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
alias :set_rest_arg :rest_arg=
|
|
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
|
+
defined?(@rest_has_name) ? @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
|
+
|
|
105
|
+
# rest_label is the capitalized resource label eg. "Neat Thing"
|
|
106
|
+
def rest_label
|
|
107
|
+
defined?(@rest_label) ? @rest_label : default_rest_label
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def default_rest_label
|
|
111
|
+
rest_key.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def rest_label=(v)
|
|
115
|
+
@rest_label = v.to_s
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
alias :set_rest_label :rest_label=
|
|
119
|
+
|
|
120
|
+
# the plural version of the label eg. "Neat Things"
|
|
121
|
+
def rest_label_plural
|
|
122
|
+
defined?(@rest_label_plural) ? @rest_label_plural : default_rest_label_plural
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def default_rest_label_plural
|
|
126
|
+
#rest_name.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
|
|
127
|
+
rest_label.to_s.pluralize
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def rest_label_plural=(v)
|
|
131
|
+
@rest_label_plural = v.to_s
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
alias :set_rest_label_plural :rest_label_plural=
|
|
135
|
+
|
|
136
|
+
# rest_interface_name is the interface name for the resource. eg. "neat_things"
|
|
137
|
+
def rest_interface_name
|
|
138
|
+
defined?(@rest_interface_name) ? @rest_interface_name : default_rest_interface_name
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def default_rest_interface_name
|
|
142
|
+
rest_name
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def rest_interface_name=(v)
|
|
146
|
+
@rest_interface_name = v.to_s
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
alias :set_rest_interface_name :rest_interface_name=
|
|
150
|
+
|
|
151
|
+
# rest_perms_config enables and configures permissions prompt
|
|
152
|
+
def rest_perms_config
|
|
153
|
+
defined?(@rest_perms_config) ? @rest_perms_config : {}
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def rest_perms_config=(v)
|
|
157
|
+
@rest_perms_config = v
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
alias :set_rest_perms_config :rest_perms_config=
|
|
161
|
+
|
|
162
|
+
# rest_option_context_map specifies context mapping during option prompt. default is domain => ''
|
|
163
|
+
def rest_option_context_map
|
|
164
|
+
defined?(@option_context_map) ? @option_context_map : {'domain' => ''}
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def rest_option_context_map=(v)
|
|
168
|
+
@option_context_map = v
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
alias :set_rest_option_context_map :rest_option_context_map=
|
|
172
|
+
|
|
173
|
+
# rest_has_type indicates a resource has a type. default is false
|
|
174
|
+
def rest_has_type
|
|
175
|
+
defined?(@rest_has_type) && @rest_has_type
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def default_rest_has_type
|
|
179
|
+
false
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def rest_has_type=(v)
|
|
183
|
+
@rest_has_type = !!v
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
alias :set_rest_has_type :rest_has_type=
|
|
187
|
+
|
|
188
|
+
## duplicated the rest_* settings with rest_type, for the types resource
|
|
189
|
+
|
|
190
|
+
# rest_type_name is the rest_name for the type, only applicable if rest_has_type
|
|
191
|
+
def rest_type_name
|
|
192
|
+
defined?(@rest_type_name) ? @rest_type_name : default_rest_type_name
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def default_rest_type_name
|
|
196
|
+
rest_key + "_types"
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def rest_type_name=(v)
|
|
200
|
+
@rest_type_name = v.to_s
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
alias :set_rest_type_name :rest_type_name=
|
|
204
|
+
alias :set_rest_type :rest_type_name=
|
|
205
|
+
#alias :rest_type= :rest_type_name=
|
|
206
|
+
|
|
207
|
+
# rest_type_key is the singular name of the resource eg. "neat_thing"
|
|
208
|
+
def rest_type_key
|
|
209
|
+
defined?(@rest_type_key) ? @rest_type_key : default_rest_type_key
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def default_rest_type_key
|
|
213
|
+
rest_type_name.chomp("s")
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def rest_type_key=(v)
|
|
217
|
+
@rest_type_key = v.to_s
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
alias :set_rest_type_key :rest_type_key=
|
|
221
|
+
|
|
222
|
+
def rest_type_arg
|
|
223
|
+
defined?(@rest_type_arg) ? @rest_type_arg : default_rest_type_arg
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def default_rest_type_arg
|
|
227
|
+
# rest_type_key.gsub("_", " ") # "[" + rest_key.gsub("_", " ") + "]"
|
|
228
|
+
"type" # [type]
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def rest_type_arg=(v)
|
|
232
|
+
@rest_type_arg = v.to_s
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
alias :set_rest_type_arg :rest_type_arg=
|
|
236
|
+
|
|
237
|
+
# rest_type_label is the capitalized resource label eg. "Neat Thing"
|
|
238
|
+
def rest_type_label
|
|
239
|
+
defined?(@rest_type_label) ? @rest_type_label : default_rest_type_label
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def default_rest_type_label
|
|
243
|
+
rest_type_key.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def rest_type_label=(v)
|
|
247
|
+
@rest_type_label = v.to_s
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
alias :set_rest_type_label :rest_type_label=
|
|
251
|
+
|
|
252
|
+
# the plural version of the label eg. "Neat Things"
|
|
253
|
+
def rest_type_label_plural
|
|
254
|
+
defined?(@rest_type_label_plural) ? @rest_type_label_plural : default_rest_type_label_plural
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def default_rest_type_label_plural
|
|
258
|
+
#rest_type_name.to_s.split("_").collect {|it| it.to_s.capitalize }.join(" ")
|
|
259
|
+
rest_type_label.to_s.pluralize
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def rest_type_label_plural=(v)
|
|
263
|
+
@rest_type_label_plural = v.to_s
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
alias :set_rest_type_label_plural :rest_type_label_plural=
|
|
267
|
+
|
|
268
|
+
# the name of the default interface, matches the rest name eg. "neat_things"
|
|
269
|
+
def rest_type_interface_name
|
|
270
|
+
defined?(@rest_type_interface_name) ? @rest_type_interface_name : default_rest_type_interface_name
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def default_rest_type_interface_name
|
|
274
|
+
rest_type_name
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def rest_type_interface_name=(v)
|
|
278
|
+
@rest_type_interface_name = v.to_s
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
alias :set_rest_type_interface_name :rest_type_interface_name=
|
|
282
|
+
|
|
283
|
+
# set or append to the list of interface names to register for this command
|
|
284
|
+
# The registered interfaces will be pre-loaded into instance variables
|
|
285
|
+
# eg. [:neat_things, :neat_thing_types] will instantiate @neat_things_interface and @neat_thing_types_interface
|
|
286
|
+
def register_interfaces(*interfaces)
|
|
287
|
+
@registered_interfaces ||= []
|
|
288
|
+
interfaces.flatten.each do |it|
|
|
289
|
+
@registered_interfaces << it.to_s
|
|
290
|
+
end
|
|
291
|
+
# put the default rest_interface first
|
|
292
|
+
if rest_interface_name && !@registered_interfaces.include?(rest_interface_name)
|
|
293
|
+
@registered_interfaces.unshift(rest_interface_name)
|
|
294
|
+
end
|
|
295
|
+
# and also the rest_type_interface
|
|
296
|
+
if rest_has_type && !@registered_interfaces.include?(rest_type_interface_name)
|
|
297
|
+
@registered_interfaces.unshift(rest_type_interface_name)
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
alias :register_interface :register_interfaces
|
|
302
|
+
|
|
303
|
+
# get list of interface names that are registered for this command
|
|
304
|
+
# automatically includes the interface for the rest_name and rest_type_name if has_type
|
|
305
|
+
def registered_interfaces
|
|
306
|
+
@registered_interfaces ||= []
|
|
307
|
+
# put the default rest_interface first
|
|
308
|
+
if @registered_interfaces.empty?
|
|
309
|
+
if rest_interface_name
|
|
310
|
+
@registered_interfaces.unshift(rest_interface_name)
|
|
311
|
+
end
|
|
312
|
+
if rest_has_type
|
|
313
|
+
@registered_interfaces.unshift(rest_type_interface_name)
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
@registered_interfaces
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
# clear the list of registered interfaces, perhaps useful in a command subclass
|
|
320
|
+
def clear_registered_interfaces()
|
|
321
|
+
@registered_interfaces = []
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
def rest_name
|
|
327
|
+
self.class.rest_name
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def rest_key
|
|
331
|
+
self.class.rest_key
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def rest_arg
|
|
335
|
+
self.class.rest_arg
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
def rest_has_name
|
|
339
|
+
self.class.rest_has_name
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
def rest_label
|
|
343
|
+
self.class.rest_label
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def rest_label_plural
|
|
347
|
+
self.class.rest_label_plural
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
def rest_interface_name
|
|
351
|
+
self.class.rest_interface_name
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def rest_perms_config
|
|
355
|
+
self.class.rest_perms_config
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
def rest_option_context_map
|
|
359
|
+
self.class.rest_option_context_map
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
# returns the default rest interface, allows using rest_interface_name = "your"
|
|
363
|
+
# or override this method to return @your_interface if needed
|
|
364
|
+
def rest_interface
|
|
365
|
+
instance_variable_get("@#{rest_interface_name}_interface")
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def rest_object_key
|
|
369
|
+
if respond_to?("#{rest_key}_object_key", true)
|
|
370
|
+
send("#{rest_key}_object_key")
|
|
371
|
+
else
|
|
372
|
+
rest_name.camelcase.singularize
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
def rest_list_key
|
|
377
|
+
if respond_to?("#{rest_key}_list_key", true)
|
|
378
|
+
send("#{rest_key}_list_key")
|
|
379
|
+
else
|
|
380
|
+
rest_name.camelcase
|
|
381
|
+
end
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
def rest_column_definitions(options)
|
|
385
|
+
send("#{rest_key}_column_definitions", options)
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
def rest_list_column_definitions(options)
|
|
389
|
+
send("#{rest_key}_list_column_definitions", options)
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
def rest_find_by_name_or_id(val)
|
|
393
|
+
# use explicitly defined finders
|
|
394
|
+
# else default to new generic CliCommand method to find anything by type (singular underscore)
|
|
395
|
+
if rest_has_name
|
|
396
|
+
if respond_to?("find_#{rest_key}_by_name_or_id", true)
|
|
397
|
+
send("find_#{rest_key}_by_name_or_id", val)
|
|
398
|
+
else
|
|
399
|
+
find_by_name_or_id(rest_key, val)
|
|
400
|
+
end
|
|
401
|
+
else
|
|
402
|
+
if respond_to?("find_#{rest_key}_by_id", true)
|
|
403
|
+
send("find_#{rest_key}_by_id", val)
|
|
404
|
+
else
|
|
405
|
+
find_by_id(rest_key, val)
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def rest_has_type
|
|
411
|
+
self.class.rest_has_type
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
## duplicated the rest_* settings with rest_type, for the types resource
|
|
415
|
+
|
|
416
|
+
def rest_type_name
|
|
417
|
+
self.class.rest_type_name
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
def rest_type_key
|
|
421
|
+
self.class.rest_type_key
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
def rest_type_arg
|
|
425
|
+
self.class.rest_type_arg
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
def rest_type_label
|
|
429
|
+
self.class.rest_type_label
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
def rest_type_label_plural
|
|
433
|
+
self.class.rest_type_label_plural
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
def rest_type_interface_name
|
|
437
|
+
self.class.rest_type_interface_name # || "@#{rest_type_name}_interface"
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
def rest_type_interface
|
|
441
|
+
instance_variable_get("@#{rest_type_interface_name}_interface")
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
def rest_type_object_key
|
|
445
|
+
if respond_to?("#{rest_type_key}_object_key", true)
|
|
446
|
+
send("#{rest_type_key}_object_key")
|
|
447
|
+
else
|
|
448
|
+
rest_type_name.camelcase.singularize
|
|
449
|
+
end
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
def rest_type_list_key
|
|
453
|
+
if respond_to?("#{rest_type_key}_list_key", true)
|
|
454
|
+
send("#{rest_type_key}_list_key")
|
|
455
|
+
else
|
|
456
|
+
rest_type_name.camelcase
|
|
457
|
+
end
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
def rest_type_column_definitions(options)
|
|
461
|
+
send("#{rest_type_key}_column_definitions", options)
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
def rest_type_list_column_definitions(options)
|
|
465
|
+
send("#{rest_type_key}_list_column_definitions", options)
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
def rest_type_find_by_name_or_id(val)
|
|
469
|
+
# use explicately defined finders
|
|
470
|
+
# else default to new generic CliCommand method to find anything by type (singular underscore)
|
|
471
|
+
if respond_to?("find_#{rest_type_key}_by_name_or_id", true)
|
|
472
|
+
send("find_#{rest_type_key}_by_name_or_id", val)
|
|
473
|
+
else
|
|
474
|
+
find_by_name_or_id(rest_type_key, val)
|
|
475
|
+
end
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
def registered_interfaces
|
|
479
|
+
self.class.registered_interfaces
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
# standard connect method to establish @api_client
|
|
483
|
+
# and @{name}_interface variables for each registered interface.
|
|
484
|
+
def connect(options)
|
|
485
|
+
@api_client = establish_remote_appliance_connection(options)
|
|
486
|
+
self.class.registered_interfaces.each do |interface_name|
|
|
487
|
+
if interface_name.is_a?(String) || interface_name.is_a?(Symbol)
|
|
488
|
+
instance_variable_set("@#{interface_name}_interface", @api_client.send(interface_name))
|
|
489
|
+
elsif interface_name.is_a?(Hash)
|
|
490
|
+
interface_name.each do |k,v|
|
|
491
|
+
instance_variable_set("#{k}_interface", @api_client.send(v))
|
|
492
|
+
end
|
|
493
|
+
end
|
|
494
|
+
end
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
def handle(args)
|
|
498
|
+
handle_subcommand(args)
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
def list(args)
|
|
502
|
+
params = {}
|
|
503
|
+
options = {}
|
|
504
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
505
|
+
opts.banner = subcommand_usage("[search]")
|
|
506
|
+
build_list_options(opts, options, params)
|
|
507
|
+
opts.footer = <<-EOT
|
|
508
|
+
List #{rest_label_plural.downcase}.
|
|
509
|
+
[search] is optional. This is a search phrase to filter the results.
|
|
510
|
+
EOT
|
|
511
|
+
end
|
|
512
|
+
optparse.parse!(args)
|
|
513
|
+
connect(options)
|
|
514
|
+
parse_list_options!(args, options, params)
|
|
515
|
+
rest_interface.setopts(options)
|
|
516
|
+
if options[:dry_run]
|
|
517
|
+
print_dry_run rest_interface.dry.list(params)
|
|
518
|
+
return
|
|
519
|
+
end
|
|
520
|
+
json_response = rest_interface.list(params)
|
|
521
|
+
render_response(json_response, options, rest_list_key) do
|
|
522
|
+
records = json_response[rest_list_key]
|
|
523
|
+
title = "#{rest_label_plural}"
|
|
524
|
+
subtitles = []
|
|
525
|
+
subtitles += parse_list_subtitles(options)
|
|
526
|
+
print_h1 title, subtitles, options
|
|
527
|
+
if records.nil? || records.empty?
|
|
528
|
+
print cyan,"No #{rest_label_plural.downcase} found.",reset,"\n"
|
|
529
|
+
else
|
|
530
|
+
print as_pretty_table(records, rest_list_column_definitions(options).upcase_keys!, options)
|
|
531
|
+
print_results_pagination(json_response) if json_response['meta']
|
|
532
|
+
end
|
|
533
|
+
print reset,"\n"
|
|
534
|
+
end
|
|
535
|
+
return 0, nil
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
def get(args)
|
|
539
|
+
params = {}
|
|
540
|
+
options = {}
|
|
541
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
542
|
+
opts.banner = subcommand_usage("[#{rest_arg}]")
|
|
543
|
+
build_get_options(opts, options, params)
|
|
544
|
+
opts.footer = <<-EOT
|
|
545
|
+
Get details about #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
546
|
+
[#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
547
|
+
EOT
|
|
548
|
+
end
|
|
549
|
+
optparse.parse!(args)
|
|
550
|
+
verify_args!(args:args, optparse:optparse, min:1)
|
|
551
|
+
connect(options)
|
|
552
|
+
parse_get_options!(args, options, params)
|
|
553
|
+
id = args.join(" ")
|
|
554
|
+
_get(id, params, options)
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
def _get(id, params, options)
|
|
558
|
+
if id.to_s !~ /\A\d{1,}\Z/ && rest_has_name
|
|
559
|
+
record = rest_find_by_name_or_id(id)
|
|
560
|
+
if record.nil?
|
|
561
|
+
return 1, "#{rest_label} not found for '#{id}'"
|
|
562
|
+
end
|
|
563
|
+
id = record['id']
|
|
564
|
+
end
|
|
565
|
+
rest_interface.setopts(options)
|
|
566
|
+
if options[:dry_run]
|
|
567
|
+
print_dry_run rest_interface.dry.get(id, params)
|
|
568
|
+
return
|
|
569
|
+
end
|
|
570
|
+
json_response = rest_interface.get(id, params)
|
|
571
|
+
render_response_for_get(json_response, options)
|
|
572
|
+
return 0, nil
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
def render_response_for_get(json_response, options)
|
|
576
|
+
render_response(json_response, options, rest_object_key) do
|
|
577
|
+
record = json_response[rest_object_key]
|
|
578
|
+
print_h1 rest_label, [], options
|
|
579
|
+
print cyan
|
|
580
|
+
print_description_list(rest_column_definitions(options), record, options)
|
|
581
|
+
# # could always show config eh? or maybe only with --config if that is nicer.
|
|
582
|
+
# # config = record['config'].is_a?(Hash) && !record['config'].empty?
|
|
583
|
+
# if config && !config.empty?
|
|
584
|
+
# print_h2 "Configuration"
|
|
585
|
+
# print_description_list(config.keys, config)
|
|
586
|
+
# end
|
|
587
|
+
# Option Types
|
|
588
|
+
if record['optionTypes'] && record['optionTypes'].sort { |x,y| x['displayOrder'].to_i <=> y['displayOrder'].to_i }.size > 0
|
|
589
|
+
print_h2 "Option Types", options
|
|
590
|
+
print format_option_types_table(record['optionTypes'], options, rest_object_key)
|
|
591
|
+
end
|
|
592
|
+
print reset,"\n"
|
|
593
|
+
end
|
|
594
|
+
end
|
|
595
|
+
|
|
596
|
+
def add(args)
|
|
597
|
+
record_type = nil
|
|
598
|
+
record_type_id = nil
|
|
599
|
+
options = {:options => {:context_map => rest_option_context_map}}
|
|
600
|
+
#respond_to?("#{rest_key}_option_context_map", true) ? send("#{rest_key}_option_context_map") : {'domain' => ''}}}
|
|
601
|
+
option_types = respond_to?("add_#{rest_key}_option_types", true) ? send("add_#{rest_key}_option_types") : []
|
|
602
|
+
advanced_option_types = respond_to?("add_#{rest_key}_advanced_option_types", true) ? send("add_#{rest_key}_advanced_option_types") : []
|
|
603
|
+
type_option_type = option_types.find {|it| it['fieldName'] == 'type'}
|
|
604
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
605
|
+
if rest_has_name
|
|
606
|
+
opts.banner = subcommand_usage("[name]")
|
|
607
|
+
else
|
|
608
|
+
opts.banner = subcommand_usage()
|
|
609
|
+
end
|
|
610
|
+
if rest_has_type && type_option_type.nil?
|
|
611
|
+
opts.on( '-t', "--#{rest_type_arg} TYPE", "#{rest_type_label}" ) do |val|
|
|
612
|
+
record_type_id = val
|
|
613
|
+
end
|
|
614
|
+
end
|
|
615
|
+
build_option_type_options(opts, options, option_types)
|
|
616
|
+
build_option_type_options(opts, options, advanced_option_types)
|
|
617
|
+
build_standard_add_options(opts, options)
|
|
618
|
+
opts.footer = <<-EOT
|
|
619
|
+
Create a new #{rest_label.downcase}.
|
|
620
|
+
[name] is required. This is the name of the new #{rest_label.downcase}.
|
|
621
|
+
EOT
|
|
622
|
+
opts.footer += send "add_#{rest_key}_footer_addn" if respond_to?("add_#{rest_key}_footer_addn", true)
|
|
623
|
+
end
|
|
624
|
+
optparse.parse!(args)
|
|
625
|
+
# todo: make supporting args[0] optional and more flexible
|
|
626
|
+
# for now args[0] is assumed to be the 'name'
|
|
627
|
+
record_name = nil
|
|
628
|
+
if rest_has_name
|
|
629
|
+
if args.count > 0
|
|
630
|
+
record_name = args.join(" ")
|
|
631
|
+
end
|
|
632
|
+
verify_args!(args:args, optparse:optparse, min:0, max: 1)
|
|
633
|
+
else
|
|
634
|
+
verify_args!(args:args, optparse:optparse, count: 0)
|
|
635
|
+
end
|
|
636
|
+
connect(options)
|
|
637
|
+
passed_options = parse_passed_options(options)
|
|
638
|
+
payload = {}
|
|
639
|
+
if options[:payload]
|
|
640
|
+
payload = options[:payload]
|
|
641
|
+
payload.deep_merge!({rest_object_key => passed_options})
|
|
642
|
+
else
|
|
643
|
+
# load or prompt for type
|
|
644
|
+
if rest_has_type && type_option_type.nil?
|
|
645
|
+
if record_type_id.nil?
|
|
646
|
+
#raise_command_error "#{rest_type_label} is required.\n#{optparse}"
|
|
647
|
+
type_list = rest_type_interface.list({max:10000, creatable:true})[rest_type_list_key]
|
|
648
|
+
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']} }
|
|
649
|
+
record_type_id = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'fieldLabel' => rest_type_label, 'type' => 'select', 'selectOptions' => type_dropdown_options, 'required' => true}], options[:options], @api_client)['type']
|
|
650
|
+
end
|
|
651
|
+
record_type = rest_type_find_by_name_or_id(record_type_id)
|
|
652
|
+
if record_type.nil?
|
|
653
|
+
return 1, "#{rest_type_label} not found for '#{record_type_id}"
|
|
654
|
+
end
|
|
655
|
+
end
|
|
656
|
+
record_payload = {}
|
|
657
|
+
if record_name
|
|
658
|
+
record_payload['name'] = record_name
|
|
659
|
+
options[:options]['name'] = record_name # injected for prompt
|
|
660
|
+
end
|
|
661
|
+
if rest_has_type && record_type
|
|
662
|
+
# inject type to options for prompting
|
|
663
|
+
record_payload['type'] = record_type['code']
|
|
664
|
+
options[:options]['type'] = record_type['code']
|
|
665
|
+
# initialize params for loading optionSource data
|
|
666
|
+
options[:params] ||= {}
|
|
667
|
+
options[:params]['type'] = record_type['code']
|
|
668
|
+
end
|
|
669
|
+
record_payload.deep_merge!(passed_options)
|
|
670
|
+
if option_types && !option_types.empty?
|
|
671
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
|
|
672
|
+
v_prompt.deep_compact!
|
|
673
|
+
v_prompt.booleanize! # 'on' => true
|
|
674
|
+
record_payload.deep_merge!(v_prompt)
|
|
675
|
+
end
|
|
676
|
+
# options by type
|
|
677
|
+
if rest_has_type && record_type.nil?
|
|
678
|
+
type_value = record_payload['type'].is_a?(Hash) ? record_payload['type']['id'] : record_payload['type']
|
|
679
|
+
if type_value
|
|
680
|
+
record_type = rest_type_find_by_name_or_id(type_value)
|
|
681
|
+
if record_type.nil?
|
|
682
|
+
return 1, "#{rest_type_label} not found for '#{type_value}"
|
|
683
|
+
end
|
|
684
|
+
end
|
|
685
|
+
# reload the type by id to get all the details ie. optionTypes
|
|
686
|
+
if record_type && record_type['optionTypes'].nil?
|
|
687
|
+
record_type = rest_type_find_by_name_or_id(record_type['id'])
|
|
688
|
+
end
|
|
689
|
+
end
|
|
690
|
+
my_option_types = nil
|
|
691
|
+
if respond_to?("load_option_types_for_#{rest_key}", true)
|
|
692
|
+
my_option_types = send("load_option_types_for_#{rest_key}", record_type, nil)
|
|
693
|
+
else
|
|
694
|
+
my_option_types = record_type ? record_type['optionTypes'] : nil
|
|
695
|
+
end
|
|
696
|
+
if my_option_types && !my_option_types.empty?
|
|
697
|
+
# remove redundant fieldContext
|
|
698
|
+
my_option_types.each do |option_type|
|
|
699
|
+
if option_type['fieldContext'] == rest_object_key
|
|
700
|
+
option_type['fieldContext'] = nil
|
|
701
|
+
end
|
|
702
|
+
end
|
|
703
|
+
api_params = (options[:params] || {}).merge(record_payload)
|
|
704
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt(my_option_types, options[:options], @api_client, api_params, false, true)
|
|
705
|
+
v_prompt.deep_compact!
|
|
706
|
+
v_prompt.booleanize! # 'on' => true
|
|
707
|
+
record_payload.deep_merge!(v_prompt)
|
|
708
|
+
end
|
|
709
|
+
# advanced options (uses no_prompt)
|
|
710
|
+
if advanced_option_types && !advanced_option_types.empty?
|
|
711
|
+
v_prompt = MtnCloud::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
|
|
712
|
+
v_prompt.deep_compact!
|
|
713
|
+
v_prompt.booleanize! # 'on' => true
|
|
714
|
+
record_payload.deep_merge!(v_prompt)
|
|
715
|
+
end
|
|
716
|
+
# permissions
|
|
717
|
+
if rest_perms_config[:enabled]
|
|
718
|
+
if rest_perms_config[:version] == 2
|
|
719
|
+
perms = prompt_permissions_v2(options.deep_merge(rest_perms_config[:options] || {}), rest_perms_config[:excludes] || [])
|
|
720
|
+
else
|
|
721
|
+
perms = prompt_permissions(options.deep_merge(rest_perms_config[:options] || {}), rest_perms_config[:excludes] || [])
|
|
722
|
+
end
|
|
723
|
+
unless rest_perms_config[:name].nil?
|
|
724
|
+
perms.transform_keys! {|k| k == 'resourcePermissions' ? rest_perms_config[:name] : k}
|
|
725
|
+
end
|
|
726
|
+
unless rest_perms_config[:context].nil?
|
|
727
|
+
perms_context = {}
|
|
728
|
+
perms_context[rest_perms_config[:context]] = perms
|
|
729
|
+
end
|
|
730
|
+
record_payload.merge!(perms)
|
|
731
|
+
end
|
|
732
|
+
payload[rest_object_key] = record_payload
|
|
733
|
+
end
|
|
734
|
+
rest_interface.setopts(options)
|
|
735
|
+
if options[:dry_run]
|
|
736
|
+
print_dry_run rest_interface.dry.create(payload)
|
|
737
|
+
return
|
|
738
|
+
end
|
|
739
|
+
json_response = rest_interface.create(payload)
|
|
740
|
+
render_response(json_response, options, rest_object_key) do
|
|
741
|
+
record = json_response[rest_object_key]
|
|
742
|
+
print_green_success "Added #{rest_label.downcase} #{record['name'] || record['id']}"
|
|
743
|
+
return _get(record["id"], {}, options)
|
|
744
|
+
end
|
|
745
|
+
return 0, nil
|
|
746
|
+
end
|
|
747
|
+
|
|
748
|
+
def update(args)
|
|
749
|
+
record_type = nil
|
|
750
|
+
record_type_id = nil
|
|
751
|
+
options = {}
|
|
752
|
+
option_types = respond_to?("update_#{rest_key}_option_types", true) ? send("update_#{rest_key}_option_types") : []
|
|
753
|
+
advanced_option_types = respond_to?("update_#{rest_key}_advanced_option_types", true) ? send("update_#{rest_key}_advanced_option_types") : []
|
|
754
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
755
|
+
opts.banner = subcommand_usage("[#{rest_arg}] [options]")
|
|
756
|
+
build_option_type_options(opts, options, option_types)
|
|
757
|
+
build_option_type_options(opts, options, advanced_option_types)
|
|
758
|
+
build_standard_update_options(opts, options)
|
|
759
|
+
opts.footer = <<-EOT
|
|
760
|
+
Update an existing #{rest_label.downcase}.
|
|
761
|
+
[#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
762
|
+
EOT
|
|
763
|
+
opts.footer += send "update_#{rest_key}_footer_addn" if respond_to?("update_#{rest_key}_footer_addn", true)
|
|
764
|
+
end
|
|
765
|
+
optparse.parse!(args)
|
|
766
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
|
767
|
+
connect(options)
|
|
768
|
+
id = args[0]
|
|
769
|
+
record = rest_find_by_name_or_id(id)
|
|
770
|
+
if record.nil?
|
|
771
|
+
return 1, "#{rest_name} not found for '#{id}'"
|
|
772
|
+
end
|
|
773
|
+
# load type so we can prompt for those option types
|
|
774
|
+
if rest_has_type
|
|
775
|
+
record_type_id = record['type']['id']
|
|
776
|
+
record_type = rest_type_find_by_name_or_id(record_type_id)
|
|
777
|
+
if record_type.nil?
|
|
778
|
+
return 1, "#{rest_type_label} not found for '#{record_type_id}"
|
|
779
|
+
end
|
|
780
|
+
# reload the type by id to get all the details ie. optionTypes
|
|
781
|
+
if record_type['optionTypes'].nil?
|
|
782
|
+
record_type = rest_type_find_by_name_or_id(record_type['id'])
|
|
783
|
+
end
|
|
784
|
+
end
|
|
785
|
+
passed_options = parse_passed_options(options)
|
|
786
|
+
payload = {}
|
|
787
|
+
if options[:payload]
|
|
788
|
+
payload = options[:payload]
|
|
789
|
+
payload.deep_merge!({rest_object_key => passed_options}) unless passed_options.empty?
|
|
790
|
+
else
|
|
791
|
+
record_payload = passed_options
|
|
792
|
+
if rest_has_type && record_type
|
|
793
|
+
# inject type to options for prompting
|
|
794
|
+
# record_payload['type'] = record_type['code']
|
|
795
|
+
# options[:options]['type'] = record_type['code']
|
|
796
|
+
# initialize params for loading optionSource data
|
|
797
|
+
options[:params] ||= {}
|
|
798
|
+
options[:params]['type'] = record_type['code']
|
|
799
|
+
end
|
|
800
|
+
# update options without prompting by default
|
|
801
|
+
if option_types && !option_types.empty?
|
|
802
|
+
api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
|
|
803
|
+
v_prompt = MtnCloud::Cli::OptionTypes.no_prompt(option_types, options[:options], @api_client, api_params)
|
|
804
|
+
v_prompt.deep_compact!
|
|
805
|
+
v_prompt.booleanize! # 'on' => true
|
|
806
|
+
record_payload.deep_merge!(v_prompt)
|
|
807
|
+
end
|
|
808
|
+
# options by type
|
|
809
|
+
my_option_types = nil
|
|
810
|
+
if respond_to?("load_option_types_for_#{rest_key}", true)
|
|
811
|
+
my_option_types = send("load_option_types_for_#{rest_key}", record_type, nil)
|
|
812
|
+
else
|
|
813
|
+
my_option_types = record_type ? record_type['optionTypes'] : nil
|
|
814
|
+
end
|
|
815
|
+
if my_option_types && !my_option_types.empty?
|
|
816
|
+
# remove redundant fieldContext
|
|
817
|
+
# make them optional for updates
|
|
818
|
+
# todo: use current value as default instead of just making things optioanl
|
|
819
|
+
# maybe new prompt() options like {:mode => :edit, :object => storage_server} or something
|
|
820
|
+
my_option_types.each do |option_type|
|
|
821
|
+
if option_type['fieldContext'] == rest_object_key
|
|
822
|
+
option_type['fieldContext'] = nil
|
|
823
|
+
end
|
|
824
|
+
option_type.delete('required')
|
|
825
|
+
option_type.delete('defaultValue')
|
|
826
|
+
end
|
|
827
|
+
api_params = (options[:params] || {}).merge(record_payload) # need to merge in values from record too, ughhh
|
|
828
|
+
v_prompt = MtnCloud::Cli::OptionTypes.no_prompt(my_option_types, options[:options], @api_client, api_params)
|
|
829
|
+
v_prompt.deep_compact!
|
|
830
|
+
v_prompt.booleanize! # 'on' => true
|
|
831
|
+
record_payload.deep_merge!(v_prompt)
|
|
832
|
+
end
|
|
833
|
+
# advanced options
|
|
834
|
+
if advanced_option_types && !advanced_option_types.empty?
|
|
835
|
+
v_prompt = MtnCloud::Cli::OptionTypes.no_prompt(advanced_option_types, options[:options], @api_client, options[:params])
|
|
836
|
+
v_prompt.deep_compact!
|
|
837
|
+
v_prompt.booleanize! # 'on' => true
|
|
838
|
+
record_payload.deep_merge!(v_prompt)
|
|
839
|
+
end
|
|
840
|
+
# remove empty config, compact could hanlde this
|
|
841
|
+
if record_payload['config'] && record_payload['config'].empty?
|
|
842
|
+
record_payload.delete('config')
|
|
843
|
+
end
|
|
844
|
+
# prevent updating with empty payload
|
|
845
|
+
if record_payload.empty?
|
|
846
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
|
847
|
+
end
|
|
848
|
+
payload[rest_object_key] = record_payload
|
|
849
|
+
end
|
|
850
|
+
rest_interface.setopts(options)
|
|
851
|
+
if options[:dry_run]
|
|
852
|
+
print_dry_run rest_interface.dry.update(record['id'], payload)
|
|
853
|
+
return
|
|
854
|
+
end
|
|
855
|
+
json_response = rest_interface.update(record['id'], payload)
|
|
856
|
+
render_response(json_response, options, rest_object_key) do
|
|
857
|
+
print_green_success "Updated #{rest_label.downcase} #{record['name'] || record['id']}"
|
|
858
|
+
_get(record["id"], {}, options)
|
|
859
|
+
end
|
|
860
|
+
return 0, nil
|
|
861
|
+
end
|
|
862
|
+
|
|
863
|
+
def remove(args)
|
|
864
|
+
params = {}
|
|
865
|
+
options = {}
|
|
866
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
867
|
+
opts.banner = subcommand_usage("[#{rest_arg}]")
|
|
868
|
+
build_standard_remove_options(opts, options)
|
|
869
|
+
opts.footer = <<-EOT
|
|
870
|
+
Delete an existing #{rest_label.downcase}.
|
|
871
|
+
[#{rest_arg}] is required. This is the #{rest_has_name ? 'name or id' : 'id'} of #{a_or_an(rest_label)} #{rest_label.downcase}.
|
|
872
|
+
EOT
|
|
873
|
+
end
|
|
874
|
+
optparse.parse!(args)
|
|
875
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
|
876
|
+
connect(options)
|
|
877
|
+
params.merge!(parse_query_options(options))
|
|
878
|
+
id = args[0]
|
|
879
|
+
record = rest_find_by_name_or_id(id)
|
|
880
|
+
if record.nil?
|
|
881
|
+
return 1, "#{rest_name} not found for '#{id}'"
|
|
882
|
+
end
|
|
883
|
+
unless options[:yes] || MtnCloud::Cli::OptionTypes.confirm("Are you sure you want to delete the #{rest_label.downcase} #{record['name'] || record['id']}?")
|
|
884
|
+
return 9, "aborted"
|
|
885
|
+
end
|
|
886
|
+
rest_interface.setopts(options)
|
|
887
|
+
if options[:dry_run]
|
|
888
|
+
print_dry_run rest_interface.dry.destroy(record['id'], params)
|
|
889
|
+
return 0, nil
|
|
890
|
+
end
|
|
891
|
+
json_response = rest_interface.destroy(record['id'], params)
|
|
892
|
+
render_response(json_response, options) do
|
|
893
|
+
print_green_success "Removed #{rest_label.downcase} #{record['name'] || record['id']}"
|
|
894
|
+
end
|
|
895
|
+
return 0, nil
|
|
896
|
+
end
|
|
897
|
+
|
|
898
|
+
def list_types(args)
|
|
899
|
+
params = {}
|
|
900
|
+
options = {}
|
|
901
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
902
|
+
opts.banner = subcommand_usage("[search]")
|
|
903
|
+
build_list_options(opts, options, params)
|
|
904
|
+
opts.footer = <<-EOT
|
|
905
|
+
List #{rest_type_label_plural.downcase}.
|
|
906
|
+
[search] is optional. This is a search phrase to filter the results.
|
|
907
|
+
EOT
|
|
908
|
+
end
|
|
909
|
+
optparse.parse!(args)
|
|
910
|
+
connect(options)
|
|
911
|
+
parse_list_options!(args, options, params)
|
|
912
|
+
rest_type_interface.setopts(options)
|
|
913
|
+
if options[:dry_run]
|
|
914
|
+
print_dry_run rest_type_interface.dry.list(params)
|
|
915
|
+
return
|
|
916
|
+
end
|
|
917
|
+
json_response = rest_type_interface.list(params)
|
|
918
|
+
render_response(json_response, options, rest_type_list_key) do
|
|
919
|
+
records = json_response[rest_type_list_key]
|
|
920
|
+
title = "#{rest_type_label_plural}"
|
|
921
|
+
subtitles = []
|
|
922
|
+
subtitles += parse_list_subtitles(options)
|
|
923
|
+
print_h1 title, subtitles, options
|
|
924
|
+
if records.nil? || records.empty?
|
|
925
|
+
print cyan,"No #{rest_type_label_plural.downcase} found.",reset,"\n"
|
|
926
|
+
else
|
|
927
|
+
print as_pretty_table(records, rest_type_list_column_definitions(options).upcase_keys!, options)
|
|
928
|
+
print_results_pagination(json_response) if json_response['meta']
|
|
929
|
+
end
|
|
930
|
+
print reset,"\n"
|
|
931
|
+
end
|
|
932
|
+
return 0, nil
|
|
933
|
+
end
|
|
934
|
+
|
|
935
|
+
def get_type(args)
|
|
936
|
+
params = {}
|
|
937
|
+
options = {}
|
|
938
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
939
|
+
opts.banner = subcommand_usage("[#{rest_type_arg}]")
|
|
940
|
+
build_get_options(opts, options, params)
|
|
941
|
+
opts.footer = <<-EOT
|
|
942
|
+
Get details about #{a_or_an(rest_type_label)} #{rest_type_label.downcase}.
|
|
943
|
+
[#{rest_type_arg}] is required. This is the name or id of #{a_or_an(rest_type_label)} #{rest_type_label.downcase}.
|
|
944
|
+
EOT
|
|
945
|
+
end
|
|
946
|
+
optparse.parse!(args)
|
|
947
|
+
verify_args!(args:args, optparse:optparse, min:1)
|
|
948
|
+
connect(options)
|
|
949
|
+
parse_get_options!(args, options, params)
|
|
950
|
+
id = args.join(" ")
|
|
951
|
+
_get_type(id, params, options)
|
|
952
|
+
end
|
|
953
|
+
|
|
954
|
+
def _get_type(id, params, options)
|
|
955
|
+
if id.to_s !~ /\A\d{1,}\Z/ # && rest_type_has_name
|
|
956
|
+
record = rest_type_find_by_name_or_id(id)
|
|
957
|
+
if record.nil?
|
|
958
|
+
return 1, "#{rest_type_label} not found for '#{id}'"
|
|
959
|
+
end
|
|
960
|
+
id = record['id']
|
|
961
|
+
end
|
|
962
|
+
rest_type_interface.setopts(options)
|
|
963
|
+
if options[:dry_run]
|
|
964
|
+
print_dry_run rest_type_interface.dry.get(id, params)
|
|
965
|
+
return
|
|
966
|
+
end
|
|
967
|
+
json_response = rest_type_interface.get(id, params)
|
|
968
|
+
render_response_for_get_type(json_response, options)
|
|
969
|
+
return 0, nil
|
|
970
|
+
end
|
|
971
|
+
|
|
972
|
+
def render_response_for_get_type(json_response, options)
|
|
973
|
+
render_response(json_response, options, rest_type_object_key) do
|
|
974
|
+
record = json_response[rest_type_object_key]
|
|
975
|
+
print_h1 rest_type_label, [], options
|
|
976
|
+
print cyan
|
|
977
|
+
print_description_list(rest_type_column_definitions(options), record, options)
|
|
978
|
+
# # could always show config eh? or maybe only with --config if that is nicer.
|
|
979
|
+
# # config = record['config'].is_a?(Hash) && !record['config'].empty?
|
|
980
|
+
# if config && !config.empty?
|
|
981
|
+
# print_h2 "Configuration"
|
|
982
|
+
# print_description_list(config.keys, config)
|
|
983
|
+
# end
|
|
984
|
+
# Option Types
|
|
985
|
+
if record['optionTypes'] && record['optionTypes'].size > 0
|
|
986
|
+
print_h2 "Option Types", options
|
|
987
|
+
print format_option_types_table(record['optionTypes'], options, rest_object_key)
|
|
988
|
+
end
|
|
989
|
+
print reset,"\n"
|
|
990
|
+
end
|
|
991
|
+
end
|
|
992
|
+
|
|
993
|
+
end
|
|
994
|
+
|