Last active
April 17, 2023 10:15
-
-
Save rajathithan/3cd858198cafef22f684a9cb42ad4dcd to your computer and use it in GitHub Desktop.
compute-engine-details
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 | |
# Script to retrieve compute engine details. | |
# Author - Rajathithan Rajasekar - 03/03/2020 | |
echo "PROJECT NAME, INSTANCE NAME , ZONE , MACHINE-TYPE , OPERATING SYSTEM , CPU , MEMORY , DISK SIZE" > compute-engine-details.csv | |
prjs=( $(gcloud projects list | tail -n +2 | awk {'print $1'}) ) | |
for i in "${prjs[@]}" | |
do | |
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" >> list.txt | |
echo "Setting Project: $i" >> list.txt | |
echo $(gcloud config set project $i) | |
if [[ $(gcloud services list --enabled --filter="NAME:compute.googleapis.com" --format="value(NAME)" | grep compute) ]]; then | |
echo "Compute API is enabled is in project - $i" | |
echo $(gcloud compute instances list | awk '{print $1,$2}' | tail -n +2| while read line; do echo "$i $line"; done |xargs -n3 sh -c 'python3 retrieve-compute-engine-details.py $1 $2 $3 >> compute-engine-details.csv' sh) | |
else | |
echo "Compute API is not enabled in project - $i" | |
fi | |
done | |
While trying to execute the script, I'm getting the below:
File "/home/xpto/compute_details/retrieve-compute-engine-details.py", line 19, in <module>
request = service.instances().get(project=project, zone=zone, instance=instance)
File "/usr/local/lib/python3.9/dist-packages/googleapiclient/discovery.py", line 1073, in method
raise TypeError(
TypeError: Parameter "zone" value "NAME:" does not match the pattern "[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?"
Traceback (most recent call last):
File "/home/xpto/compute_details/retrieve-compute-engine-details.py", line 19, in <module>
request = service.instances().get(project=project, zone=zone, instance=instance)
File "/usr/local/lib/python3.9/dist-packages/googleapiclient/discovery.py", line 1073, in method
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rajathithan Thank you. Can you let me know how to get the hostname and Private IP of the machines through this script (both Linux & Windows)?
Thanks, Vishnu