16
16
17
17
'use strict' ;
18
18
19
- async function main ( nodeName , zone , tpuType , tpuSoftwareVersion ) {
19
+ async function main ( tpuClient ) {
20
20
// [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;
23
24
const { Node, NetworkConfig} =
24
25
require ( '@google-cloud/tpu' ) . protos . google . cloud . tpu . v2 ;
25
26
26
27
// Instantiate a tpuClient
27
- const tpuClient = new TpuClient ( ) ;
28
+ // TODO(developer): Uncomment below line before running the sample.
29
+ // tpuClient = new TpuClient();
28
30
29
- /**
30
- * TODO(developer): Update/uncomment these variables before running the sample.
31
- */
31
+ // TODO(developer): Update below line before running the sample.
32
32
// Project ID or project number of the Google Cloud project you want to create a node.
33
33
const projectId = await tpuClient . getProjectId ( ) ;
34
34
@@ -39,21 +39,21 @@ async function main(nodeName, zone, tpuType, tpuSoftwareVersion) {
39
39
const region = 'europe-west4' ;
40
40
41
41
// The name for your TPU.
42
- // nodeName = 'node-name-1';
42
+ const nodeName = 'node-name-1' ;
43
43
44
44
// The zone in which to create the TPU.
45
45
// For more information about supported TPU types for specific zones,
46
46
// see https://cloud.google.com/tpu/docs/regions-zones
47
- // zone = 'europe-west4-a';
47
+ const zone = 'europe-west4-a' ;
48
48
49
49
// The accelerator type that specifies the version and size of the Cloud TPU you want to create.
50
50
// For more information about supported accelerator types for each TPU version,
51
51
// see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
52
- // tpuType = 'v2-8';
52
+ const tpuType = 'v2-8' ;
53
53
54
54
// Software version that specifies the version of the TPU runtime to install. For more information,
55
55
// 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' ;
57
57
58
58
async function callCreateTpuVM ( ) {
59
59
// Create a node
@@ -78,14 +78,17 @@ async function main(nodeName, zone, tpuType, tpuSoftwareVersion) {
78
78
// Wait for the create operation to complete.
79
79
const [ response ] = await operation . promise ( ) ;
80
80
81
- console . log ( JSON . stringify ( response ) ) ;
82
81
console . log ( `TPU VM: ${ nodeName } created.` ) ;
82
+ return response ;
83
83
}
84
- await callCreateTpuVM ( ) ;
84
+ return await callCreateTpuVM ( ) ;
85
85
// [END tpu_vm_create]
86
86
}
87
87
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