MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

tpu/createVM.js:19–86  ·  view source on GitHub ↗
(tpuClient)

Source from the content-addressed store, hash-verified

17'use strict';
18
19async function main(tpuClient) {
20 // [START tpu_vm_create]
21 // Import the TPUClient
22 // TODO(developer): Uncomment below line before running the sample.
23 // const {TpuClient} = require('@google-cloud/tpu').v2;
24 const {Node, NetworkConfig} =
25 require('@google-cloud/tpu').protos.google.cloud.tpu.v2;
26
27 // Instantiate a tpuClient
28 // TODO(developer): Uncomment below line before running the sample.
29 // tpuClient = new TpuClient();
30
31 // TODO(developer): Update below line before running the sample.
32 // Project ID or project number of the Google Cloud project you want to create a node.
33 const projectId = await tpuClient.getProjectId();
34
35 // The name of the network you want the TPU node to connect to. The network should be assigned to your project.
36 const networkName = 'compute-tpu-network';
37
38 // The region of the network, that you want the TPU node to connect to.
39 const region = 'europe-west4';
40
41 // The name for your TPU.
42 const nodeName = 'node-name-1';
43
44 // The zone in which to create the TPU.
45 // For more information about supported TPU types for specific zones,
46 // see https://cloud.google.com/tpu/docs/regions-zones
47 const zone = 'europe-west4-a';
48
49 // The accelerator type that specifies the version and size of the Cloud TPU you want to create.
50 // For more information about supported accelerator types for each TPU version,
51 // see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
52 const tpuType = 'v5litepod-4';
53
54 // Software version that specifies the version of the TPU runtime to install. For more information,
55 // see https://cloud.google.com/tpu/docs/runtimes
56 const tpuSoftwareVersion = 'v2-tpuv5-litepod';
57
58 async function callCreateTpuVM() {
59 // Create a node
60 const node = new Node({
61 name: nodeName,
62 zone,
63 acceleratorType: tpuType,
64 runtimeVersion: tpuSoftwareVersion,
65 // Define network
66 networkConfig: new NetworkConfig({
67 enableExternalIps: true,
68 network: `projects/${projectId}/global/networks/${networkName}`,
69 subnetwork: `projects/${projectId}/regions/${region}/subnetworks/${networkName}`,
70 }),
71 });
72
73 const parent = `projects/${projectId}/locations/${zone}`;
74 const request = {parent, node, nodeId: nodeName};
75
76 const [operation] = await tpuClient.createNode(request);

Callers

nothing calls this directly

Calls 2

callCreateTpuVMFunction · 0.85
getProjectIdMethod · 0.80

Tested by

no test coverage detected