This command is for searches of not being used/available disks in your GCP. Like an aws command this.
aws --region ap-northeast-1 ec2 describe-volumes --filters Name=status,Values=available
- Use Cases
- Stocktaking.
- Cost controls.
- gcloud command (Google cloud SDK)
- Go
- version is .go-version for goenv
gcloud beta auth application-default login
make
./gce-available-disks -h
% ./gce-available-disks example-sre-dev
project: example-sre-dev
available disk name: test-disk-1
sizeGb: 10
creationTimestamp: 2019-09-02T01:55:29.494-07:00
project: example-sre-dev
available disk name: test-disk-2
sizeGb: 10
creationTimestamp: 2019-09-10T00:27:29.659-07:00
- Add activity log
echo example-sre-dev | ./gce-available-disks -t 180
% gcloud projects list --sort-by=projectId --format="value(projectId)" | xargs -I% -P $(($(nproc) - 1)) ./gce-available-disks %
If the above command fails, you can try the following command:
e.g.
% for pj in $(gcloud projects list --sort-by=projectId --format="value(projectId)");do echo "===== $pj start. ====="; ./gce-available-disks -l -c -s $pj | grep -v 'project,available disk name,sizeGb,creationTimestamp,createdBy' 2>/dev/null ;done | tee ~/work/tmp/gcp-available.csv
Or not using -l
option. See also the belows.
- Activity logs sometimes can't be obtained it.
- Hint
- Silent option is available.
-s
- If not use
-l
option, it expects for high-speed responce.
- Silent option is available.
- Hint
PROJECT=${YOUR_GCP_PROJECT} go test [-race|-run] . [-tc|-tl|-ts]
For example,
PROJECT=example-sre-dev go test -race -run . -tc -tl -ts
# result
project,available disk name,sizeGb,creationTimestamp,createdBy
example-sre-dev,test-disk-1,10,2019-09-02T01:55:29.494-07:00,k-oguma@example.com
example-sre-dev,test-disk-1,10,2019-09-02T01:55:29.494-07:00,k-oguma@example.com
PASS
ok github.com/k-oguma/gce-available-disks 16.136s