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

Function main

tpu/queuedResources/deleteQueuedResource.js:19–76  ·  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_delete]
21 // Import the TPUClient
22 // TODO(developer): Uncomment below line before running the sample.
23 // const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
24
25 // Instantiate a tpuClient
26 // TODO(developer): Uncomment below line before running the sample.
27 // tpuClient = new TpuClient();
28
29 /**
30 * TODO(developer): Update these variables before running the sample.
31 */
32 // Project ID or project number of the Google Cloud project, where you want to delete node.
33 const projectId = await tpuClient.getProjectId();
34
35 // The name of queued resource.
36 const queuedResourceName = 'queued-resource-1';
37
38 // The zone of your queued resource.
39 const zone = 'us-central1-a';
40
41 async function callDeleteTpuVM(nodeName) {
42 const request = {
43 name: `projects/${projectId}/locations/${zone}/nodes/${nodeName}`,
44 };
45
46 const [operation] = await tpuClient.deleteNode(request);
47
48 // Wait for the delete operation to complete.
49 await operation.promise();
50
51 console.log(`Node: ${nodeName} deleted.`);
52 }
53
54 async function callDeleteQueuedResource() {
55 const request = {
56 name: `projects/${projectId}/locations/${zone}/queuedResources/${queuedResourceName}`,
57 };
58
59 // Retrive node name
60 const [queuedResource] = await tpuClient.getQueuedResource(request);
61 const nodeName = queuedResource.tpu.nodeSpec[0].nodeId;
62
63 // Before deleting the queued resource it is required to delete the TPU VM.
64 await callDeleteTpuVM(nodeName);
65
66 const [operation] = await tpuClient.deleteQueuedResource(request);
67
68 // Wait for the delete operation to complete.
69 const [response] = await operation.promise();
70
71 console.log(`Queued resource ${queuedResourceName} deleted.`);
72 return response;
73 }
74 return await callDeleteQueuedResource();
75 // [END tpu_queued_resources_delete]
76}

Callers

nothing calls this directly

Calls 2

callDeleteQueuedResourceFunction · 0.85
getProjectIdMethod · 0.80

Tested by

no test coverage detected