1616
1717'use strict' ;
1818
19- async function main ( nodeName , zone , tpuType , tpuSoftwareVersion ) {
19+ async function main ( tpuClient ) {
2020 // [START tpu_vm_create]
21- // Import the TPU library
22- const { TpuClient} = require ( '@google-cloud/tpu' ) . v2 ;
21+ // Import the TPUClient
22+ // TODO(developer): Uncomment below line before running the sample.
23+ // const {TpuClient} = require('@google-cloud/tpu').v2;
2324 const { Node, NetworkConfig} =
2425 require ( '@google-cloud/tpu' ) . protos . google . cloud . tpu . v2 ;
2526
2627 // Instantiate a tpuClient
27- const tpuClient = new TpuClient ( ) ;
28+ // TODO(developer): Uncomment below line before running the sample.
29+ // tpuClient = new TpuClient();
2830
29- /**
30- * TODO(developer): Update/uncomment these variables before running the sample.
31- */
31+ // TODO(developer): Update below line before running the sample.
3232 // Project ID or project number of the Google Cloud project you want to create a node.
3333 const projectId = await tpuClient . getProjectId ( ) ;
3434
@@ -39,21 +39,21 @@ async function main(nodeName, zone, tpuType, tpuSoftwareVersion) {
3939 const region = 'europe-west4' ;
4040
4141 // The name for your TPU.
42- // nodeName = 'node-name-1';
42+ const nodeName = 'node-name-1' ;
4343
4444 // The zone in which to create the TPU.
4545 // For more information about supported TPU types for specific zones,
4646 // see https://cloud.google.com/tpu/docs/regions-zones
47- // zone = 'europe-west4-a';
47+ const zone = 'europe-west4-a' ;
4848
4949 // The accelerator type that specifies the version and size of the Cloud TPU you want to create.
5050 // For more information about supported accelerator types for each TPU version,
5151 // see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
52- // tpuType = 'v2-8';
52+ const tpuType = 'v2-8' ;
5353
5454 // Software version that specifies the version of the TPU runtime to install. For more information,
5555 // see https://cloud.google.com/tpu/docs/runtimes
56- // tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
56+ const tpuSoftwareVersion = 'tpu-vm-tf-2.14.1' ;
5757
5858 async function callCreateTpuVM ( ) {
5959 // Create a node
@@ -78,14 +78,17 @@ async function main(nodeName, zone, tpuType, tpuSoftwareVersion) {
7878 // Wait for the create operation to complete.
7979 const [ response ] = await operation . promise ( ) ;
8080
81- console . log ( JSON . stringify ( response ) ) ;
8281 console . log ( `TPU VM: ${ nodeName } created.` ) ;
82+ return response ;
8383 }
84- await callCreateTpuVM ( ) ;
84+ return await callCreateTpuVM ( ) ;
8585 // [END tpu_vm_create]
8686}
8787
88- main ( ...process . argv . slice ( 2 ) ) . catch ( err => {
89- console . error ( err ) ;
90- process . exitCode = 1 ;
91- } ) ;
88+ module . exports = main ;
89+
90+ // TODO(developer): Uncomment below lines before running the sample.
91+ // main(...process.argv.slice(2)).catch(err => {
92+ // console.error(err);
93+ // process.exitCode = 1;
94+ // });
0 commit comments