Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit

Permalink
Cleanup the VM in cloudshell
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiddelkoop committed Dec 16, 2021
1 parent 8b7b10a commit 9e05d7c
Showing 1 changed file with 82 additions and 12 deletions.
94 changes: 82 additions & 12 deletions content/GCP/08_cleaning_up_resources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
]
},
{
Expand All @@ -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\""
]
},
Expand Down Expand Up @@ -164,18 +165,17 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"id": "24616c20-ae7e-4d0f-9f9c-6c8752891fa7",
"metadata": {},
"outputs": [
{
"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"
]
}
],
Expand All @@ -193,7 +193,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"id": "a1310b76-6212-48fa-b023-0a15e06d4332",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -221,7 +221,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"id": "b088681d-633d-4991-ba7d-2ecfb41c36dd",
"metadata": {},
"outputs": [
Expand All @@ -240,7 +240,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"id": "74d0e8e7-f097-41c5-88fe-929edcb0c1c1",
"metadata": {},
"outputs": [
Expand All @@ -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": []
Expand Down

0 comments on commit 9e05d7c

Please sign in to comment.