列出集群

列出项目中的所有 Dataproc 集群。

代码示例

Python

在试用此示例之前,请按照使用客户端库的 Dataproc 快速入门中的 Python 设置说明进行操作。如需了解详情,请参阅 Dataproc Python API 参考文档

如需向 Dataproc 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

def list_clusters(dataproc, project, region):
    """List the details of clusters in the region."""
    for cluster in dataproc.list_clusters(
        request={"project_id": project, "region": region}
    ):
        print(f"{cluster.cluster_name} - {cluster.status.state.name}")

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器