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

Function main

tpu/queuedResources/createQueuedResource.js:19–116  ·  view source on GitHub ↗
(tpuClient)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

callCreateQueuedResourceFunction · 0.85
getProjectIdMethod · 0.80

Tested by

no test coverage detected