GCP and python

122 views
Skip to first unread message

Mithun Gangadharan

unread,
Jun 7, 2021, 2:29:56 PM6/7/21
to Google Cloud Developers
Hi,

has anyone created a python script to find the VMs across google cloud projects using deprecated images?

Basically, 
list all the projects with compute engine API enabled
list all the VMs in the project
find the source image of the disk and check if it is depracated
and return the list of VMs per project

Any guidance on how to achieve this would be helpful
Being a  beginner in python, I struggle on how to approach it

thanks

thanks

Alexis (Google Cloud Support)

unread,
Jun 8, 2021, 3:30:00 PM6/8/21
to Google Cloud Developers

Hi,

The steps below are using the gcloud CLI which can be a batch script once installed on your OS, it's simpler in my opinion. However, for other languages, you will need to call the REST API via HTTP which can be more complicated. If you really want to use the API via Python, this[0] is an example of the REST API's first step if you decide to call it via HTTP. Just search for the other steps in the left menu relative to the CLI instructions below.

Get deprecated images:
- list the deprecated images[1] (using --show-deprecated. Very long list!)

Get projects with Compute API enabled:
- list all the projects[2] 
- list the services[3] (APIs) enabled inside a project

Get disks in a project:
- list disks[4] inside the filtered projects

Match project disks with deprecated images:
- describe[5] those disks, look for "sourceImage" property and match it with deprecated images


Documents:

Reply all
Reply to author
Forward
0 new messages