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,1294 @@
|
|
|
1
|
+
require 'mtncloud/cli/cli_command'
|
|
2
|
+
|
|
3
|
+
class MtnCloud::Cli::SecurityGroups
|
|
4
|
+
include MtnCloud::Cli::CliCommand
|
|
5
|
+
include MtnCloud::Cli::InfrastructureHelper
|
|
6
|
+
|
|
7
|
+
register_subcommands :list, :get, :add, :update, :remove
|
|
8
|
+
register_subcommands :'add-location', :'remove-location'
|
|
9
|
+
register_subcommands :'add-rule', :'update-rule', :'remove-rule'
|
|
10
|
+
set_default_subcommand :list
|
|
11
|
+
|
|
12
|
+
def connect(opts)
|
|
13
|
+
@api_client = establish_remote_appliance_connection(opts)
|
|
14
|
+
@security_groups_interface = @api_client.security_groups
|
|
15
|
+
@security_group_rules_interface = @api_client.security_group_rules
|
|
16
|
+
@cloud_resource_pools_interface = @api_client.cloud_resource_pools
|
|
17
|
+
@clouds_interface = @api_client.clouds
|
|
18
|
+
@options_interface = @api_client.options
|
|
19
|
+
@active_security_group = ::MtnCloud::Cli::SecurityGroups.load_security_group_file
|
|
20
|
+
@network_security_servers = @api_client.network_security_servers
|
|
21
|
+
@network_servers = @api_client.network_servers
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def handle(args)
|
|
25
|
+
handle_subcommand(args)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def list(args)
|
|
30
|
+
params = {}
|
|
31
|
+
options = {}
|
|
32
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
33
|
+
opts.banner = subcommand_usage()
|
|
34
|
+
build_standard_list_options(opts, options)
|
|
35
|
+
opts.footer = "List security groups."
|
|
36
|
+
end
|
|
37
|
+
optparse.parse!(args)
|
|
38
|
+
# verify_args!(args:args, optparse:optparse, count:0)
|
|
39
|
+
if args.count > 0
|
|
40
|
+
options[:phrase] = args.join(" ")
|
|
41
|
+
end
|
|
42
|
+
connect(options)
|
|
43
|
+
params.merge!(parse_list_options(options))
|
|
44
|
+
@security_groups_interface.setopts(options)
|
|
45
|
+
if options[:dry_run]
|
|
46
|
+
print_dry_run @security_groups_interface.dry.list(params)
|
|
47
|
+
return
|
|
48
|
+
end
|
|
49
|
+
json_response = @security_groups_interface.list(params)
|
|
50
|
+
render_response(json_response, options, "securityGroups") do
|
|
51
|
+
security_groups = json_response['securityGroups']
|
|
52
|
+
title = "Security Groups"
|
|
53
|
+
subtitles = []
|
|
54
|
+
subtitles += parse_list_subtitles(options)
|
|
55
|
+
print_h1 title, subtitles, options
|
|
56
|
+
if security_groups.empty?
|
|
57
|
+
print cyan,"No security groups found.",reset,"\n"
|
|
58
|
+
else
|
|
59
|
+
columns = {
|
|
60
|
+
"ID" => 'id',
|
|
61
|
+
"NAME" => 'name',
|
|
62
|
+
#"DESCRIPTION" => 'description',
|
|
63
|
+
"DESCRIPTION" => lambda {|it| truncate_string(it['description'], 30) },
|
|
64
|
+
#"USED BY" => lambda {|it| it['associations'] ? it['associations'] : '' },
|
|
65
|
+
"SCOPED CLOUD" => lambda {|it| it['zone'] ? it['zone']['name'] : 'All' },
|
|
66
|
+
"SOURCE" => lambda {|it| it['syncSource'] == 'external' ? 'SYNCED' : 'CREATED' }
|
|
67
|
+
}
|
|
68
|
+
print as_pretty_table(security_groups, columns, options)
|
|
69
|
+
print_results_pagination(json_response)
|
|
70
|
+
end
|
|
71
|
+
print reset,"\n"
|
|
72
|
+
end
|
|
73
|
+
return 0, nil
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def get(args)
|
|
77
|
+
options = {}
|
|
78
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
79
|
+
opts.banner = subcommand_usage("[id]")
|
|
80
|
+
build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
|
|
81
|
+
opts.footer = "Get details about a security group."
|
|
82
|
+
end
|
|
83
|
+
optparse.parse!(args)
|
|
84
|
+
if args.count != 1
|
|
85
|
+
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
|
86
|
+
end
|
|
87
|
+
connect(options)
|
|
88
|
+
exit_code, err = 0, nil
|
|
89
|
+
|
|
90
|
+
security_group_id = nil
|
|
91
|
+
if args[0].to_s =~ /\A\d{1,}\Z/
|
|
92
|
+
security_group_id = args[0].to_i
|
|
93
|
+
else
|
|
94
|
+
security_group = find_security_group_by_name(args[0])
|
|
95
|
+
return 1, "Security Group not found" if security_group.nil?
|
|
96
|
+
security_group_id = security_group['id']
|
|
97
|
+
end
|
|
98
|
+
@security_groups_interface.setopts(options)
|
|
99
|
+
if options[:dry_run]
|
|
100
|
+
print_dry_run @security_groups_interface.dry.get(security_group_id)
|
|
101
|
+
return exit_code, err
|
|
102
|
+
end
|
|
103
|
+
json_response = @security_groups_interface.get(security_group_id)
|
|
104
|
+
render_result = render_with_format(json_response, options, 'securityGroup')
|
|
105
|
+
return exit_code, err if render_result
|
|
106
|
+
|
|
107
|
+
security_group = json_response['securityGroup']
|
|
108
|
+
security_group_locations = json_response['locations'] || security_group['locations']
|
|
109
|
+
security_group_rules = json_response['rules'] || security_group['rules']
|
|
110
|
+
|
|
111
|
+
print_h1 "Security Group Details"
|
|
112
|
+
print cyan
|
|
113
|
+
description_cols = {
|
|
114
|
+
"ID" => 'id',
|
|
115
|
+
"Name" => 'name',
|
|
116
|
+
"Description" => 'description',
|
|
117
|
+
"Scoped Cloud" => lambda {|it| it['zone'] ? it['zone']['name'] : 'All' },
|
|
118
|
+
"Source" => lambda {|it| it['syncSource'] == 'external' ? 'SYNCED' : 'CREATED' },
|
|
119
|
+
"Visibility" => 'visibility',
|
|
120
|
+
"Active" => lambda {|it| format_boolean(it['active']) },
|
|
121
|
+
"Tenants" => lambda {|it| it['tenants'] ? it['tenants'].collect {|it| it['name'] }.uniq.sort.join(', ') : '' },
|
|
122
|
+
}
|
|
123
|
+
print_description_list(description_cols, security_group)
|
|
124
|
+
# print reset,"\n"
|
|
125
|
+
|
|
126
|
+
if security_group['resourcePermission'].nil?
|
|
127
|
+
#print "\n", "No group access found", "\n"
|
|
128
|
+
else
|
|
129
|
+
print_h2 "Group Access"
|
|
130
|
+
rows = []
|
|
131
|
+
if security_group['resourcePermission']['all']
|
|
132
|
+
rows.push({"name" => 'All'})
|
|
133
|
+
end
|
|
134
|
+
if security_group['resourcePermission']['sites']
|
|
135
|
+
security_group['resourcePermission']['sites'].each do |site|
|
|
136
|
+
rows.push(site)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
rows = rows.collect do |site|
|
|
140
|
+
{group: site['name'], default: site['default'] ? 'Yes' : ''}
|
|
141
|
+
end
|
|
142
|
+
columns = [:group, :default]
|
|
143
|
+
print cyan
|
|
144
|
+
print as_pretty_table(rows, columns)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
if security_group_locations && security_group_locations.size > 0
|
|
148
|
+
print_h2 "Locations"
|
|
149
|
+
print cyan
|
|
150
|
+
location_cols = {
|
|
151
|
+
"ID" => 'id',
|
|
152
|
+
"CLOUD" => lambda {|it| it['zone'] ? it['zone']['name'] : '' },
|
|
153
|
+
"EXTERNAL ID" => lambda {|it| it['externalId'] },
|
|
154
|
+
"RESOURCE POOL" => lambda {|it| it['zonePool'] ? it['zonePool']['name'] : '' }
|
|
155
|
+
}
|
|
156
|
+
puts as_pretty_table(security_group_locations, location_cols)
|
|
157
|
+
else
|
|
158
|
+
print reset,"\n"
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
if security_group_rules
|
|
162
|
+
if security_group_rules == 0
|
|
163
|
+
#print cyan,"No rules.",reset,"\n"
|
|
164
|
+
else
|
|
165
|
+
print_h2 "Rules"
|
|
166
|
+
print cyan
|
|
167
|
+
# NAME DIRECTION SOURCE DESTINATION RULE TYPE PROTOCOL PORT RANGE
|
|
168
|
+
rule_cols = {
|
|
169
|
+
"ID" => 'id',
|
|
170
|
+
"NAME" => 'name',
|
|
171
|
+
"DIRECTION" => lambda {|it| it['direction'] },
|
|
172
|
+
"SOURCE" => lambda {|it|
|
|
173
|
+
if it['sourceType'] == 'cidr'
|
|
174
|
+
"Network: #{it['source']}"
|
|
175
|
+
elsif it['sourceType'] == 'group'
|
|
176
|
+
"Group: #{it['sourceGroup'] ? it['sourceGroup']['name'] : ''}"
|
|
177
|
+
elsif it['sourceType'] == 'tier'
|
|
178
|
+
"Tier: #{it['sourceTier'] ? it['sourceTier']['name'] : ''}"
|
|
179
|
+
elsif it['sourceType'] == 'instance'
|
|
180
|
+
"Instance"
|
|
181
|
+
else
|
|
182
|
+
it['sourceType']
|
|
183
|
+
end
|
|
184
|
+
},
|
|
185
|
+
"DESTINATION" => lambda {|it|
|
|
186
|
+
if it['destinationType'] == 'cidr'
|
|
187
|
+
"Network: #{it['destination']}"
|
|
188
|
+
elsif it['destinationType'] == 'group'
|
|
189
|
+
"Group: #{it['destinationGroup'] ? it['destinationGroup']['name'] : ''}"
|
|
190
|
+
elsif it['destinationType'] == 'tier'
|
|
191
|
+
"Tier: #{it['destinationTier'] ? it['destinationTier']['name'] : ''}"
|
|
192
|
+
elsif it['destinationType'] == 'instance'
|
|
193
|
+
"Instance"
|
|
194
|
+
else
|
|
195
|
+
it['destinationType']
|
|
196
|
+
end
|
|
197
|
+
},
|
|
198
|
+
"RULE TYPE" => lambda {|it| it['ruleType'] == 'customRule' ? 'Custom' : it['ruleType'] },
|
|
199
|
+
"PROTOCOL" => lambda {|it| it['protocol'] },
|
|
200
|
+
"PORT RANGE" => lambda {|it| it['portRange'] }
|
|
201
|
+
}
|
|
202
|
+
puts as_pretty_table(security_group_rules, rule_cols)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
return exit_code, err
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def add(args)
|
|
210
|
+
params = {}
|
|
211
|
+
options = {:options => {}}
|
|
212
|
+
cloud_id = nil
|
|
213
|
+
resource_pool_id = nil
|
|
214
|
+
tenants = nil
|
|
215
|
+
group_access_all = nil
|
|
216
|
+
group_access_list = nil
|
|
217
|
+
group_defaults_list = nil
|
|
218
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
219
|
+
opts.banner = subcommand_usage("[name] [options]")
|
|
220
|
+
opts.on( '--name Name', String, "Name of the security group" ) do |val|
|
|
221
|
+
options[:options]['name'] = val
|
|
222
|
+
end
|
|
223
|
+
opts.on( '--description Description', String, "Description of the security group" ) do |val|
|
|
224
|
+
options[:options]['description'] = val
|
|
225
|
+
end
|
|
226
|
+
opts.on( '-c', '--cloud CLOUD', "Scoped Cloud Name or ID" ) do |val|
|
|
227
|
+
cloud_id = val
|
|
228
|
+
end
|
|
229
|
+
opts.on( '--resource-pool ID', String, "ID of the Resource Pool for Amazon VPC and Azure Resource Group" ) do |val|
|
|
230
|
+
resource_pool_id = val
|
|
231
|
+
end
|
|
232
|
+
opts.on('--group-access-all [on|off]', String, "Toggle Access for all groups.") do |val|
|
|
233
|
+
group_access_all = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
|
234
|
+
end
|
|
235
|
+
opts.on('--group-access LIST', Array, "Group Access, comma separated list of group IDs.") do |list|
|
|
236
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
|
237
|
+
group_access_list = []
|
|
238
|
+
else
|
|
239
|
+
group_access_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
opts.on('--group-defaults LIST', Array, "Group Default Selection, comma separated list of group IDs") do |list|
|
|
243
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
|
244
|
+
group_defaults_list = []
|
|
245
|
+
else
|
|
246
|
+
group_defaults_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
opts.on('--tenants LIST', Array, "Tenant Access, comma separated list of account IDs") do |list|
|
|
250
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
|
251
|
+
options['tenants'] = []
|
|
252
|
+
else
|
|
253
|
+
options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
opts.on('--can-manage LIST', Array, "Tenant Can Manage, comma separated list of account IDs that can manage") do |list|
|
|
257
|
+
options['canManage'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
|
258
|
+
end
|
|
259
|
+
opts.on('--visibility [private|public]', String, "Visibility") do |val|
|
|
260
|
+
options['visibility'] = val
|
|
261
|
+
end
|
|
262
|
+
opts.on('--active [on|off]', String, "Can be used to disable a security group") do |val|
|
|
263
|
+
options[:options]['active'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
|
264
|
+
end
|
|
265
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
|
266
|
+
opts.footer = "Create a security group." + "\n" +
|
|
267
|
+
"[name] is required. This is the name of the security group."
|
|
268
|
+
end
|
|
269
|
+
optparse.parse!(args)
|
|
270
|
+
if args.count > 1
|
|
271
|
+
raise_command_error "wrong number of arguments, expected 0-1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
|
272
|
+
end
|
|
273
|
+
if args[0]
|
|
274
|
+
options[:options]['name'] = args[0]
|
|
275
|
+
end
|
|
276
|
+
connect(options)
|
|
277
|
+
begin
|
|
278
|
+
|
|
279
|
+
# load cloud
|
|
280
|
+
cloud = nil
|
|
281
|
+
if cloud_id
|
|
282
|
+
cloud = find_cloud_by_name_or_id(cloud_id)
|
|
283
|
+
return 1 if cloud.nil?
|
|
284
|
+
options[:options]['zoneId'] = cloud['id'].to_s
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# construct payload
|
|
288
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
|
|
289
|
+
payload = nil
|
|
290
|
+
if options[:payload]
|
|
291
|
+
payload = options[:payload]
|
|
292
|
+
payload.deep_merge!({'securityGroup' => passed_options}) unless passed_options.empty?
|
|
293
|
+
else
|
|
294
|
+
# prompt for resource folder options
|
|
295
|
+
payload = {
|
|
296
|
+
'securityGroup' => {
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
# allow arbitrary -O options
|
|
300
|
+
payload.deep_merge!({'securityGroup' => passed_options}) unless passed_options.empty?
|
|
301
|
+
|
|
302
|
+
# Name
|
|
303
|
+
options[:options]['name'] = options[:name] if options.key?(:name)
|
|
304
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true}], options[:options])
|
|
305
|
+
payload['securityGroup']['name'] = v_prompt['name']
|
|
306
|
+
|
|
307
|
+
# Description
|
|
308
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false}], options[:options])
|
|
309
|
+
payload['securityGroup']['description'] = v_prompt['description']
|
|
310
|
+
|
|
311
|
+
# Scoped Cloud
|
|
312
|
+
# /api/options/clouds requires groupId...
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
begin
|
|
316
|
+
scoped_clouds = [{"name" => "All", "value" => "all"}]
|
|
317
|
+
clouds_response = @options_interface.options_for_source('cloudsForSecurityGroup',{})
|
|
318
|
+
if clouds_response['data']
|
|
319
|
+
clouds_response['data'].each do |it|
|
|
320
|
+
scoped_clouds << {"name" => it['name'], "value" => it['value']}
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'zoneId', 'fieldLabel' => 'Scoped Cloud', 'type' => 'select', 'selectOptions' => scoped_clouds, 'required' => false, 'defaultValue' => (payload['securityGroup']['zoneId'] || 'all')}], options[:options], @api_client)
|
|
324
|
+
#v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'zoneId', 'fieldLabel' => 'Scoped Cloud', 'type' => 'select', 'optionSource' => 'cloudsForSecurityGroup', 'required' => false}], options[:options], @api_client)
|
|
325
|
+
if !v_prompt['zoneId'].to_s.empty? && v_prompt['zoneId'].to_s != 'all' && v_prompt['zoneId'].to_s != '-1'
|
|
326
|
+
payload['securityGroup']['zoneId'] = v_prompt['zoneId']
|
|
327
|
+
|
|
328
|
+
cloud = find_cloud_by_id(payload['securityGroup']['zoneId'])
|
|
329
|
+
|
|
330
|
+
# parse --resource-pool
|
|
331
|
+
# if resource_pool_id
|
|
332
|
+
# resource_pool = find_resource_pool_by_name_or_id(cloud['id'], resource_pool_id)
|
|
333
|
+
# return 1 if resource_pool.nil?
|
|
334
|
+
# end
|
|
335
|
+
|
|
336
|
+
# prompt for zone specific settings that go under "securityGroup.customOptions" for some reason
|
|
337
|
+
custom_options_values = prompt_security_group_custom_options(options, cloud, resource_pool_id)
|
|
338
|
+
payload['securityGroup'].deep_merge!(custom_options_values)
|
|
339
|
+
end
|
|
340
|
+
rescue => ex
|
|
341
|
+
# raise ex
|
|
342
|
+
print yellow,"Failed to determine the available scoped clouds.",reset,"\n"
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# Group Access
|
|
346
|
+
if group_access_all != nil
|
|
347
|
+
payload['resourcePermissions'] ||= {}
|
|
348
|
+
payload['resourcePermissions']['all'] = group_access_all
|
|
349
|
+
end
|
|
350
|
+
if group_access_list != nil
|
|
351
|
+
payload['resourcePermissions'] ||= {}
|
|
352
|
+
payload['resourcePermissions']['sites'] = group_access_list.collect do |site_id|
|
|
353
|
+
site = {"id" => site_id.to_i}
|
|
354
|
+
if group_defaults_list && group_defaults_list.include?(site_id)
|
|
355
|
+
site["default"] = true
|
|
356
|
+
end
|
|
357
|
+
site
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
# Tenants
|
|
362
|
+
if options['tenants'] || options['canManage']
|
|
363
|
+
payload['tenantPermissions'] = {}
|
|
364
|
+
payload['tenantPermissions']['accounts'] = ((options['tenants'] || []) + (options['canManage'] || [])).uniq
|
|
365
|
+
payload['tenantPermissions']['canManageAccounts'] = options['canManage'] if options['canManage']
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# Visibility
|
|
369
|
+
if options['visibility'] != nil
|
|
370
|
+
payload['securityGroup']['visibility'] = options['visibility']
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
# Active
|
|
374
|
+
if options['active'] != nil
|
|
375
|
+
payload['securityGroup']['active'] = options['active']
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
@security_groups_interface.setopts(options)
|
|
381
|
+
if options[:dry_run]
|
|
382
|
+
print_dry_run @security_groups_interface.dry.create(payload)
|
|
383
|
+
return 0
|
|
384
|
+
end
|
|
385
|
+
json_response = @security_groups_interface.create(payload)
|
|
386
|
+
if options[:json]
|
|
387
|
+
puts as_json(json_response, options)
|
|
388
|
+
return 0
|
|
389
|
+
end
|
|
390
|
+
print_green_success "Created security group #{json_response['securityGroup']['name']}"
|
|
391
|
+
return 0
|
|
392
|
+
rescue RestClient::Exception => e
|
|
393
|
+
print_rest_exception(e, options)
|
|
394
|
+
exit 1
|
|
395
|
+
end
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def update(args)
|
|
399
|
+
params = {}
|
|
400
|
+
options = {:options => {}}
|
|
401
|
+
tenants = nil
|
|
402
|
+
group_access_all = nil
|
|
403
|
+
group_access_list = nil
|
|
404
|
+
group_defaults_list = nil
|
|
405
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
406
|
+
opts.banner = subcommand_usage("[security-group] [options]")
|
|
407
|
+
opts.on( '--name Name', String, "Name of the security group" ) do |val|
|
|
408
|
+
options[:options]['name'] = val
|
|
409
|
+
end
|
|
410
|
+
opts.on( '--description Description', String, "Description of the security group" ) do |val|
|
|
411
|
+
options[:options]['description'] = val
|
|
412
|
+
end
|
|
413
|
+
opts.on('--group-access-all [on|off]', String, "Toggle Access for all groups.") do |val|
|
|
414
|
+
group_access_all = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
|
415
|
+
end
|
|
416
|
+
opts.on('--group-access LIST', Array, "Group Access, comma separated list of group IDs.") do |list|
|
|
417
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
|
418
|
+
group_access_list = []
|
|
419
|
+
else
|
|
420
|
+
group_access_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
opts.on('--group-defaults LIST', Array, "Group Default Selection, comma separated list of group IDs") do |list|
|
|
424
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
|
425
|
+
group_defaults_list = []
|
|
426
|
+
else
|
|
427
|
+
group_defaults_list = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
|
428
|
+
end
|
|
429
|
+
end
|
|
430
|
+
opts.on('--tenants LIST', Array, "Tenant Access, comma separated list of account IDs") do |list|
|
|
431
|
+
if list.size == 1 && list[0] == 'null' # hacky way to clear it
|
|
432
|
+
options['tenants'] = []
|
|
433
|
+
else
|
|
434
|
+
options['tenants'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
|
435
|
+
end
|
|
436
|
+
end
|
|
437
|
+
opts.on('--can-manage LIST', Array, "Tenant Can Manage, comma separated list of account IDs that can manage") do |list|
|
|
438
|
+
options['canManage'] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
|
439
|
+
end
|
|
440
|
+
opts.on('--visibility [private|public]', String, "Visibility") do |val|
|
|
441
|
+
options['visibility'] = val
|
|
442
|
+
end
|
|
443
|
+
opts.on('--active [on|off]', String, "Can be used to disable a security group") do |val|
|
|
444
|
+
options[:options]['active'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
|
445
|
+
end
|
|
446
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
|
447
|
+
opts.footer = "Update a security group." + "\n" +
|
|
448
|
+
"[security-group] is required. This is the name or id of the security group."
|
|
449
|
+
end
|
|
450
|
+
optparse.parse!(args)
|
|
451
|
+
if args.count != 1
|
|
452
|
+
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
|
453
|
+
end
|
|
454
|
+
connect(options)
|
|
455
|
+
begin
|
|
456
|
+
security_group = find_security_group_by_name_or_id(args[0])
|
|
457
|
+
return 1 if security_group.nil?
|
|
458
|
+
|
|
459
|
+
# construct payload
|
|
460
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
|
|
461
|
+
payload = nil
|
|
462
|
+
if options[:payload]
|
|
463
|
+
payload = options[:payload]
|
|
464
|
+
payload['securityGroup'].deep_merge!(passed_options) unless passed_options.empty?
|
|
465
|
+
else
|
|
466
|
+
# prompt for resource folder options
|
|
467
|
+
payload = {
|
|
468
|
+
'securityGroup' => {
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
# allow arbitrary -O options
|
|
472
|
+
payload['securityGroup'].deep_merge!(passed_options) unless passed_options.empty?
|
|
473
|
+
|
|
474
|
+
# Group Access
|
|
475
|
+
if group_access_all != nil
|
|
476
|
+
payload['resourcePermissions'] ||= {}
|
|
477
|
+
payload['resourcePermissions']['all'] = group_access_all
|
|
478
|
+
end
|
|
479
|
+
if group_access_list != nil
|
|
480
|
+
payload['resourcePermissions'] ||= {}
|
|
481
|
+
payload['resourcePermissions']['sites'] = group_access_list.collect do |site_id|
|
|
482
|
+
site = {"id" => site_id.to_i}
|
|
483
|
+
if group_defaults_list && group_defaults_list.include?(site_id)
|
|
484
|
+
site["default"] = true
|
|
485
|
+
end
|
|
486
|
+
site
|
|
487
|
+
end
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
# Tenants
|
|
491
|
+
if options['tenants'] || options['canManage']
|
|
492
|
+
payload['tenantPermissions'] = {}
|
|
493
|
+
payload['tenantPermissions']['accounts'] = ((options['tenants'] || []) + (options['canManage'] || [])).uniq
|
|
494
|
+
payload['tenantPermissions']['canManageAccounts'] = options['canManage'] if options['canManage']
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
# Visibility
|
|
498
|
+
if options['visibility'] != nil
|
|
499
|
+
payload['securityGroup']['visibility'] = options['visibility']
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
# Active
|
|
503
|
+
if options['active'] != nil
|
|
504
|
+
payload['securityGroup']['active'] = options['active']
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
if payload['securityGroup'].empty? && payload['tenantPermissions'].nil? && payload['resourcePermissions'].nil?
|
|
508
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
@security_groups_interface.setopts(options)
|
|
514
|
+
if options[:dry_run]
|
|
515
|
+
print_dry_run @security_groups_interface.dry.update(security_group['id'], payload)
|
|
516
|
+
return 0
|
|
517
|
+
end
|
|
518
|
+
json_response = @security_groups_interface.update(security_group['id'], payload)
|
|
519
|
+
if options[:json]
|
|
520
|
+
puts as_json(json_response, options)
|
|
521
|
+
return 0
|
|
522
|
+
end
|
|
523
|
+
print_green_success "Updated security group #{json_response['securityGroup']['name']}"
|
|
524
|
+
get([security_group['id']])
|
|
525
|
+
return 0
|
|
526
|
+
rescue RestClient::Exception => e
|
|
527
|
+
print_rest_exception(e, options)
|
|
528
|
+
exit 1
|
|
529
|
+
end
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
def remove(args)
|
|
533
|
+
options = {}
|
|
534
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
535
|
+
opts.banner = subcommand_usage("[id]")
|
|
536
|
+
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
|
|
537
|
+
opts.footer = "Delete a security group." + "\n" +
|
|
538
|
+
"[security-group] is required. This is the name or id of the security group."
|
|
539
|
+
end
|
|
540
|
+
optparse.parse!(args)
|
|
541
|
+
if args.count != 1
|
|
542
|
+
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
|
543
|
+
end
|
|
544
|
+
connect(options)
|
|
545
|
+
begin
|
|
546
|
+
security_group = find_security_group_by_name_or_id(args[0])
|
|
547
|
+
return 1 if security_group.nil?
|
|
548
|
+
|
|
549
|
+
unless options[:yes] || MtnCloud::Cli::OptionTypes.confirm("Are you sure you want to delete the security group: #{security_group['name']}?")
|
|
550
|
+
return 9, "aborted command"
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
@security_groups_interface.setopts(options)
|
|
554
|
+
if options[:dry_run]
|
|
555
|
+
print_dry_run @security_groups_interface.dry.delete(security_group['id'])
|
|
556
|
+
return
|
|
557
|
+
end
|
|
558
|
+
json_response = @security_groups_interface.delete(security_group['id'])
|
|
559
|
+
if options[:json]
|
|
560
|
+
puts as_json(json_response, options)
|
|
561
|
+
return 0
|
|
562
|
+
end
|
|
563
|
+
#list([])
|
|
564
|
+
print_green_success "Removed security group #{args[0]}"
|
|
565
|
+
return 0
|
|
566
|
+
rescue RestClient::Exception => e
|
|
567
|
+
print_rest_exception(e, options)
|
|
568
|
+
exit 1
|
|
569
|
+
end
|
|
570
|
+
end
|
|
571
|
+
|
|
572
|
+
def add_location(args)
|
|
573
|
+
cloud_id = nil
|
|
574
|
+
resource_pool_id = nil
|
|
575
|
+
params = {}
|
|
576
|
+
options = {:options => {}}
|
|
577
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
578
|
+
opts.banner = subcommand_usage("[security-group] [options]")
|
|
579
|
+
opts.on( '-c', '--cloud CLOUD', "Cloud Name or ID" ) do |val|
|
|
580
|
+
cloud_id = val
|
|
581
|
+
end
|
|
582
|
+
opts.on( '--resource-pool ID', String, "ID of the Resource Pool for Amazon VPC and Azure Resource Group" ) do |val|
|
|
583
|
+
resource_pool_id = val
|
|
584
|
+
end
|
|
585
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
|
586
|
+
opts.footer = "Add security group to a location (cloud)." + "\n" +
|
|
587
|
+
"[security-group] is required. This is the name or id of the security group."
|
|
588
|
+
end
|
|
589
|
+
optparse.parse!(args)
|
|
590
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
|
591
|
+
connect(options)
|
|
592
|
+
begin
|
|
593
|
+
security_group = find_security_group_by_name_or_id(args[0])
|
|
594
|
+
return 1 if security_group.nil?
|
|
595
|
+
|
|
596
|
+
# construct payload
|
|
597
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
|
|
598
|
+
payload = nil
|
|
599
|
+
if options[:payload]
|
|
600
|
+
payload = options[:payload]
|
|
601
|
+
payload.deep_merge!({'securityGroupLocation' => passed_options}) unless passed_options.empty?
|
|
602
|
+
else
|
|
603
|
+
# prompt for resource folder options
|
|
604
|
+
payload = {
|
|
605
|
+
'securityGroupLocation' => {
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
payload.deep_merge!({'securityGroupLocation' => passed_options}) unless passed_options.empty?
|
|
609
|
+
|
|
610
|
+
cloud = nil
|
|
611
|
+
if cloud_id
|
|
612
|
+
options[:options]['zoneId'] = cloud_id
|
|
613
|
+
end
|
|
614
|
+
# Cloud prompt
|
|
615
|
+
scoped_clouds = []
|
|
616
|
+
clouds_response = @options_interface.options_for_source('cloudsForSecurityGroup',{securityGroupId: security_group['id']})
|
|
617
|
+
if clouds_response['data']
|
|
618
|
+
clouds_response['data'].each do |it|
|
|
619
|
+
scoped_clouds << {"name" => it['name'], "value" => it['value']}
|
|
620
|
+
end
|
|
621
|
+
end
|
|
622
|
+
if scoped_clouds.empty?
|
|
623
|
+
raise_command_error("Security group has 0 available clouds for adding a location", args, optparse)
|
|
624
|
+
end
|
|
625
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'zoneId', 'fieldLabel' => 'Cloud', 'type' => 'select', 'selectOptions' => scoped_clouds, 'required' => true}], options[:options], @api_client)
|
|
626
|
+
payload['securityGroupLocation']['zoneId'] = v_prompt['zoneId']
|
|
627
|
+
cloud = find_cloud_by_id(payload['securityGroupLocation']['zoneId'])
|
|
628
|
+
return 1 if cloud.nil?
|
|
629
|
+
|
|
630
|
+
# parse --resource-pool
|
|
631
|
+
# if resource_pool_id
|
|
632
|
+
# resource_pool = find_resource_pool_by_name_or_id(cloud['id'], resource_pool_id)
|
|
633
|
+
# return 1 if resource_pool.nil?
|
|
634
|
+
# end
|
|
635
|
+
|
|
636
|
+
# prompt for zone specific settings that go under "securityGroup.customOptions" for some reason
|
|
637
|
+
custom_options_values = prompt_security_group_custom_options(options, cloud, resource_pool_id)
|
|
638
|
+
payload['securityGroupLocation'].deep_merge!(custom_options_values)
|
|
639
|
+
end
|
|
640
|
+
@security_groups_interface.setopts(options)
|
|
641
|
+
if options[:dry_run]
|
|
642
|
+
print_dry_run @security_groups_interface.dry.create_location(security_group['id'], payload)
|
|
643
|
+
return 0
|
|
644
|
+
end
|
|
645
|
+
json_response = @security_groups_interface.create_location(security_group['id'], payload)
|
|
646
|
+
if options[:json]
|
|
647
|
+
puts as_json(json_response, options)
|
|
648
|
+
return 0
|
|
649
|
+
end
|
|
650
|
+
print_green_success "Created security group location #{security_group['name']} - #{cloud['name']}"
|
|
651
|
+
get([security_group['id']])
|
|
652
|
+
return 0
|
|
653
|
+
rescue RestClient::Exception => e
|
|
654
|
+
print_rest_exception(e, options)
|
|
655
|
+
exit 1
|
|
656
|
+
end
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
def remove_location(args)
|
|
660
|
+
cloud_id = nil
|
|
661
|
+
resource_pool_id = nil
|
|
662
|
+
params = {}
|
|
663
|
+
options = {:options => {}}
|
|
664
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
665
|
+
opts.banner = subcommand_usage("[security-group] [options]")
|
|
666
|
+
opts.on( '-c', '--cloud CLOUD', "Cloud Name or ID" ) do |val|
|
|
667
|
+
cloud_id = val
|
|
668
|
+
end
|
|
669
|
+
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
|
|
670
|
+
opts.footer = "Remove security group from a location (cloud)." + "\n" +
|
|
671
|
+
"[security-group] is required. This is the name or id of the security group."
|
|
672
|
+
end
|
|
673
|
+
optparse.parse!(args)
|
|
674
|
+
if args.count != 1
|
|
675
|
+
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
|
676
|
+
end
|
|
677
|
+
connect(options)
|
|
678
|
+
begin
|
|
679
|
+
security_group = find_security_group_by_name_or_id(args[0])
|
|
680
|
+
return 1 if security_group.nil?
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
# load cloud
|
|
684
|
+
if cloud_id.nil?
|
|
685
|
+
puts_error "#{MtnCloud::Terminal.angry_prompt}missing required option: [cloud]\n#{optparse}"
|
|
686
|
+
return 1
|
|
687
|
+
end
|
|
688
|
+
cloud = find_cloud_by_name_or_id(cloud_id)
|
|
689
|
+
return 1 if cloud.nil?
|
|
690
|
+
|
|
691
|
+
security_group_location = nil
|
|
692
|
+
if security_group['locations']
|
|
693
|
+
security_group_location = security_group['locations'].find {|it| it['zone']['id'] == cloud['id'] }
|
|
694
|
+
end
|
|
695
|
+
if security_group_location.nil?
|
|
696
|
+
print_red_alert "Security group location not found for cloud #{cloud['name']}"
|
|
697
|
+
return 1
|
|
698
|
+
end
|
|
699
|
+
|
|
700
|
+
unless options[:yes] || MtnCloud::Cli::OptionTypes.confirm("Are you sure you want to delete the security group location #{security_group['name']} - #{cloud['name']}?")
|
|
701
|
+
return 9, "aborted command"
|
|
702
|
+
end
|
|
703
|
+
|
|
704
|
+
@security_groups_interface.setopts(options)
|
|
705
|
+
if options[:dry_run]
|
|
706
|
+
print_dry_run @security_groups_interface.dry.delete_location(security_group['id'], security_group_location['id'])
|
|
707
|
+
return 0
|
|
708
|
+
end
|
|
709
|
+
json_response = @security_groups_interface.delete_location(security_group['id'], security_group_location['id'])
|
|
710
|
+
if options[:json]
|
|
711
|
+
puts as_json(json_response, options)
|
|
712
|
+
return 0
|
|
713
|
+
end
|
|
714
|
+
print_green_success "Created security group location #{security_group['name']} - #{cloud['name']}"
|
|
715
|
+
get([security_group['id']])
|
|
716
|
+
return 0
|
|
717
|
+
rescue RestClient::Exception => e
|
|
718
|
+
print_rest_exception(e, options)
|
|
719
|
+
exit 1
|
|
720
|
+
end
|
|
721
|
+
end
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
def add_rule(args)
|
|
725
|
+
params = {}
|
|
726
|
+
options = {:options => {}}
|
|
727
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
728
|
+
opts.banner = subcommand_usage("[security-group] [options]")
|
|
729
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
|
730
|
+
opts.on( '--name VALUE', String, "Name of the rule" ) do |val|
|
|
731
|
+
options[:options]['name'] = val
|
|
732
|
+
end
|
|
733
|
+
opts.on( '--direction VALUE', String, "Direction" ) do |val|
|
|
734
|
+
options[:options]['direction'] = val
|
|
735
|
+
end
|
|
736
|
+
opts.on( '--rule-type VALUE', String, "Rule Type" ) do |val|
|
|
737
|
+
options[:options]['ruleType'] = val
|
|
738
|
+
end
|
|
739
|
+
opts.on( '--protocol VALUE', String, "Protocol" ) do |val|
|
|
740
|
+
options[:options]['protocol'] = val
|
|
741
|
+
end
|
|
742
|
+
opts.on( '--port-range VALUE', String, "Port Range" ) do |val|
|
|
743
|
+
options[:options]['portRange'] = val
|
|
744
|
+
end
|
|
745
|
+
opts.on( '--source-type VALUE', String, "Source Type" ) do |val|
|
|
746
|
+
options[:options]['sourceType'] = val
|
|
747
|
+
end
|
|
748
|
+
opts.on( '--source VALUE', String, "Source" ) do |val|
|
|
749
|
+
options[:options]['source'] = val
|
|
750
|
+
end
|
|
751
|
+
opts.on( '--source-group VALUE', String, "Source Security Group" ) do |val|
|
|
752
|
+
options[:options]['sourceGroup'] = val
|
|
753
|
+
end
|
|
754
|
+
opts.on( '--source-tier VALUE', String, "Source Tier" ) do |val|
|
|
755
|
+
options[:options]['sourceTier'] = val
|
|
756
|
+
end
|
|
757
|
+
opts.on( '--destination-type VALUE', String, "Destination Type" ) do |val|
|
|
758
|
+
options[:options]['destinationType'] = val
|
|
759
|
+
end
|
|
760
|
+
opts.on( '--destination VALUE', String, "Destination" ) do |val|
|
|
761
|
+
options[:options]['destination'] = val
|
|
762
|
+
end
|
|
763
|
+
opts.on( '--destination-group VALUE', String, "Destination Security Group" ) do |val|
|
|
764
|
+
options[:options]['destinationGroup'] = val
|
|
765
|
+
end
|
|
766
|
+
opts.on( '--destination-tier VALUE', String, "Destination Tier" ) do |val|
|
|
767
|
+
options[:options]['destinationTier'] = val
|
|
768
|
+
end
|
|
769
|
+
opts.footer = "Create a security group rule." + "\n" +
|
|
770
|
+
"[security-group] is required. This is the name or id of the security group." + "\n"
|
|
771
|
+
"[name] is required. This is the name of the security group rule."
|
|
772
|
+
end
|
|
773
|
+
optparse.parse!(args)
|
|
774
|
+
if args.count < 1 || args.count > 2
|
|
775
|
+
raise_command_error "wrong number of arguments, expected 1-2 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
|
776
|
+
end
|
|
777
|
+
connect(options)
|
|
778
|
+
begin
|
|
779
|
+
security_group = find_security_group_by_name_or_id(args[0])
|
|
780
|
+
return 1 if security_group.nil?
|
|
781
|
+
|
|
782
|
+
# construct payload
|
|
783
|
+
if args[1]
|
|
784
|
+
options[:options]['name'] = args[1]
|
|
785
|
+
end
|
|
786
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
|
|
787
|
+
payload = nil
|
|
788
|
+
if options[:payload]
|
|
789
|
+
payload = options[:payload]
|
|
790
|
+
payload.deep_merge!({'rule' => passed_options}) unless passed_options.empty?
|
|
791
|
+
else
|
|
792
|
+
# prompt for resource folder options
|
|
793
|
+
payload = {
|
|
794
|
+
'rule' => {
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
payload.deep_merge!({'rule' => passed_options}) unless passed_options.empty?
|
|
798
|
+
|
|
799
|
+
# prompt
|
|
800
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true}], options[:options])
|
|
801
|
+
payload['rule']['name'] = v_prompt['name'] unless v_prompt['name'].nil?
|
|
802
|
+
|
|
803
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'direction', 'fieldLabel' => 'Direction', 'type' => 'select', 'optionSource' => 'securityGroupDirection', 'required' => true, 'defaultValue' => 'ingress'}], options[:options], @api_client)
|
|
804
|
+
payload['rule']['direction'] = v_prompt['direction'] unless v_prompt['direction'].nil?
|
|
805
|
+
|
|
806
|
+
rule_types = [{"name" => "Custom Rule", "value" => "customRule"}]
|
|
807
|
+
instance_types = @options_interface.options_for_source('instanceTypes',{})
|
|
808
|
+
if instance_types['data']
|
|
809
|
+
instance_types['data'].each do |it|
|
|
810
|
+
rule_types << {"name" => it['name'], "value" => it['code'] || it['value']}
|
|
811
|
+
end
|
|
812
|
+
end
|
|
813
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'ruleType', 'fieldLabel' => 'Rule Type', 'type' => 'select', 'selectOptions' => rule_types, 'required' => true, 'defaultValue' => 'customRule'}], options[:options], @api_client)
|
|
814
|
+
payload['rule']['ruleType'] = v_prompt['ruleType'] unless v_prompt['ruleType'].nil?
|
|
815
|
+
|
|
816
|
+
if payload['rule']['ruleType'] == 'customRule'
|
|
817
|
+
|
|
818
|
+
protocols = [{"name" => "TCP", "value" => "tcp"}, {"name" => "UDP", "value" => "udp"}, {"name" => "ICMP", "value" => "icmp"}]
|
|
819
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'protocol', 'fieldLabel' => 'Protocol', 'type' => 'select', 'selectOptions' => protocols, 'required' => true, 'defaultValue' => 'tcp'}], options[:options], @api_client)
|
|
820
|
+
payload['rule']['protocol'] = v_prompt['protocol'] unless v_prompt['protocol'].nil?
|
|
821
|
+
|
|
822
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'portRange', 'fieldLabel' => 'Port Range', 'type' => 'text', 'required' => true}], options[:options])
|
|
823
|
+
payload['rule']['portRange'] = v_prompt['portRange'] unless v_prompt['portRange'].nil?
|
|
824
|
+
|
|
825
|
+
end
|
|
826
|
+
|
|
827
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'sourceType', 'fieldLabel' => 'Source Type', 'type' => 'select', 'optionSource' => 'securityGroupSourceType', 'required' => true, 'defaultValue' => 'cidr'}], options[:options], @api_client, {'rule.securityGroupId': security_group['id'], 'securityGroupRule.direction': payload['rule']['direction']})
|
|
828
|
+
payload['rule']['sourceType'] = v_prompt['sourceType'] unless v_prompt['sourceType'].nil?
|
|
829
|
+
|
|
830
|
+
if payload['rule']['sourceType'] == 'cidr'
|
|
831
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'source', 'fieldLabel' => 'Source', 'type' => 'text', 'required' => true, 'description' => 'Source CIDR eg. 0.0.0.0/0'}], options[:options])
|
|
832
|
+
payload['rule']['source'] = v_prompt['source'] unless v_prompt['source'].nil?
|
|
833
|
+
elsif payload['rule']['sourceType'] == 'group'
|
|
834
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'sourceGroup', 'fieldLabel' => 'Source Security Group', 'type' => 'select', 'optionSource' => 'securityGroups', 'required' => true}], options[:options], @api_client)
|
|
835
|
+
payload['rule']['sourceGroup'] = {"id" => v_prompt['sourceGroup']} unless v_prompt['sourceGroup'].nil?
|
|
836
|
+
elsif payload['rule']['sourceType'] == 'tier'
|
|
837
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'sourceTier', 'fieldLabel' => 'Source Tier', 'type' => 'select', 'optionSource' => 'tiers', 'required' => true}], options[:options], @api_client)
|
|
838
|
+
payload['rule']['sourceTier'] = {"id" => v_prompt['sourceTier']} unless v_prompt['sourceTier'].nil?
|
|
839
|
+
end
|
|
840
|
+
|
|
841
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'destinationType', 'fieldLabel' => 'Destination Type', 'type' => 'select', 'optionSource' => 'securityGroupDestinationType', 'required' => true, 'defaultValue' => 'instance'}], options[:options], @api_client, {'rule.securityGroupId': security_group['id'], 'securityGroupRule.direction': payload['rule']['direction']})
|
|
842
|
+
payload['rule']['destinationType'] = v_prompt['destinationType'] unless v_prompt['destinationType'].nil?
|
|
843
|
+
|
|
844
|
+
if payload['rule']['destinationType'] == 'cidr'
|
|
845
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'destination', 'fieldLabel' => 'Destination', 'type' => 'text', 'required' => true, 'description' => 'Destination CIDR eg. 0.0.0.0/0'}], options[:options])
|
|
846
|
+
payload['rule']['destination'] = v_prompt['destination'] unless v_prompt['destination'].nil?
|
|
847
|
+
elsif payload['rule']['destinationType'] == 'group'
|
|
848
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'destinationGroup', 'fieldLabel' => 'Destination Security Group', 'type' => 'select', 'optionSource' => 'securityGroups', 'required' => true}], options[:options], @api_client)
|
|
849
|
+
payload['rule']['destinationGroup'] = {"id" => v_prompt['destinationGroup']} unless v_prompt['destinationGroup'].nil?
|
|
850
|
+
elsif payload['rule']['destinationType'] == 'tier'
|
|
851
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt([{'fieldName' => 'destinationTier', 'fieldLabel' => 'Destination Tier', 'type' => 'select', 'optionSource' => 'tiers', 'required' => true}], options[:options], @api_client)
|
|
852
|
+
payload['rule']['destinationTier'] = {"id" => v_prompt['destinationTier']} unless v_prompt['destinationTier'].nil?
|
|
853
|
+
end
|
|
854
|
+
|
|
855
|
+
end
|
|
856
|
+
|
|
857
|
+
@security_group_rules_interface.setopts(options)
|
|
858
|
+
if options[:dry_run]
|
|
859
|
+
print_dry_run @security_group_rules_interface.dry.create(security_group['id'], payload)
|
|
860
|
+
return 0
|
|
861
|
+
end
|
|
862
|
+
json_response = @security_group_rules_interface.create(security_group['id'], payload)
|
|
863
|
+
if options[:json]
|
|
864
|
+
puts as_json(json_response, options)
|
|
865
|
+
return 0
|
|
866
|
+
end
|
|
867
|
+
display_name = (json_response['rule'] && json_response['rule']['name'].to_s != '') ? json_response['rule']['name'] : json_response['rule']['id']
|
|
868
|
+
print_green_success "Created security group rule #{display_name}"
|
|
869
|
+
get([security_group['id']])
|
|
870
|
+
return 0
|
|
871
|
+
rescue RestClient::Exception => e
|
|
872
|
+
print_rest_exception(e, options)
|
|
873
|
+
exit 1
|
|
874
|
+
end
|
|
875
|
+
end
|
|
876
|
+
|
|
877
|
+
def remove_rule(args)
|
|
878
|
+
params = {}
|
|
879
|
+
options = {:options => {}}
|
|
880
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
881
|
+
opts.banner = subcommand_usage("[security-group] [id]")
|
|
882
|
+
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
|
|
883
|
+
opts.footer = "Delete a security group rule." + "\n" +
|
|
884
|
+
"[security-group] is required. This is the name or id of the security group." + "\n"
|
|
885
|
+
"[rule] is required. This is the name or id of the security group rule."
|
|
886
|
+
end
|
|
887
|
+
optparse.parse!(args)
|
|
888
|
+
if args.count != 2
|
|
889
|
+
raise_command_error "wrong number of arguments, expected 2 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
|
890
|
+
end
|
|
891
|
+
connect(options)
|
|
892
|
+
begin
|
|
893
|
+
security_group = find_security_group_by_name_or_id(args[0])
|
|
894
|
+
return 1 if security_group.nil?
|
|
895
|
+
|
|
896
|
+
#security_group_rule = find_security_group_rule_by_id(security_group['id'], args[1])
|
|
897
|
+
#return 1 if security_group_rule.nil?
|
|
898
|
+
|
|
899
|
+
security_group_rule = nil
|
|
900
|
+
if security_group['rules']
|
|
901
|
+
matching_rules = []
|
|
902
|
+
if args[1].to_s =~ /\A\d{1,}\Z/
|
|
903
|
+
matching_rules = security_group['rules'].select {|it| it['id'].to_s == args[1].to_s }
|
|
904
|
+
else
|
|
905
|
+
matching_rules = security_group['rules'].select {|it| it['name'] == args[1].to_s }
|
|
906
|
+
end
|
|
907
|
+
if matching_rules.size > 1
|
|
908
|
+
print_red_alert "#{matching_rules.size} security group rules found by name '#{args[1]}'"
|
|
909
|
+
rows = matching_rules.collect do |it|
|
|
910
|
+
{id: it['id'], name: it['name']}
|
|
911
|
+
end
|
|
912
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
|
913
|
+
return 1
|
|
914
|
+
else
|
|
915
|
+
security_group_rule = matching_rules[0]
|
|
916
|
+
end
|
|
917
|
+
end
|
|
918
|
+
if security_group_rule.nil?
|
|
919
|
+
print_red_alert "Security group rule not found for '#{args[1]}'"
|
|
920
|
+
return 1
|
|
921
|
+
end
|
|
922
|
+
|
|
923
|
+
unless options[:yes] || MtnCloud::Cli::OptionTypes.confirm("Are you sure you want to delete the security group rule: #{security_group_rule['id']}?")
|
|
924
|
+
return 9, "aborted command"
|
|
925
|
+
end
|
|
926
|
+
|
|
927
|
+
@security_groups_interface.setopts(options)
|
|
928
|
+
if options[:dry_run]
|
|
929
|
+
print_dry_run @security_group_rules_interface.dry.delete(security_group['id'], security_group_rule['id'])
|
|
930
|
+
return 0
|
|
931
|
+
end
|
|
932
|
+
json_response = @security_group_rules_interface.delete(security_group['id'], security_group_rule['id'])
|
|
933
|
+
if options[:json]
|
|
934
|
+
puts as_json(json_response, options)
|
|
935
|
+
return 0
|
|
936
|
+
end
|
|
937
|
+
display_name = (security_group_rule['name'].to_s != '') ? security_group_rule['name'] : security_group_rule['id'].to_s
|
|
938
|
+
print_green_success "Deleted security group rule #{display_name}"
|
|
939
|
+
get([security_group['id']])
|
|
940
|
+
return 0
|
|
941
|
+
rescue RestClient::Exception => e
|
|
942
|
+
print_rest_exception(e, options)
|
|
943
|
+
exit 1
|
|
944
|
+
end
|
|
945
|
+
end
|
|
946
|
+
|
|
947
|
+
def update_rule(args)
|
|
948
|
+
params = {}
|
|
949
|
+
options = {:options => {}}
|
|
950
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
951
|
+
opts.banner = subcommand_usage("[security-group] [rule]")
|
|
952
|
+
opts.on( '--name VALUE', String, "Name of the rule" ) do |val|
|
|
953
|
+
options[:options]['name'] = val
|
|
954
|
+
end
|
|
955
|
+
opts.on( '--direction VALUE', String, "Direction" ) do |val|
|
|
956
|
+
options[:options]['direction'] = val
|
|
957
|
+
end
|
|
958
|
+
opts.on( '--rule-type VALUE', String, "Rule Type" ) do |val|
|
|
959
|
+
options[:options]['ruleType'] = val
|
|
960
|
+
end
|
|
961
|
+
opts.on( '--protocol VALUE', String, "Protocol" ) do |val|
|
|
962
|
+
options[:options]['protocol'] = val
|
|
963
|
+
end
|
|
964
|
+
opts.on( '--port-range VALUE', String, "Port Range" ) do |val|
|
|
965
|
+
options[:options]['portRange'] = val
|
|
966
|
+
end
|
|
967
|
+
opts.on( '--source-type VALUE', String, "Source Type" ) do |val|
|
|
968
|
+
options[:options]['sourceType'] = val
|
|
969
|
+
end
|
|
970
|
+
opts.on( '--source VALUE', String, "Source" ) do |val|
|
|
971
|
+
options[:options]['source'] = val
|
|
972
|
+
end
|
|
973
|
+
opts.on( '--source-group VALUE', String, "Source Security Group" ) do |val|
|
|
974
|
+
options[:options]['sourceGroup'] = val
|
|
975
|
+
end
|
|
976
|
+
opts.on( '--source-tier VALUE', String, "Source Tier" ) do |val|
|
|
977
|
+
options[:options]['sourceTier'] = val
|
|
978
|
+
end
|
|
979
|
+
opts.on( '--destination-type VALUE', String, "Destination Type" ) do |val|
|
|
980
|
+
options[:options]['destinationType'] = val
|
|
981
|
+
end
|
|
982
|
+
opts.on( '--destination VALUE', String, "Destination" ) do |val|
|
|
983
|
+
options[:options]['destination'] = val
|
|
984
|
+
end
|
|
985
|
+
opts.on( '--destination-group VALUE', String, "Destination Security Group" ) do |val|
|
|
986
|
+
options[:options]['destinationGroup'] = val
|
|
987
|
+
end
|
|
988
|
+
opts.on( '--destination-tier VALUE', String, "Destination Tier" ) do |val|
|
|
989
|
+
options[:options]['destinationTier'] = val
|
|
990
|
+
end
|
|
991
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
|
992
|
+
opts.footer = "Update a security group rule." + "\n" +
|
|
993
|
+
"[security-group] is required. This is the name or id of the security group." + "\n"
|
|
994
|
+
"[rule] is required. This is the name or id of the security group rule."
|
|
995
|
+
end
|
|
996
|
+
optparse.parse!(args)
|
|
997
|
+
if args.count != 2
|
|
998
|
+
raise_command_error "wrong number of arguments, expected 2 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
|
999
|
+
end
|
|
1000
|
+
connect(options)
|
|
1001
|
+
begin
|
|
1002
|
+
security_group = find_security_group_by_name_or_id(args[0])
|
|
1003
|
+
return 1 if security_group.nil?
|
|
1004
|
+
|
|
1005
|
+
#security_group_rule = find_security_group_rule_by_id(security_group['id'], args[1])
|
|
1006
|
+
#return 1 if security_group_rule.nil?
|
|
1007
|
+
|
|
1008
|
+
security_group_rule = nil
|
|
1009
|
+
if security_group['rules']
|
|
1010
|
+
matching_rules = []
|
|
1011
|
+
if args[1].to_s =~ /\A\d{1,}\Z/
|
|
1012
|
+
matching_rules = security_group['rules'].select {|it| it['id'].to_s == args[1].to_s }
|
|
1013
|
+
else
|
|
1014
|
+
matching_rules = security_group['rules'].select {|it| it['name'] == args[1].to_s }
|
|
1015
|
+
end
|
|
1016
|
+
if matching_rules.size > 1
|
|
1017
|
+
print_red_alert "#{matching_rules.size} security group rules found by name '#{args[1]}'"
|
|
1018
|
+
rows = matching_rules.collect do |it|
|
|
1019
|
+
{id: it['id'], name: it['name']}
|
|
1020
|
+
end
|
|
1021
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
|
1022
|
+
return 1
|
|
1023
|
+
else
|
|
1024
|
+
security_group_rule = matching_rules[0]
|
|
1025
|
+
end
|
|
1026
|
+
end
|
|
1027
|
+
if security_group_rule.nil?
|
|
1028
|
+
print_red_alert "Security group rule not found for '#{args[1]}'"
|
|
1029
|
+
return 1
|
|
1030
|
+
end
|
|
1031
|
+
|
|
1032
|
+
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
|
|
1033
|
+
payload = nil
|
|
1034
|
+
if options[:payload]
|
|
1035
|
+
payload = options[:payload]
|
|
1036
|
+
payload.deep_merge!({'rule' => passed_options}) unless passed_options.empty?
|
|
1037
|
+
else
|
|
1038
|
+
# prompt for resource folder options
|
|
1039
|
+
payload = {
|
|
1040
|
+
'rule' => {
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
payload.deep_merge!({'rule' => passed_options}) unless passed_options.empty?
|
|
1044
|
+
|
|
1045
|
+
if passed_options.empty?
|
|
1046
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
|
1047
|
+
end
|
|
1048
|
+
|
|
1049
|
+
end
|
|
1050
|
+
|
|
1051
|
+
@security_groups_interface.setopts(options)
|
|
1052
|
+
if options[:dry_run]
|
|
1053
|
+
print_dry_run @security_group_rules_interface.dry.update(security_group['id'], security_group_rule['id'], payload)
|
|
1054
|
+
return 0
|
|
1055
|
+
end
|
|
1056
|
+
json_response = @security_group_rules_interface.update(security_group['id'], security_group_rule['id'], payload)
|
|
1057
|
+
if options[:json]
|
|
1058
|
+
puts as_json(json_response, options)
|
|
1059
|
+
return 0
|
|
1060
|
+
end
|
|
1061
|
+
security_group_rule = json_response['rule']
|
|
1062
|
+
display_name = (security_group_rule['name'].to_s != '') ? security_group_rule['name'] : security_group_rule['id'].to_s
|
|
1063
|
+
print_green_success "Updated security group rule #{display_name}"
|
|
1064
|
+
get([security_group['id']])
|
|
1065
|
+
return 0
|
|
1066
|
+
rescue RestClient::Exception => e
|
|
1067
|
+
print_rest_exception(e, options)
|
|
1068
|
+
exit 1
|
|
1069
|
+
end
|
|
1070
|
+
end
|
|
1071
|
+
|
|
1072
|
+
# JD: still need this??
|
|
1073
|
+
def use(args)
|
|
1074
|
+
options = {}
|
|
1075
|
+
optparse = MtnCloud::Cli::OptionParser.new do |opts|
|
|
1076
|
+
opts.banner = subcommand_usage("[id] [--none]")
|
|
1077
|
+
opts.on('--none','--none', "Do not use an active group.") do |json|
|
|
1078
|
+
options[:unuse] = true
|
|
1079
|
+
end
|
|
1080
|
+
build_common_options(opts, options, [])
|
|
1081
|
+
end
|
|
1082
|
+
optparse.parse!(args)
|
|
1083
|
+
if args.length < 1 && !options[:unuse]
|
|
1084
|
+
puts optparse
|
|
1085
|
+
return
|
|
1086
|
+
end
|
|
1087
|
+
connect(options)
|
|
1088
|
+
begin
|
|
1089
|
+
|
|
1090
|
+
if options[:unuse]
|
|
1091
|
+
if @active_security_group[@appliance_name.to_sym]
|
|
1092
|
+
@active_security_group.delete(@appliance_name.to_sym)
|
|
1093
|
+
end
|
|
1094
|
+
::MtnCloud::Cli::SecurityGroups.save_security_group(@active_security_group)
|
|
1095
|
+
unless options[:quiet]
|
|
1096
|
+
print cyan
|
|
1097
|
+
puts "Switched to no active security group."
|
|
1098
|
+
print reset
|
|
1099
|
+
end
|
|
1100
|
+
print reset
|
|
1101
|
+
return # exit 0
|
|
1102
|
+
end
|
|
1103
|
+
|
|
1104
|
+
security_group = find_security_group_by_name_or_id(args[0])
|
|
1105
|
+
return 1 if security_group.nil?
|
|
1106
|
+
|
|
1107
|
+
if !security_group.nil?
|
|
1108
|
+
@active_security_group[@appliance_name.to_sym] = security_group['id']
|
|
1109
|
+
::MtnCloud::Cli::SecurityGroups.save_security_group(@active_security_group)
|
|
1110
|
+
puts cyan, "Using Security Group #{args[0]}", reset
|
|
1111
|
+
else
|
|
1112
|
+
puts red, "Security Group not found", reset
|
|
1113
|
+
end
|
|
1114
|
+
return 0
|
|
1115
|
+
rescue RestClient::Exception => e
|
|
1116
|
+
print_rest_exception(e, options)
|
|
1117
|
+
exit 1
|
|
1118
|
+
end
|
|
1119
|
+
end
|
|
1120
|
+
|
|
1121
|
+
def unuse(args)
|
|
1122
|
+
use(args + ['--none'])
|
|
1123
|
+
end
|
|
1124
|
+
|
|
1125
|
+
def self.load_security_group_file
|
|
1126
|
+
remote_file = security_group_file_path
|
|
1127
|
+
if File.exist? remote_file
|
|
1128
|
+
return YAML.load_file(remote_file)
|
|
1129
|
+
else
|
|
1130
|
+
{}
|
|
1131
|
+
end
|
|
1132
|
+
end
|
|
1133
|
+
|
|
1134
|
+
def self.security_group_file_path
|
|
1135
|
+
File.join(MtnCloud::Cli.home_directory,"securitygroup")
|
|
1136
|
+
end
|
|
1137
|
+
|
|
1138
|
+
def self.save_security_group(new_config)
|
|
1139
|
+
fn = security_group_file_path
|
|
1140
|
+
if !Dir.exist?(File.dirname(fn))
|
|
1141
|
+
FileUtils.mkdir_p(File.dirname(fn))
|
|
1142
|
+
end
|
|
1143
|
+
File.open(fn, 'w') {|f| f.write new_config.to_yaml } #Store
|
|
1144
|
+
FileUtils.chmod(0600, fn)
|
|
1145
|
+
new_config
|
|
1146
|
+
end
|
|
1147
|
+
|
|
1148
|
+
private
|
|
1149
|
+
|
|
1150
|
+
def find_security_group_by_name_or_id(val)
|
|
1151
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
|
1152
|
+
return find_security_group_by_id(val)
|
|
1153
|
+
else
|
|
1154
|
+
return find_security_group_by_name(val)
|
|
1155
|
+
end
|
|
1156
|
+
end
|
|
1157
|
+
|
|
1158
|
+
def find_security_group_by_id(id)
|
|
1159
|
+
begin
|
|
1160
|
+
json_response = @security_groups_interface.get(id.to_i)
|
|
1161
|
+
return json_response['securityGroup']
|
|
1162
|
+
rescue RestClient::Exception => e
|
|
1163
|
+
if e.response && e.response.code == 404
|
|
1164
|
+
print_red_alert "Security Group not found by id #{id}"
|
|
1165
|
+
return nil
|
|
1166
|
+
else
|
|
1167
|
+
raise e
|
|
1168
|
+
end
|
|
1169
|
+
end
|
|
1170
|
+
end
|
|
1171
|
+
|
|
1172
|
+
def find_security_group_by_name(name)
|
|
1173
|
+
json_response = @security_groups_interface.list({name: name.to_s})
|
|
1174
|
+
security_groups = json_response['securityGroups']
|
|
1175
|
+
if security_groups.empty?
|
|
1176
|
+
print_red_alert "Security Group not found by name #{name}"
|
|
1177
|
+
return nil
|
|
1178
|
+
elsif security_groups.size > 1
|
|
1179
|
+
print_red_alert "#{security_groups.size} security groups found by name #{name}"
|
|
1180
|
+
rows = security_groups.collect do |it|
|
|
1181
|
+
{id: it['id'], name: it['name']}
|
|
1182
|
+
end
|
|
1183
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
|
1184
|
+
return nil
|
|
1185
|
+
else
|
|
1186
|
+
return security_groups[0]
|
|
1187
|
+
end
|
|
1188
|
+
end
|
|
1189
|
+
|
|
1190
|
+
def find_security_group_rule_by_id(security_group_id, id)
|
|
1191
|
+
begin
|
|
1192
|
+
json_response = @security_groups_interface.get(security_group_id.to_i, id.to_i)
|
|
1193
|
+
return json_response['rule']
|
|
1194
|
+
rescue RestClient::Exception => e
|
|
1195
|
+
if e.response && e.response.code == 404
|
|
1196
|
+
print_red_alert "Security Group Rule not found by id #{id}"
|
|
1197
|
+
return nil
|
|
1198
|
+
else
|
|
1199
|
+
raise e
|
|
1200
|
+
end
|
|
1201
|
+
end
|
|
1202
|
+
end
|
|
1203
|
+
|
|
1204
|
+
def find_resource_pool_by_name_or_id(cloud_id, val)
|
|
1205
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
|
1206
|
+
return find_resource_pool_by_id(cloud_id, val)
|
|
1207
|
+
else
|
|
1208
|
+
return find_resource_pool_by_name(cloud_id, val)
|
|
1209
|
+
end
|
|
1210
|
+
end
|
|
1211
|
+
|
|
1212
|
+
def find_resource_pool_by_id(cloud_id, id)
|
|
1213
|
+
begin
|
|
1214
|
+
json_response = @cloud_resource_pools_interface.get(cloud_id, id.to_i)
|
|
1215
|
+
return json_response['resourcePool']
|
|
1216
|
+
rescue RestClient::Exception => e
|
|
1217
|
+
if e.response && e.response.code == 404
|
|
1218
|
+
print_red_alert "Resource Pool not found by id #{id}"
|
|
1219
|
+
return nil
|
|
1220
|
+
else
|
|
1221
|
+
raise e
|
|
1222
|
+
end
|
|
1223
|
+
end
|
|
1224
|
+
end
|
|
1225
|
+
|
|
1226
|
+
def find_resource_pool_by_name(cloud_id, name)
|
|
1227
|
+
json_response = @cloud_resource_pools_interface.list(cloud_id, {name: name.to_s})
|
|
1228
|
+
resource_pools = json_response['resourcePools']
|
|
1229
|
+
if resource_pools.empty?
|
|
1230
|
+
print_red_alert "Resource Pool not found by name #{name}"
|
|
1231
|
+
return nil
|
|
1232
|
+
elsif resource_pools.size > 1
|
|
1233
|
+
matching_resource_pools = resource_pools.select { |it| name && (it['name'] == name || it['externalId'] == name) }
|
|
1234
|
+
if matching_resource_pools.size == 1
|
|
1235
|
+
return matching_resource_pools[0]
|
|
1236
|
+
end
|
|
1237
|
+
print_red_alert "#{resource_pools.size} resource pools found by name #{name}"
|
|
1238
|
+
rows = resource_pools.collect do |it|
|
|
1239
|
+
{id: it['id'], name: it['name']}
|
|
1240
|
+
end
|
|
1241
|
+
print "\n"
|
|
1242
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
|
1243
|
+
return nil
|
|
1244
|
+
else
|
|
1245
|
+
resource_pool = resource_pools[0]
|
|
1246
|
+
# merge in tenants map
|
|
1247
|
+
if json_response['tenants'] && json_response['tenants'][resource_pool['id']]
|
|
1248
|
+
resource_pool['tenants'] = json_response['tenants'][resource_pool['id']]
|
|
1249
|
+
end
|
|
1250
|
+
return resource_pool
|
|
1251
|
+
end
|
|
1252
|
+
end
|
|
1253
|
+
|
|
1254
|
+
def prompt_security_group_custom_options(options, cloud, resource_pool_id=nil)
|
|
1255
|
+
custom_options_values = {}
|
|
1256
|
+
# Custom Options prompt
|
|
1257
|
+
# securityServer is no longer used, it has been replaced by networkServer,
|
|
1258
|
+
# default to the cloud type code, since it's the same...
|
|
1259
|
+
# no optionTypes returned here, so hard coded by type
|
|
1260
|
+
# The API used to return securityServer which could be fetched to get its optionTypes
|
|
1261
|
+
if cloud['securityServer']
|
|
1262
|
+
sec_server = @network_security_servers.get(cloud['securityServer']['id'])['networkSecurityServer']
|
|
1263
|
+
if sec_server['type']
|
|
1264
|
+
v_prompt = MtnCloud::Cli::OptionTypes.prompt(sec_server['type']['optionTypes'], options[:options], @api_client, {zoneId: cloud['id']})
|
|
1265
|
+
custom_options_values.deep_merge!(v_prompt)
|
|
1266
|
+
end
|
|
1267
|
+
else
|
|
1268
|
+
network_server_type = cloud['networkServer'] ? cloud['networkServer']['type'] : (cloud['securityServer'] ? cloud['securityServer']['type'] : cloud["zoneType"]["code"])
|
|
1269
|
+
if network_server_type == 'amazon'
|
|
1270
|
+
if cloud['config'] && !cloud['config']['vpc'].to_s.empty?
|
|
1271
|
+
custom_options_values.deep_merge!({'customOptions' => {'vpc' => cloud['config']['vpc']} })
|
|
1272
|
+
else
|
|
1273
|
+
options[:options].deep_merge!({'customOptions' => {'vpc' => resource_pool_id} }) if resource_pool_id
|
|
1274
|
+
custom_options_values = MtnCloud::Cli::OptionTypes.prompt([{'fieldContext' => 'customOptions', 'fieldName' => 'vpc', 'fieldLabel' => 'VPC', 'type' => 'select', 'optionSource' => 'zonePools', 'required' => true, 'config' => {'valueField' => 'externalId'}}], options[:options], @api_client, {zoneId: cloud['id'], ignoreDefaultPool: true})
|
|
1275
|
+
end
|
|
1276
|
+
elsif network_server_type == 'azure' || network_server_type == 'azurestack'
|
|
1277
|
+
if cloud['config'] && !cloud['config']['resourceGroup'].to_s.empty?
|
|
1278
|
+
custom_options_values.deep_merge!({'customOptions' => {'resourceGroup' => cloud['config']['resourceGroup']} })
|
|
1279
|
+
else
|
|
1280
|
+
options[:options].deep_merge!({'customOptions' => {'resourceGroup' => resource_pool_id} }) if resource_pool_id
|
|
1281
|
+
custom_options_values = MtnCloud::Cli::OptionTypes.prompt([{'fieldContext' => 'customOptions', 'fieldName' => 'resourceGroup', 'fieldLabel' => 'Resource Group', 'type' => 'select', 'optionSource' => 'zonePools', 'required' => true, 'config' => {'valueField' => 'externalId'}}], options[:options], @api_client, {zoneId: cloud['id'], ignoreDefaultPool: true})
|
|
1282
|
+
end
|
|
1283
|
+
elsif network_server_type == 'openstack' || network_server_type == 'opentelekom' || network_server_type == 'huawei'
|
|
1284
|
+
if cloud['config'] && !cloud['config']['resourcePoolId'].to_s.empty?
|
|
1285
|
+
custom_options_values.deep_merge!({'customOptions' => {'resourcePoolId' => cloud['config']['resourcePoolId']} })
|
|
1286
|
+
else
|
|
1287
|
+
options[:options].deep_merge!({'customOptions' => {'resourcePoolId' => resource_pool_id} }) if resource_pool_id
|
|
1288
|
+
custom_options_values = MtnCloud::Cli::OptionTypes.prompt([{'fieldContext' => 'customOptions', 'fieldName' => 'resourcePoolId', 'fieldLabel' => 'Resource Pool', 'type' => 'select', 'optionSource' => 'zonePools', 'required' => true}], options[:options], @api_client, {zoneId: cloud['id'], ignoreDefaultPool: true})
|
|
1289
|
+
end
|
|
1290
|
+
end
|
|
1291
|
+
end
|
|
1292
|
+
return custom_options_values
|
|
1293
|
+
end
|
|
1294
|
+
end
|