From 9e05d7c0d0d7e7194eeb2c56e9689e13ba7da417 Mon Sep 17 00:00:00 2001 From: Timothy Middelkoop Date: Thu, 16 Dec 2021 20:17:43 +0000 Subject: [PATCH] Cleanup the VM in cloudshell --- content/GCP/08_cleaning_up_resources.ipynb | 94 +++++++++++++++++++--- 1 file changed, 82 insertions(+), 12 deletions(-) diff --git a/content/GCP/08_cleaning_up_resources.ipynb b/content/GCP/08_cleaning_up_resources.ipynb index c9cf459..de00ca1 100644 --- a/content/GCP/08_cleaning_up_resources.ipynb +++ b/content/GCP/08_cleaning_up_resources.ipynb @@ -95,7 +95,8 @@ "ACCOUNT=$(gcloud config list --format='value(core.account)')\n", "PROJECT=$(gcloud config list --format='value(core.project)')\n", "BUCKET=\"essentials-${USER}-*\"\n", - "REGION=\"us-west2\"" + "REGION=\"us-west2\"\n", + "ZONE=\"us-west2-c\"" ] }, { @@ -108,13 +109,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "Account: 281138444384-compute@developer.gserviceaccount.com, Project: essentials-project-335018, Region: us-west2\n", + "Account: learner@class.internet2.edu, Project: essentials-project-335018, Region: us-west2 Zone: us-west2-c\n", "Bucket: essentials-learner-*\n" ] } ], "source": [ - "echo \"Account: $ACCOUNT, Project: $PROJECT, Region: $REGION\"\n", + "echo \"Account: $ACCOUNT, Project: $PROJECT, Region: $REGION Zone: $ZONE\"\n", "echo \"Bucket: $BUCKET\"" ] }, @@ -164,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "24616c20-ae7e-4d0f-9f9c-6c8752891fa7", "metadata": {}, "outputs": [ @@ -172,10 +173,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Removing gs://essentials-learner-2021-12-16/output/result-LO08_L1TP_025033_20201108_20201120_01_T1.png#1639681244335643...\n", - "Removing gs://essentials-learner-2021-12-16/output/result-LO08_L1TP_025033_20201108_20201120_01_T1.png.aux.xml#1639681242914074...\n", - "/ [2/2 objects] 100% Done \n", - "Operation completed over 2 objects. \n" + "Removing gs://essentials-learner-2021-12-16/1#1639684995415818...\n", + "/ [1/1 objects] 100% Done \n", + "Operation completed over 1 objects. \n" ] } ], @@ -193,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "a1310b76-6212-48fa-b023-0a15e06d4332", "metadata": {}, "outputs": [ @@ -221,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "b088681d-633d-4991-ba7d-2ecfb41c36dd", "metadata": {}, "outputs": [ @@ -240,7 +240,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "74d0e8e7-f097-41c5-88fe-929edcb0c1c1", "metadata": {}, "outputs": [ @@ -259,10 +259,80 @@ "gcloud asset search-all-resources --format='value(name)' |grep -vE '/(services|networks|routes|subnetworks|firewalls|serviceAccounts)/' | sort" ] }, + { + "cell_type": "markdown", + "id": "f275a53a-a3d1-4a0f-a44c-21e2ba7186ba", + "metadata": {}, + "source": [ + "Looks like we forgot to delete the VM." + ] + }, + { + "cell_type": "markdown", + "id": "74fd626a-6102-4815-a8c2-27aade6ebc3b", + "metadata": {}, + "source": [ + "## CLeanup VMs\n", + "We can also create and delete VMs using the `gcloud` command. Note, the `--quiet` disables conformation. **WARNING: This command will immediately delete the VM called essentials**" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "2ab8b339-b923-4623-942c-ddd424e3bcf7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Deleted [https://www.googleapis.com/compute/v1/projects/essentials-project-335018/zones/us-west2-c/instances/essentials].\n" + ] + } + ], + "source": [ + "gcloud compute instances delete essentials --zone=$ZONE --quiet" + ] + }, + { + "cell_type": "markdown", + "id": "4a215b73-ac5e-4fa6-88b7-8af26ee4090f", + "metadata": {}, + "source": [ + "Check again" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "e53cb55c-3195-4fc3-9aab-cabad44d865e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "//cloudresourcemanager.googleapis.com/projects/essentials-project-335018\n", + "//compute.googleapis.com/projects/essentials-project-335018\n" + ] + } + ], + "source": [ + "gcloud asset search-all-resources --format='value(name)' |grep -vE '/(services|networks|routes|subnetworks|firewalls|serviceAccounts)/' | sort" + ] + }, + { + "cell_type": "markdown", + "id": "631a08af-88bb-463c-b388-8993021ee216", + "metadata": {}, + "source": [ + "Success! The only resource left is the project (both are project resources)" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "6173c04b-a4e7-4c3d-99f9-cc6e14c49489", + "id": "cac28557-fec2-43f4-aaa5-4f82b2257c55", "metadata": {}, "outputs": [], "source": []