Server IP : 85.214.239.14 / Your IP : 3.23.102.79 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/ansible_collections/google/cloud/scripts/ |
Upload File : |
#!/usr/bin/env bash # cleanup-project cleans up an ansible testing project # # WARNING: do not run tests against a project while # this is running, or else your tests will fail. # # dependencies: # - google-cloud-sdk (gcloudgcloud ) set -e PROJECT_ID="${1}" FOLDER_ID="${2}" # service account is unused today # SERVICE_ACCOUNT_NAME="${2}" ZONE="us-central1-a" main() { # note: the ordering here is deliberate, to start with # leaf resources and work upwards to parent resources. cleanup_resource_per_region "compute" "vpn-tunnels" cleanup_resource "compute" "instances" "" "--zone=$ZONE" cleanup_resource_per_region "compute" "addresses" cleanup_resource "compute" "target-http-proxies" "" "--global" cleanup_resource "compute" "forwarding-rules" "--global" "--global" cleanup_resource "compute" "forwarding-rules" \ "--regions=us-central1" "--region=us-central1" cleanup_resource "compute" "url-maps" "--global" "--global" cleanup_resource "compute" "url-maps" \ "--regions=us-central1" "--region=us-central1" cleanup_resource "compute" "backend-services" "--global" "--global" cleanup_resource "compute" "backend-services" \ "--regions=us-central1" "--region=us-central1" for resource in $(gcloud projects list --filter="parent.id:$FOLDER_ID" --format="csv[no-heading](PROJECT_ID)"); do gcloud projects delete "${resource}" -q done } cleanup_resource() { resource_group="$1" resource="$2" extra_list_arg="$3" extra_delete_arg="$4" for resource_id in $(gcloud "${resource_group}" "${resource}" list --project="${PROJECT_ID}" --format="csv[no-heading](name)" "${extra_list_arg}"); do gcloud "${resource_group}" "${resource}" delete "${resource_id}" --project="${PROJECT_ID}" -q "${extra_delete_arg}" done } cleanup_resource_per_region() { resource_group="$1" resource="$2" for resource_and_region in $(gcloud "${resource_group}" "${resource}" list --project="${PROJECT_ID}" --format="csv[no-heading](name,region)"); do read -r resource_id region < <(echo "$resource_and_region" | tr "," " ") gcloud "${resource_group}" "${resource}" delete "${resource_id}" --project="${PROJECT_ID}" -q --region="${region}" done } main