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

Function main

tpu/createStartupScriptVM.js:19–93  ·  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_startup_script]
21 // Import the TPUClient
22 // TODO(developer): Uncomment below line before running the sample.
23 // const {TpuClient} = require('@google-cloud/tpu').v2;
24
25 const {Node, NetworkConfig} =
26 require('@google-cloud/tpu').protos.google.cloud.tpu.v2;
27
28 // Instantiate a tpuClient
29 // TODO(developer): Uncomment below line before running the sample.
30 // tpuClient = new TpuClient();
31
32 // TODO(developer): Update these variables before running the sample.
33 // Project ID or project number of the Google Cloud project you want to create a node.
34 const projectId = await tpuClient.getProjectId();
35
36 // The name of the network you want the TPU node to connect to. The network should be assigned to your project.
37 const networkName = 'compute-tpu-network';
38
39 // The region of the network, that you want the TPU node to connect to.
40 const region = 'europe-west4';
41
42 // The name for your TPU.
43 const nodeName = 'node-name-1';
44
45 // The zone in which to create the TPU.
46 // For more information about supported TPU types for specific zones,
47 // see https://cloud.google.com/tpu/docs/regions-zones
48 const zone = 'europe-west4-a';
49
50 // The accelerator type that specifies the version and size of the Cloud TPU you want to create.
51 // For more information about supported accelerator types for each TPU version,
52 // see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
53 const tpuType = 'v5litepod-4';
54
55 // Software version that specifies the version of the TPU runtime to install. For more information,
56 // see https://cloud.google.com/tpu/docs/runtimes
57 const tpuSoftwareVersion = 'v2-tpuv5-litepod';
58
59 async function callCreateTpuVMStartupScript() {
60 // Create a node
61 const node = new Node({
62 name: nodeName,
63 zone,
64 acceleratorType: tpuType,
65 runtimeVersion: tpuSoftwareVersion,
66 // Define network
67 networkConfig: new NetworkConfig({
68 enableExternalIps: true,
69 network: `projects/${projectId}/global/networks/${networkName}`,
70 subnetwork: `projects/${projectId}/regions/${region}/subnetworks/${networkName}`,
71 }),
72 metadata: {
73 // The script updates numpy to the latest version and logs the output to a file.
74 'startup-script': `#!/bin/bash
75 echo "Hello World" > /var/log/hello.log
76 sudo pip3 install --upgrade numpy >> /var/log/hello.log 2>&1`,

Callers

nothing calls this directly

Calls 2

getProjectIdMethod · 0.80

Tested by

no test coverage detected