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,307 @@
|
|
|
1
|
+
require 'term/ansicolor'
|
|
2
|
+
require 'optparse'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'rest_client'
|
|
5
|
+
require 'net/https'
|
|
6
|
+
require 'mtncloud/logging'
|
|
7
|
+
require 'mtncloud/cli/errors'
|
|
8
|
+
require 'mtncloud/cli/expression_parser'
|
|
9
|
+
|
|
10
|
+
class MtnCloud::Cli::ErrorHandler
|
|
11
|
+
include Term::ANSIColor
|
|
12
|
+
|
|
13
|
+
def initialize(io=$stderr)
|
|
14
|
+
@stderr = io
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def handle_error(err, options={})
|
|
18
|
+
exit_code = 1
|
|
19
|
+
options = (options || {}).clone
|
|
20
|
+
if MtnCloud::Logging.debug?
|
|
21
|
+
options[:debug] = true
|
|
22
|
+
end
|
|
23
|
+
do_print_stacktrace = true
|
|
24
|
+
|
|
25
|
+
#@stderr.puts "#{dark}Handling error #{err.class} - #{err}#{reset}"
|
|
26
|
+
|
|
27
|
+
case (err)
|
|
28
|
+
when SystemExit
|
|
29
|
+
# nothing to do, assume the command that exited printed an error already
|
|
30
|
+
# print "\n"
|
|
31
|
+
cmdexit = err
|
|
32
|
+
if cmdexit.success?
|
|
33
|
+
exit_code, err = 0, nil
|
|
34
|
+
else
|
|
35
|
+
exit_code, err = cmdexit.status, "Command exited with status: #{cmdexit.status}"
|
|
36
|
+
end
|
|
37
|
+
return exit_code, err
|
|
38
|
+
# when MtnCloud::Cli::CommandNotFoundError
|
|
39
|
+
# puts_angry_error err.message
|
|
40
|
+
# @stderr.puts "Try help to see a list of available commands"
|
|
41
|
+
# do_print_stacktrace = false
|
|
42
|
+
# if err.exit_code
|
|
43
|
+
# exit_code = err.exit_code
|
|
44
|
+
# end
|
|
45
|
+
when MtnCloud::Cli::CommandAborted
|
|
46
|
+
# user declined a confirmation prompt, do not print anything and exit 9
|
|
47
|
+
do_print_stacktrace = false
|
|
48
|
+
exit_code = err.exit_code if err.exit_code
|
|
49
|
+
# err = err.message
|
|
50
|
+
return
|
|
51
|
+
when ::OptionParser::InvalidOption, ::OptionParser::AmbiguousOption,
|
|
52
|
+
::OptionParser::MissingArgument, ::OptionParser::InvalidArgument,
|
|
53
|
+
::OptionParser::NeedlessArgument
|
|
54
|
+
# raise err
|
|
55
|
+
# @stderr.puts "#{red}#{err.message}#{reset}"
|
|
56
|
+
puts_angry_error err.message
|
|
57
|
+
@stderr.puts err.optparse.banner if err.optparse && err.optparse.banner
|
|
58
|
+
@stderr.puts "Try --help for more usage information"
|
|
59
|
+
do_print_stacktrace = false
|
|
60
|
+
# exit_code = 127
|
|
61
|
+
when MtnCloud::Cli::CommandArgumentsError
|
|
62
|
+
puts_angry_error err.message
|
|
63
|
+
if err.args.include?("--help") || err.args.include?("--help")
|
|
64
|
+
@stderr.puts err.optparse
|
|
65
|
+
else
|
|
66
|
+
@stderr.puts err.optparse.banner if err.optparse && err.optparse.banner
|
|
67
|
+
@stderr.puts "Try --help for more usage information"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
do_print_stacktrace = false
|
|
71
|
+
if err.exit_code
|
|
72
|
+
exit_code = err.exit_code
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
when MtnCloud::Cli::CommandError
|
|
76
|
+
# this should probably always print the whole thing as red, but just does the first line for now.
|
|
77
|
+
# until verify_args! replaces raise_command_error where the full parser help is in the error message..
|
|
78
|
+
message_lines = err.message.split(/\r?\n/)
|
|
79
|
+
first_line = message_lines.shift
|
|
80
|
+
puts_angry_error first_line
|
|
81
|
+
if !message_lines.empty?
|
|
82
|
+
@stderr.puts message_lines.join("\n") unless message_lines.empty?
|
|
83
|
+
else
|
|
84
|
+
if err.args.include?("--help") || err.args.include?("--help")
|
|
85
|
+
@stderr.puts err.optparse
|
|
86
|
+
else
|
|
87
|
+
@stderr.puts err.optparse.banner if err.optparse && err.optparse.banner && message_lines.empty?
|
|
88
|
+
@stderr.puts "Try --help for more usage information"
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
do_print_stacktrace = false
|
|
92
|
+
if err.exit_code
|
|
93
|
+
exit_code = err.exit_code
|
|
94
|
+
end
|
|
95
|
+
when MtnCloud::Cli::ExpressionParser::InvalidExpression
|
|
96
|
+
# @stderr.puts "#{red}#{err.message}#{reset}"
|
|
97
|
+
puts_angry_error err.message
|
|
98
|
+
do_print_stacktrace = false
|
|
99
|
+
exit_code = 99
|
|
100
|
+
when SocketError
|
|
101
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance.#{reset}"
|
|
102
|
+
@stderr.puts "#{red}#{err.message}#{reset}"
|
|
103
|
+
when RestClient::Exceptions::Timeout
|
|
104
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance.#{reset}"
|
|
105
|
+
@stderr.puts "#{red}#{err.message}#{reset}"
|
|
106
|
+
when Errno::ECONNREFUSED
|
|
107
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance.#{reset}"
|
|
108
|
+
@stderr.puts "#{red}#{err.message}#{reset}"
|
|
109
|
+
when OpenSSL::SSL::SSLError
|
|
110
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance.#{reset}"
|
|
111
|
+
@stderr.puts "#{red}#{err.message}#{reset}"
|
|
112
|
+
when RestClient::Exception
|
|
113
|
+
print_rest_exception(err, options)
|
|
114
|
+
# no stacktrace for now...
|
|
115
|
+
return exit_code, err
|
|
116
|
+
when ArgumentError
|
|
117
|
+
@stderr.puts "#{red}Argument Error: #{err.message}#{reset}"
|
|
118
|
+
else
|
|
119
|
+
@stderr.puts "#{red}Unexpected Error#{reset}"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
if do_print_stacktrace
|
|
123
|
+
if options[:debug]
|
|
124
|
+
if err.is_a?(Exception)
|
|
125
|
+
print_stacktrace(err)
|
|
126
|
+
else
|
|
127
|
+
@stderr.puts err.to_s
|
|
128
|
+
end
|
|
129
|
+
else
|
|
130
|
+
@stderr.puts "Use -V or --debug for more verbose debugging information."
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
return exit_code, err
|
|
135
|
+
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def print_stacktrace(err)
|
|
139
|
+
@stderr.print red, "\n", "#{err.class}: #{err.message}", "\n", reset
|
|
140
|
+
@stderr.print err.backtrace.join("\n"), "\n\n"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# def handle_rest_exception(err, io=@stderr)
|
|
144
|
+
# if !err.is_a?(RestClient::Exception)
|
|
145
|
+
# raise err
|
|
146
|
+
# end
|
|
147
|
+
# print_rest_exception(err, io=@stderr)
|
|
148
|
+
# end
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def print_rest_exception(err, options)
|
|
152
|
+
e = err
|
|
153
|
+
# heh
|
|
154
|
+
if MtnCloud::Logging.debug? && options[:debug].nil?
|
|
155
|
+
options[:debug] = true
|
|
156
|
+
end
|
|
157
|
+
if err.response
|
|
158
|
+
if options[:debug]
|
|
159
|
+
begin
|
|
160
|
+
print_rest_exception_request_and_response(e)
|
|
161
|
+
ensure
|
|
162
|
+
@stderr.print reset
|
|
163
|
+
end
|
|
164
|
+
return
|
|
165
|
+
end
|
|
166
|
+
if err.response.code == 400
|
|
167
|
+
begin
|
|
168
|
+
print_rest_errors(JSON.parse(err.response.to_s), options)
|
|
169
|
+
rescue TypeError, JSON::ParserError => ex
|
|
170
|
+
end
|
|
171
|
+
elsif err.response.code == 404
|
|
172
|
+
begin
|
|
173
|
+
print_rest_errors(JSON.parse(err.response.to_s), options)
|
|
174
|
+
rescue TypeError, JSON::ParserError => ex
|
|
175
|
+
# not json, just 404
|
|
176
|
+
@stderr.print red, "Error Communicating with the remote appliance. #{e}", reset, "\n"
|
|
177
|
+
end
|
|
178
|
+
else
|
|
179
|
+
@stderr.print red, "Error Communicating with the remote appliance. #{e}", reset, "\n"
|
|
180
|
+
if options[:json] || options[:debug]
|
|
181
|
+
begin
|
|
182
|
+
response = JSON.parse(e.response.to_s)
|
|
183
|
+
# @stderr.print red
|
|
184
|
+
@stderr.print JSON.pretty_generate(response)
|
|
185
|
+
@stderr.print reset, "\n"
|
|
186
|
+
rescue TypeError, JSON::ParserError => ex
|
|
187
|
+
@stderr.print red, "Failed to parse JSON response: #{ex}", reset, "\n"
|
|
188
|
+
# @stderr.print red
|
|
189
|
+
@stderr.print response.to_s
|
|
190
|
+
@stderr.print reset, "\n"
|
|
191
|
+
ensure
|
|
192
|
+
@stderr.print reset
|
|
193
|
+
end
|
|
194
|
+
else
|
|
195
|
+
# quick parse only for msg display
|
|
196
|
+
response = (JSON.parse(e.response.to_s) rescue nil)
|
|
197
|
+
if response.is_a?(Hash) && response['success'] == false && response['msg']
|
|
198
|
+
@stderr.print red, response['msg'].to_s, reset, "\n"
|
|
199
|
+
end
|
|
200
|
+
@stderr.puts "Use -V or --debug for more verbose debugging information."
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
else
|
|
204
|
+
@stderr.print red, "Error Communicating with the remote appliance. #{e}", reset, "\n"
|
|
205
|
+
end
|
|
206
|
+
# uh, having this print method return exit_code, err to standardize return values of methods that are still calling it, at the end just by chance..
|
|
207
|
+
# return exit_code, err
|
|
208
|
+
return 1, err
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def print_rest_errors(response, options={})
|
|
212
|
+
begin
|
|
213
|
+
if options[:json]
|
|
214
|
+
@stderr.print red
|
|
215
|
+
@stderr.print JSON.pretty_generate(response)
|
|
216
|
+
@stderr.print reset, "\n"
|
|
217
|
+
else
|
|
218
|
+
if !response['success']
|
|
219
|
+
@stderr.print red,bold
|
|
220
|
+
if response['msg']
|
|
221
|
+
@stderr.puts response['msg']
|
|
222
|
+
end
|
|
223
|
+
if response['errors']
|
|
224
|
+
# response['errors'].each do |key, value|
|
|
225
|
+
# @stderr.print "* #{key}: #{value}\n"
|
|
226
|
+
# end
|
|
227
|
+
# puts as_yaml(response['errors'])
|
|
228
|
+
@stderr.print format_rest_errors(response['errors'])
|
|
229
|
+
end
|
|
230
|
+
@stderr.print reset
|
|
231
|
+
else
|
|
232
|
+
# this should not really happen
|
|
233
|
+
@stderr.print cyan,bold, "\nSuccess!"
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
ensure
|
|
237
|
+
@stderr.print reset
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def format_rest_errors(errors, context=nil)
|
|
242
|
+
out = ""
|
|
243
|
+
Hash(errors).each do |key, value|
|
|
244
|
+
if value.is_a?(Hash)
|
|
245
|
+
out << format_rest_errors(value, context ? "#{context}.#{key}" : key)
|
|
246
|
+
else
|
|
247
|
+
prefix = context ? (context + '.') : ''
|
|
248
|
+
out << "* #{prefix}#{key}: #{value}\n"
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
out
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def print_rest_request(req)
|
|
255
|
+
@stderr.print "REQUEST"
|
|
256
|
+
@stderr.print "\n"
|
|
257
|
+
@stderr.print "#{req.method.to_s.upcase} #{req.url.inspect}"
|
|
258
|
+
@stderr.print "\n"
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def print_rest_response(res)
|
|
262
|
+
# size = @raw_response ? File.size(@tf.path) : (res.body.nil? ? 0 : res.body.size)
|
|
263
|
+
size = (res.body.nil? ? 0 : res.body.size)
|
|
264
|
+
@stderr.print "RESPONSE"
|
|
265
|
+
@stderr.print "\n"
|
|
266
|
+
display_size = Filesize.from("#{size} B").pretty rescue size
|
|
267
|
+
@stderr.print "HTTP #{res.net_http_res.code} #{res.net_http_res.message} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{display_size}"
|
|
268
|
+
@stderr.print "\n"
|
|
269
|
+
begin
|
|
270
|
+
@stderr.print JSON.pretty_generate(JSON.parse(res.body))
|
|
271
|
+
rescue
|
|
272
|
+
@stderr.print res.body.to_s
|
|
273
|
+
end
|
|
274
|
+
@stderr.print "\n"
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def print_rest_exception_request_and_response(e)
|
|
278
|
+
@stderr.puts "#{red}Error Communicating with the remote appliance. (HTTP #{e.response.code})#{reset}"
|
|
279
|
+
response = e.response
|
|
280
|
+
request = response.instance_variable_get("@request")
|
|
281
|
+
@stderr.print red
|
|
282
|
+
print_rest_request(request)
|
|
283
|
+
@stderr.print "\n"
|
|
284
|
+
print_rest_response(response)
|
|
285
|
+
@stderr.print reset
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
protected
|
|
290
|
+
|
|
291
|
+
def puts_angry_error(*msgs)
|
|
292
|
+
# @stderr.print "#{Term::ANSIColor.red}mtncloud: #{Term::ANSIColor.reset}#{msg}\n"
|
|
293
|
+
@stderr.print(MtnCloud::Terminal.angry_prompt)
|
|
294
|
+
@stderr.print(Term::ANSIColor.red)
|
|
295
|
+
@stderr.puts(*msgs)
|
|
296
|
+
@stderr.print(reset)
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# def puts(*args)
|
|
300
|
+
# @stderr.puts(*args)
|
|
301
|
+
# end
|
|
302
|
+
|
|
303
|
+
# def print(*args)
|
|
304
|
+
# @stderr.print(*args)
|
|
305
|
+
# end
|
|
306
|
+
|
|
307
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module MtnCloud::Cli
|
|
2
|
+
|
|
3
|
+
# A standard error to raise in your CliCommand classes.
|
|
4
|
+
class CommandError < StandardError
|
|
5
|
+
|
|
6
|
+
attr_reader :args, :optparse, :exit_code
|
|
7
|
+
|
|
8
|
+
def initialize(msg, args=[], optparse=nil, exit_code=nil)
|
|
9
|
+
@args = args
|
|
10
|
+
@optparse = optparse
|
|
11
|
+
@exit_code = exit_code # || 1
|
|
12
|
+
super(msg)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# An error indicating the command was not recognized, assigned exit code 127
|
|
18
|
+
class CommandNotFoundError < CommandError
|
|
19
|
+
|
|
20
|
+
def initialize(msg, args=[], optparse=nil, exit_code=nil)
|
|
21
|
+
super(msg, args, optparse, exit_code || 127)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# An error for wrong number of arguments
|
|
27
|
+
# could use ::OptionParser::MissingArgument, ::OptionParser::NeedlessArgument
|
|
28
|
+
# maybe return an error code other than 1?
|
|
29
|
+
class CommandArgumentsError < CommandError
|
|
30
|
+
|
|
31
|
+
def initialize(msg, args=[], optparse=nil, exit_code=nil)
|
|
32
|
+
super(msg, args, optparse, exit_code || 1)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# An error indicating authorization is required (unable to aquire access token)
|
|
38
|
+
class AuthorizationRequiredError < CommandError
|
|
39
|
+
|
|
40
|
+
def initialize(msg, args=[], optparse=nil, exit_code=nil)
|
|
41
|
+
super(msg, args, optparse, exit_code || 1)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# An error indicating the user declined to accept a confirmation prompt, assigned exit code 9
|
|
46
|
+
class CommandAborted < CommandError
|
|
47
|
+
|
|
48
|
+
def initialize(msg, args=[], optparse=nil, exit_code=nil)
|
|
49
|
+
super(msg, args, optparse, exit_code || 9)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require 'shellwords'
|
|
2
|
+
|
|
3
|
+
# Provides parsing of user input into an Array of expressions for execution
|
|
4
|
+
# Syntax currently supports the && and || operators, and the use of parenthesis
|
|
5
|
+
# returns an Array of objects.
|
|
6
|
+
# Each object might be a command (String), an operator (well known String)
|
|
7
|
+
# or another expression (Array)
|
|
8
|
+
module MtnCloud::Cli::ExpressionParser
|
|
9
|
+
|
|
10
|
+
# An error class for invalid expressions
|
|
11
|
+
class InvalidExpression < StandardError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
## constants used internally for parsing mtncloud expressions
|
|
15
|
+
# note: the space padding in the _TOKEN strings is important for splitting
|
|
16
|
+
|
|
17
|
+
OPEN_PARENTHESIS = "("
|
|
18
|
+
OPEN_PARENTHESIS_TOKEN = "___+++OPEN_PARENTHESIS+++___"
|
|
19
|
+
OPEN_PARENTHESIS_REGEX = /(\()(?=(?:[^"']|"[^'"]*")*$)/
|
|
20
|
+
|
|
21
|
+
CLOSED_PARENTHESIS = ")"
|
|
22
|
+
CLOSED_PARENTHESIS_TOKEN = "___+++CLOSED_PARENTHESIS+++___"
|
|
23
|
+
CLOSED_PARENTHESIS_REGEX = /(\))(?=(?:[^"']|"[^'"]*")*$)/
|
|
24
|
+
|
|
25
|
+
AND_OPERATOR = "&&"
|
|
26
|
+
AND_OPERATOR_TOKEN = "___+++AND_OPERATOR+++___"
|
|
27
|
+
AND_OPERATOR_REGEX = /(\&\&)(?=(?:[^"']|"[^'"]*")*$)/
|
|
28
|
+
|
|
29
|
+
OR_OPERATOR = "||"
|
|
30
|
+
OR_OPERATOR_TOKEN = "___+++OR_OPERATOR+++___"
|
|
31
|
+
OR_OPERATOR_REGEX = /(\|\|)(?=(?:[^"']|"[^'"]*")*$)/
|
|
32
|
+
|
|
33
|
+
PIPE_OPERATOR = "|"
|
|
34
|
+
PIPE_OPERATOR_TOKEN = "___+++PIPE_OPERATOR+++___"
|
|
35
|
+
PIPE_OPERATOR_REGEX = /(\|)(?=(?:[^"']|"[^'"]*")*$)/
|
|
36
|
+
|
|
37
|
+
COMMAND_DELIMETER = ";"
|
|
38
|
+
COMMAND_DELIMETER_REGEX = /(\;)(?=(?:[^"']|"[^'"]*")*$)/
|
|
39
|
+
COMMAND_DELIMETER_TOKEN = "___+++COMMAND_DELIMETER+++___"
|
|
40
|
+
|
|
41
|
+
# parse an expression of mtncloud commands into a list of expressions
|
|
42
|
+
def self.parse(input)
|
|
43
|
+
# the input is a comment
|
|
44
|
+
if input.to_s =~ /^\s*#/
|
|
45
|
+
return [input]
|
|
46
|
+
end
|
|
47
|
+
result = []
|
|
48
|
+
# first, build up a temporary command string
|
|
49
|
+
# swap in well known tokens so we can split it safely
|
|
50
|
+
expression_str = input.dup.to_s
|
|
51
|
+
expression_str.gsub!(OPEN_PARENTHESIS_REGEX, " #{OPEN_PARENTHESIS_TOKEN} ")
|
|
52
|
+
expression_str.gsub!(CLOSED_PARENTHESIS_REGEX, " #{CLOSED_PARENTHESIS_TOKEN} ")
|
|
53
|
+
expression_str.gsub!(AND_OPERATOR_REGEX, " #{AND_OPERATOR_TOKEN} ")
|
|
54
|
+
expression_str.gsub!(OR_OPERATOR_REGEX, " #{OR_OPERATOR_TOKEN} ")
|
|
55
|
+
expression_str.gsub!(PIPE_OPERATOR_REGEX, " #{PIPE_OPERATOR_TOKEN} ")
|
|
56
|
+
expression_str.gsub!(COMMAND_DELIMETER_REGEX, " #{COMMAND_DELIMETER_TOKEN} ")
|
|
57
|
+
# split on unquoted whitespace
|
|
58
|
+
tokens = expression_str.split(/(\s)(?=(?:[^"']|"[^'"]*")*$)/).collect {|it| it.to_s.strip }.select {|it| !it.empty? }.compact
|
|
59
|
+
# swap back for nice looking tokens
|
|
60
|
+
tokens = tokens.map do |t|
|
|
61
|
+
case t
|
|
62
|
+
when OPEN_PARENTHESIS_TOKEN then OPEN_PARENTHESIS
|
|
63
|
+
when CLOSED_PARENTHESIS_TOKEN then CLOSED_PARENTHESIS
|
|
64
|
+
when AND_OPERATOR_TOKEN then AND_OPERATOR
|
|
65
|
+
when OR_OPERATOR_TOKEN then OR_OPERATOR
|
|
66
|
+
when PIPE_OPERATOR_TOKEN then PIPE_OPERATOR
|
|
67
|
+
when COMMAND_DELIMETER_TOKEN then COMMAND_DELIMETER
|
|
68
|
+
else
|
|
69
|
+
t
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# result = parse_expression_from_tokens(tokens)
|
|
74
|
+
begin
|
|
75
|
+
result = parse_expression_from_tokens(tokens)
|
|
76
|
+
rescue InvalidExpression => ex
|
|
77
|
+
raise InvalidExpression.new("#{ex}. Invalid Expression: #{input}")
|
|
78
|
+
end
|
|
79
|
+
return result
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# turn a flat list of tokens into an array of expressions
|
|
83
|
+
def self.parse_expression_from_tokens(tokens)
|
|
84
|
+
result = []
|
|
85
|
+
remaining_tokens = tokens.dup
|
|
86
|
+
current_command_tokens = []
|
|
87
|
+
while !remaining_tokens.empty?
|
|
88
|
+
token = remaining_tokens.shift
|
|
89
|
+
if token == CLOSED_PARENTHESIS
|
|
90
|
+
raise InvalidExpression.new("Encountered a closed parenthesis ')' with no matching open parenthesis '('")
|
|
91
|
+
elsif token == OPEN_PARENTHESIS
|
|
92
|
+
# add the command
|
|
93
|
+
if current_command_tokens.size != 0
|
|
94
|
+
result << current_command_tokens.join(" ")
|
|
95
|
+
current_command_tokens = []
|
|
96
|
+
end
|
|
97
|
+
# start of a new sub expression
|
|
98
|
+
# find the index of the matching closed parenthesis
|
|
99
|
+
cur_expression_index = 0
|
|
100
|
+
closed_parenthesis_index = nil
|
|
101
|
+
remaining_tokens.each_with_index do |t, index|
|
|
102
|
+
if t == OPEN_PARENTHESIS
|
|
103
|
+
cur_expression_index += 1
|
|
104
|
+
elsif t == CLOSED_PARENTHESIS
|
|
105
|
+
if cur_expression_index == 0
|
|
106
|
+
closed_parenthesis_index = index
|
|
107
|
+
break
|
|
108
|
+
else
|
|
109
|
+
cur_expression_index -= 1
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
if cur_expression_index < 0
|
|
113
|
+
raise InvalidExpression.new("Encountered a closed parenthesis ')' with no matching open parenthesis '('")
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
if !closed_parenthesis_index
|
|
117
|
+
raise InvalidExpression.new("Encountered an open parenthesis '(' with no matching closed parenthesis ')'")
|
|
118
|
+
end
|
|
119
|
+
# ok, parse a subexpression for the tokens up that index
|
|
120
|
+
sub_tokens = remaining_tokens[0..closed_parenthesis_index-1]
|
|
121
|
+
result << parse_expression_from_tokens(sub_tokens)
|
|
122
|
+
# continue on parsing the remaining tokens
|
|
123
|
+
remaining_tokens = remaining_tokens[closed_parenthesis_index + 1..remaining_tokens.size - 1]
|
|
124
|
+
elsif token == AND_OPERATOR || token == OR_OPERATOR || token == PIPE_OPERATOR
|
|
125
|
+
# add the command
|
|
126
|
+
if current_command_tokens.size != 0
|
|
127
|
+
result << current_command_tokens.join(" ")
|
|
128
|
+
current_command_tokens = []
|
|
129
|
+
end
|
|
130
|
+
# add the operator
|
|
131
|
+
result << token
|
|
132
|
+
elsif token == COMMAND_DELIMETER
|
|
133
|
+
# add the command
|
|
134
|
+
if current_command_tokens.size != 0
|
|
135
|
+
result << current_command_tokens.join(" ")
|
|
136
|
+
current_command_tokens = []
|
|
137
|
+
end
|
|
138
|
+
else
|
|
139
|
+
# everything else is assumed to be part of a command, inject it
|
|
140
|
+
current_command_tokens << token
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# add the command
|
|
145
|
+
if current_command_tokens.size != 0
|
|
146
|
+
result << current_command_tokens.join(" ")
|
|
147
|
+
current_command_tokens = []
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
return result
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|