Skip to content

Commit 26236f4

Browse files
Joanna Grycziennae
authored andcommitted
feat: tpu_vm_get
1 parent 2d79b73 commit 26236f4

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

compute/test/tpu.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ describe('Compute tpu', async () => {
4747

4848
assert.include(response, `TPU VM: ${nodeName} created.`);
4949
});
50+
51+
xit('should return tpu node', () => {
52+
const response = execSync(`node ./tpu/vmGet.js ${nodeName} ${zone}`, {
53+
cwd,
54+
});
55+
56+
assert.include(response, `Node: ${nodeName} retrived.`);
57+
});
5058
});

compute/tpu/vmGet.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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(nodeName, zone) {
20+
// [START tpu_vm_get]
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 create a node.
31+
const projectId = await tpuClient.getProjectId();
32+
33+
// The name of TPU to retrive.
34+
// nodeName = 'node-name-1';
35+
36+
// The zone in which the TPU is created.
37+
// zone = 'us-central1-a';
38+
39+
async function callGetTpuVM() {
40+
const request = {
41+
name: `projects/${projectId}/locations/${zone}/nodes/${nodeName}`,
42+
};
43+
44+
const [response] = await tpuClient.getNode(request);
45+
46+
console.log(`Node: ${nodeName} retrived.`);
47+
console.log(JSON.stringify(response));
48+
}
49+
50+
await callGetTpuVM();
51+
// [END tpu_vm_get]
52+
}
53+
54+
main(...process.argv.slice(2)).catch(err => {
55+
console.error(err);
56+
process.exitCode = 1;
57+
});

0 commit comments

Comments
 (0)