GCP AI platform API

411 views Asked by At

I am trying to programatically create "AI Platform Notebooks" in GCP. The gcloud sdk does have some support for managing these notebooks, but not creating them. And there is no client library for support for Node.js (the language I'm using). Creating notebooks is however supported by the GCP REST API as documented here. However, I am struggling to work out how to specify what notebook I want in the request's JSON. From the GCP web UI, the settings I want are:

  • instance name: "testing-instance"
  • region: "europe-west2"
  • zone: "europe-west2a"
  • environment: "TensorFlow Enterprise 2.1 (with IntelĀ® MKL-DNN/MKL)"
  • machine type: "e2-highmem-2 (Efficient Instance, 2 vCPUs, 16 GB RAM)"
  • access to jupyter lab: "Single user only"
  • user email: "[email protected]"
  • service account: "[email protected]"

But I am struggling to translate this into a JSON request for the REST API. Below is what I have so far. I am not sure any of it is correct, and I'm definitely missing the environment (tensorflow 2.1) and single user only access. I have no idea how to go about achieving this other than randomly trying different requests until it works. (I have left some of the JSON as just specifying the types as per the docs for now, for reference).

POST https://notebooks.googleapis.com/v1beta1/projects/my-project/locations/europe-west2/instances
{
  "name" : "testing-instance",
  "instanceOwners": [
    string
  ],
  "serviceAccount": "[email protected]",
  "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.
}
2

There are 2 answers

0
guillaume blaquiere On BEST ANSWER

Here the required 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": "[email protected]"
      }
    ]
  },
  "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": "[email protected]",
      "scopes": [
        "https://www.googleapis.com/auth/cloud-platform",
        "https://www.googleapis.com/auth/userinfo.email"
      ]
    }
  ],
  "tags": {
    "items": [
      "deeplearning-vm"
    ]
  }
}

Impossible to guess by yourselves. How I do? Do it with the console and before submitting, open the Chorme debugger and capture the network request. The post request contain this JSON!

Enjoy

0
Manan Soni On

To create a notebook instance using api, this is the minimum json that worked for me, you can always tweak and/or add on to it!

{
    "acceleratorConfig": {},
    "installGpuDriver": false,
    "machineType": "n1-standard-4",
    "name": "apitestinstance3",
    "noProxyAccess": false,
    "noPublicIp": false,
    "vmImage": {
        "imageFamily": "tf-2-8-cu113-notebooks-debian-10",
        "project": "deeplearning-platform-release"
    }
}