列出叢集

列出專案中的所有 Dataproc 叢集。

程式碼範例

Python

在試用這個範例之前,請先按照Python使用用戶端程式庫的 Dataproc 快速入門導覽課程中的設定說明操作。 詳情請參閱 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 範例瀏覽器