1616
1717'use strict' ;
1818
19- async function main (
20- nodeName ,
21- queuedResourceName ,
22- zone ,
23- tpuType ,
24- tpuSoftwareVersion
25- ) {
19+ async function main ( tpuClient ) {
2620 // [START tpu_queued_resources_create]
27- // Import the TPU library
28- const { TpuClient} = require ( '@google-cloud/tpu' ) . v2alpha1 ;
21+ // Import the TPUClient
22+ // TODO(developer): Uncomment below line before running the sample.
23+ // const {TpuClient} = require('@google-cloud/tpu').v2alpha1;
2924 const { Node, NetworkConfig, QueuedResource} =
3025 require ( '@google-cloud/tpu' ) . protos . google . cloud . tpu . v2alpha1 ;
3126
3227 // Instantiate a tpuClient
33- const tpuClient = new TpuClient ( ) ;
28+ // TODO(developer): Uncomment below line before running the sample.
29+ // tpuClient = new TpuClient();
3430
3531 /**
36- * TODO(developer): Update/uncomment these variables before running the sample.
32+ * TODO(developer): Update these variables before running the sample.
3733 */
3834 // Project ID or project number of the Google Cloud project, where you want to create queued resource.
3935 const projectId = await tpuClient . getProjectId ( ) ;
@@ -45,24 +41,24 @@ async function main(
4541 const region = 'europe-west4' ;
4642
4743 // The name for your queued resource.
48- // queuedResourceName = 'queued-resource-1';
44+ const queuedResourceName = 'queued-resource-1' ;
4945
5046 // The name for your node.
51- // nodeName = 'node-name-1';
47+ const nodeName = 'node-name-1' ;
5248
5349 // The zone in which to create the node.
5450 // For more information about supported TPU types for specific zones,
5551 // see https://cloud.google.com/tpu/docs/regions-zones
56- // zone = 'europe-west4-a';
52+ const zone = 'europe-west4-a' ;
5753
5854 // The accelerator type that specifies the version and size of the node you want to create.
5955 // For more information about supported accelerator types for each TPU version,
6056 // see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
61- // tpuType = 'v2-8';
57+ const tpuType = 'v2-8' ;
6258
6359 // Software version that specifies the version of the node runtime to install. For more information,
6460 // see https://cloud.google.com/tpu/docs/runtimes
65- // tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
61+ const tpuSoftwareVersion = 'tpu-vm-tf-2.14.1' ;
6662
6763 async function callCreateQueuedResource ( ) {
6864 // Create a node
@@ -108,17 +104,21 @@ async function main(
108104 const [ operation ] = await tpuClient . createQueuedResource ( request ) ;
109105
110106 // Wait for the create operation to complete.
111- await operation . promise ( ) ;
107+ const [ response ] = await operation . promise ( ) ;
112108
113109 // You can wait until TPU Node is READY,
114- // and check its status using getTpuVm () from `tpu_vm_get` sample.
110+ // and check its status using callGetTpuVm () from `tpu_vm_get` sample.
115111 console . log ( `Queued resource ${ queuedResourceName } created.` ) ;
112+ return response ;
116113 }
117- await callCreateQueuedResource ( ) ;
114+ return await callCreateQueuedResource ( ) ;
118115 // [END tpu_queued_resources_create]
119116}
120117
121- main ( ...process . argv . slice ( 2 ) ) . catch ( err => {
122- console . error ( err ) ;
123- process . exitCode = 1 ;
124- } ) ;
118+ module . exports = main ;
119+
120+ // TODO(developer): Uncomment below lines before running the sample.
121+ // main(...process.argv.slice(2)).catch(err => {
122+ // console.error(err);
123+ // process.exitCode = 1;
124+ // });
0 commit comments