0

我正在尝试在 GCP 中以编程方式创建“AI 平台笔记本”。gcloud sdk 确实支持管理这些笔记本,但不支持创建它们。并且没有支持 Node.js(我正在使用的语言)的客户端库。但是,此处记录的 GCP REST API 支持创建笔记本。但是,我正在努力弄清楚如何在请求的 JSON 中指定我想要的笔记本。从 GCP 网络用户界面,我想要的设置是:

  • 实例名称:“测试实例”
  • 地区:“欧洲西部2”
  • 区域:“欧洲西部2a”
  • 环境:“TensorFlow Enterprise 2.1(采用英特尔® MKL-DNN/MKL)”
  • 机器类型:“e2-highmem-2(高效实例,2 个 vCPU,16 GB RAM)”
  • 访问 jupyter 实验室:“仅限单用户”
  • 用户电子邮件:“firstname.surname@email.com”
  • 服务帐户:“team@project.iam.gserviceaccount.com”

但我正在努力将其转换为 REST API 的 JSON 请求。以下是我到目前为止所拥有的。我不确定其中任何一个是否正确,而且我肯定缺少环境(tensorflow 2.1)和仅限单用户访问。除了随机尝试不同的请求直到它起作用之外,我不知道如何实现这一点。(我暂时留下了一些 JSON,只是根据文档指定类型,以供参考)。

POST https://notebooks.googleapis.com/v1beta1/projects/my-project/locations/europe-west2/instances
{
  "name" : "testing-instance",
  "instanceOwners": [
    string
  ],
  "serviceAccount": "team@project.iam.gserviceaccount.com",
  "machineType": "e2-highmem-2 (Efficient Instance, 2 vCPUs, 16 GB RAM)",
  "acceleratorConfig": {
    object (AcceleratorConfig)
  },
  "state": enum (State),
  "installGpuDriver": boolean,
  "customGpuDriverPath": string,
  "bootDiskType": enum (DiskType),
  "bootDiskSizeGb": string,
  "dataDiskType": enum (DiskType),
  "dataDiskSizeGb": string,
  "noRemoveDataDisk": boolean,
  "diskEncryption": enum (DiskEncryption),
  "kmsKey": string,
  "noPublicIp": boolean,
  "noProxyAccess": boolean,
  "network": string,
  "subnet": string,
  "labels": {
    string: string,
    ...
  },
  "metadata": {
    string: string,
    ...
  },
  "createTime": string,
  "updateTime": string,

  // Union field environment can be only one of the following:
  "vmImage": {
    object (VmImage)
  },
  "containerImage": {
    object (ContainerImage)
  }
  // End of list of possible types for union field environment.
}
4

1 回答 1

3

这里需要的JSON

{
  "name": "testing-instance",
  "machineType": "zones/europe-west2-a/machineTypes/e2-highmem-2",
  "guestAccelerators": [],
  "metadata": {
    "items": [
      {
        "key": "proxy-mode",
        "value": "mail"
      },
      {
        "key": "framework",
        "value": "TensorFlow:2.1"
      },
      {
        "key": "proxy-user-mail",
        "value": "firstname.surname@email.com"
      }
    ]
  },
  "disks": [
    {
      "boot": true,
      "autoDelete": true,
      "initializeParams": {
        "diskType": "zones/europe-west2-a/diskTypes/pd-standard",
        "diskSizeGb": "100",
        "sourceImage": "projects/deeplearning-platform-release/global/images/family/tf2-2-1-cu101-notebooks-debian-9"
      }
    }
  ],
  "scheduling": {
    "onHostMaintenance": "MIGRATE"
  },
  "networkInterfaces": [
    {
      "subnetwork": "https://www.googleapis.com/compute/v1/projects/gbl-imt-homerider-basguillaueb/regions/europe-west2/subnetworks/datalab-network",
      "accessConfigs": [
        {
          "name": "external-nat",
          "type": "ONE_TO_ONE_NAT"
        }
      ]
    }
  ],
  "serviceAccounts": [
    {
      "email": "team@project.iam.gserviceaccount.com",
      "scopes": [
        "https://www.googleapis.com/auth/cloud-platform",
        "https://www.googleapis.com/auth/userinfo.email"
      ]
    }
  ],
  "tags": {
    "items": [
      "deeplearning-vm"
    ]
  }
}

自己猜不出来的。我怎样做?使用控制台执行此操作,在提交之前,打开 Chorme 调试器并捕获网络请求。发布请求包含此 JSON!

享受

于 2020-09-09T20:04:56.450 回答