Skip to content

Commit 8b32197

Browse files
Joanna Grycziennae
authored andcommitted
feat: tpu_vm_list
1 parent 26236f4 commit 8b32197

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

compute/test/tpu.test.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'use strict';
1818

1919
const path = require('path');
20-
const {assert} = require('chai');
20+
const assert = require('node:assert/strict');
2121
const {describe, xit} = require('mocha');
2222
const cp = require('child_process');
2323
// const {TpuClient} = require('@google-cloud/tpu').v2;
@@ -45,14 +45,22 @@ describe('Compute tpu', async () => {
4545
}
4646
);
4747

48-
assert.include(response, `TPU VM: ${nodeName} created.`);
48+
assert(response.includes(`TPU VM: ${nodeName} created.`));
4949
});
5050

5151
xit('should return tpu node', () => {
5252
const response = execSync(`node ./tpu/vmGet.js ${nodeName} ${zone}`, {
5353
cwd,
5454
});
5555

56-
assert.include(response, `Node: ${nodeName} retrived.`);
56+
assert(response.includes(`Node: ${nodeName} retrived.`));
57+
});
58+
59+
xit('should return list of tpu nodes', () => {
60+
const response = execSync(`node ./tpu/vmList.js ${zone}`, {
61+
cwd,
62+
});
63+
64+
assert(Array.isArray(response));
5765
});
5866
});

compute/tpu/vmGet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ async function main(nodeName, zone) {
2727
/**
2828
* TODO(developer): Update/uncomment these variables before running the sample.
2929
*/
30-
// Project ID or project number of the Google Cloud project you want to create a node.
30+
// Project ID or project number of the Google Cloud project you want to retrive a node.
3131
const projectId = await tpuClient.getProjectId();
3232

3333
// The name of TPU to retrive.
3434
// nodeName = 'node-name-1';
3535

36-
// The zone in which the TPU is created.
36+
// The zone, where the TPU is created.
3737
// zone = 'us-central1-a';
3838

3939
async function callGetTpuVM() {

compute/tpu/vmList.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(zone) {
20+
// [START tpu_vm_list]
21+
// Import the TPU library
22+
const tpuLib = require('@google-cloud/tpu');
23+
24+
// Instantiate a tpuClient
25+
const tpuClient = new tpuLib.TpuClient();
26+
27+
/**
28+
* TODO(developer): Update/uncomment these variables before running the sample.
29+
*/
30+
// Project ID or project number of the Google Cloud project you want to retrive a list of TPU nodes.
31+
const projectId = await tpuClient.getProjectId();
32+
33+
// The zone from which the TPUs are retrived.
34+
// zone = 'us-central1-a';
35+
36+
async function callTpuVMList() {
37+
const request = {
38+
parent: `projects/${projectId}/locations/${zone}`,
39+
};
40+
41+
const [response] = await tpuClient.listNodes(request);
42+
43+
console.log('VM list retrived.');
44+
console.log(JSON.stringify(response));
45+
}
46+
47+
await callTpuVMList();
48+
// [END tpu_vm_list]
49+
}
50+
51+
main(...process.argv.slice(2)).catch(err => {
52+
console.error(err);
53+
process.exitCode = 1;
54+
});

0 commit comments

Comments
 (0)