This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python code-samples/gcloud-python/start_stop_instances_labels_gcloud.py | |
Executing command "gcloud compute instances stop kube-master --zone us-central1-c --project sj-test-070418" | |
Stopping instance(s) kube-master...done. | |
Updated [https://www.googleapis.com/compute/v1/projects/sj-test-070418/zones/us-central1-c/instances/kube-master]. | |
Executing command "gcloud compute instances stop db-server-1 --zone us-central1-c --project sj-test-070218" | |
Stopping instance(s) db-server-1...done. | |
Updated [https://www.googleapis.com/compute/v1/projects/sj-test-070218/zones/us-central1-c/instances/db-server-1]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python code-samples/gcloud-python/delete_unattached_unused_disks_gcloud.py | |
Disk kube-master is attached to instance kube-master | |
Disk orphan-disk-2 is not attached to any instance and is not labeled for delete protection | |
Executing command "gcloud compute disks delete orphan-disk-2 --zone europe-west1-b --project sj-test-070218" | |
Disk orphan-disk-3 is not attached to any instance and is labeled for delete protection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bash get_disk_data.sh | |
project_id,disk_name,user | |
sj-test-070418,kube-master,kube-master | |
sj-test-070218,orphan-disk-2, | |
sj-test-070218,db-server-1,db-server-1 | |
sj-test-062218,orphan-disk-1, | |
sj-test-062218,app-server-1,app-server-1 | |
sj-test-062218,web-server-1,web-server-1 | |
sj-test-062218,web-server-2,web-server-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Header row for the CSV output | |
echo "project_id,disk_name,user" | |
# for every project in the list get the required details. Remove CSV header from the gcloud output. Add the project id to the beginning of each row | |
for project in $(gcloud projects list --format="value(projectId)") | |
do | |
# Because of the nested structure you get '] at the end of the output. Use sed to remove it | |
gcloud compute disks list --format="csv[no-heading](name,users.basename())" --project $project | sed s/\']//g | sed "s/^/$project,/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bash get_license_data.sh | |
project_id,instance_name,license | |
sj-test-070418,kube-master,centos-7 | |
sj-test-070218,db-server-1,centos-7 | |
sj-test-062218,app-server-1,centos-7 | |
sj-test-062218,web-server-1,centos-7 | |
sj-test-062218,web-server-2,centos-7 | |
sj-test-062218,test-redhat,rhel-7-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Header row for the CSV output | |
echo "project_id,instance_name,license" | |
# for every project in the list get the required details. Remove CSV header from the gcloud output. Add the project id to the beginning of each row | |
for project in $(gcloud projects list --format="value(projectId)") | |
do | |
# Because of the nested structure you get ']] at the end of the output. Use sed to remove it | |
gcloud compute instances list --format="csv[no-heading](name,disks.licenses.basename())" --project $project | sed s/\']]//g | sed "s/^/$project,/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcloud compute instances list - format="csv(name,labels.app-name,labels.biz-unit,labels.env-name,metadata.items.server-role,metadata.items.server-type, metadata.items.os-image)" | |
name,app-name,biz-unit,env-name,server-role,server-type,os-image | |
app-server-1,misc,ecom,prod,app,tomcat,centos | |
web-server-1,misc,ecom,prod,web,nginx,centos | |
web-server-2,misc,ecom,prod,web,nginx,centos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcloud compute instances list --format json | |
(~~ part of the response ~~) | |
"id": "3091147347390362603", | |
"kind": "compute#instance", | |
"labels": { | |
"app-name": "misc", | |
"biz-unit": "ecom", | |
"env-name": "prod", | |
}, | |
"metadata": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) | |
$ gcloud projects list --format="csv(projectId, name, labels)" | |
project_id,name,labels | |
sj-test-070418,sj-test-070418,app-name=micro-svc-app;biz-unit=it;env-name=qa;owner=john-smith | |
sj-test-070218,sj-test-070218,app-name=myapp;biz-unit=engineering;env-name=non-prod;owner=shashank | |
sj-test-062218,sj-test-062218,app-name=misc;biz-unit=ecom;env-name=prod;owner=jane-doe | |
secure-moment-207103,My First Project, | |
2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gcloud projects list --format json | |
[ | |
{ | |
"createTime": "2018-07-02T14:13:29.262Z", | |
"labels": { | |
"app-name": "micro-svc-app", | |
"biz-unit": "it", | |
"env-name": "qa", | |
"owner": "john-smith" | |
}, |
NewerOlder