Python GCP: Difference between revisions

From Federal Burro of Information
Jump to navigationJump to search
(Created page with " using discover to get the container service client. Then listing clusters. <pre> from googleapiclient import discovery from oauth2client.client import GoogleCredentials credentials = GoogleCredentials.get_application_default() service = discovery.build('container', 'v1', credentials=credentials) gcp_projects = ['project-1', 'project-2', 'project-3'] for project in gcp_projects: request = service.projects().zones().clusters().list(projectId=project, zone='-')...")
 
No edit summary
 
Line 24: Line 24:




[[category:scripts]]
[[Category:Script]]

Latest revision as of 20:16, 23 November 2022

using discover to get the container service client.

Then listing clusters.

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

service = discovery.build('container', 'v1', credentials=credentials)

gcp_projects = ['project-1', 'project-2', 'project-3']

for project in gcp_projects:
    request = service.projects().zones().clusters().list(projectId=project, zone='-')
    response = request.execute()

    if 'clusters' in response:
        for cluster in response['clusters']:
            print("%s,%s,%d" % (project, cluster['name'], cluster['currentNodeCount']))