MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

compute/listInstances.js:21–49  ·  view source on GitHub ↗

* Gets a list of instances created in given project in given zone. * * @param {string} projectId - ID or number of the project you want to use. * @param {string} zone - Name of the zone you want to check, for example: us-west3-b

(projectId, zone)

Source from the content-addressed store, hash-verified

19 * @param {string} zone - Name of the zone you want to check, for example: us-west3-b
20 */
21function main(projectId, zone) {
22 // [START compute_instances_list]
23 /**
24 * TODO(developer): Uncomment and replace these variables before running the sample.
25 */
26 // const projectId = 'YOUR_PROJECT_ID';
27 // const zone = 'europe-central2-b'
28
29 const compute = require('@google-cloud/compute');
30
31 // List all instances in the given zone in the specified project.
32 async function listInstances() {
33 const instancesClient = new compute.InstancesClient();
34
35 const [instanceList] = await instancesClient.list({
36 project: projectId,
37 zone,
38 });
39
40 console.log(`Instances found in zone ${zone}:`);
41
42 for (const instance of instanceList) {
43 console.log(` - ${instance.name} (${instance.machineType})`);
44 }
45 }
46
47 listInstances();
48 // [END compute_instances_list]
49}
50
51main(...process.argv.slice(2));

Callers 1

listInstances.jsFile · 0.70

Calls 1

listInstancesFunction · 0.85

Tested by

no test coverage detected