Python GCP
From Federal Burro of Information
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']))