0

如何在 python 中复制以下 gcloud 命令?

gcloud beta dataproc clusters create spark-nlp-cluster \
     --region global \
     --metadata 'PIP_PACKAGES=google-cloud-storage spark-nlp==2.5.3' \
     --worker-machine-type n1-standard-1 \
     --num-workers 2 \
     --image-version 1.4-debian10 \
     --initialization-actions gs://dataproc-initialization-actions/python/pip-install.sh \
     --optional-components=JUPYTER,ANACONDA \
     --enable-component-gateway 

这是我到目前为止在 python 中的内容:


    cluster_data = {
        "project_id": project,
        "cluster_name": cluster_name,
        "config": {
            "gce_cluster_config": {"zone_uri": zone_uri},
            "master_config": {"num_instances": 1, "machine_type_uri": "n1-standard-1"},
            "worker_config": {"num_instances": 2, "machine_type_uri": "n1-standard-1"},
            "software_config":{"image_version":"1.4-debian10","optional_components":{"JUPYTER","ANACONDA"}}
            
        },
    }

    cluster = dataproc.create_cluster(
        request={"project_id": project, "region": region, "cluster": cluster_data}
    )

不确定如何将这些 gcloud 命令转换为 python:

     --metadata 'PIP_PACKAGES=google-cloud-storage spark-nlp==2.5.3' \  
     --initialization-actions gs://dataproc-initialization-actions/python/pip-install.sh \
     --enable-component-gateway 
4

1 回答 1

0

你可以这样尝试:

cluster_data = {
    "project_id": project,
    "cluster_name": cluster_name,
    "config": {
        "gce_cluster_config": {"zone_uri": zone_uri},
        "master_config": {"num_instances": 1, "machine_type_uri": "n1-standard-1"},
        "worker_config": {"num_instances": 2, "machine_type_uri": "n1-standard-1"},
        "software_config":{"image_version":"1.4-debian10","optional_components":{"JUPYTER","ANACONDA"}},
        "initialization_actions":{"executable_file" : "gs://dataproc-initialization-actions/python/pip-install.sh"},
        "gce_cluster_config": {"metadata": "PIP_PACKAGES=google-cloud-storage,spark-nlp==2.5.3"},
        "endpoint_config": {"enable_http_port_access":True},
        
    },
}

您可以访问更多信息:GCP 集群配置

于 2021-08-05T14:55:46.233 回答