Here is how I do it in my code:
""" If you have a credentials issue, run: gcloud beta auth application-default login """ import time import googleapiclient.discovery service = googleapiclient.discovery.build('container', 'v1') clusters_resource = service.projects().zones().clusters() operations_resource = service.projects().zones().operations() def create_cluster(project_id, zone, config, async=False): req = clusters_resource.create(projectId=project_id, zone=zone, body=config) operation = req.execute() if async: return while operation['status'] == 'RUNNING': time.sleep(1) req = operations_resource.get(projectId=project_id, zone=zone, operationId=operation['name']) operation = req.execute() return operation['status'] == 'DONE'
source share