Python GCP

From Federal Burro of Information
Revision as of 20:16, 23 November 2022 by David (talk | contribs) (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='-')...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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']))