Reputation: 1
I'm writing code to list Virtual Machines created in Google Cloud Compute Engine. I'm using NodeJS Client Library "@google-cloud/compute" Link to Client Library and from that I am using compute.getVMs method to list Instances and I've to pass pageToken as an option to getVMs method. I'm unable to figure out how to pass it as an option in the code and Implement it. Can anyone help, Please?
Link to compute.getVMs method and documentation
Code to List VM Instances
'use strict';
async function main() {
const Compute = require('@google-cloud/compute');
const compute = new Compute();
async function listVMs() {
const vms = await compute.getVMs({
maxResults: 10,
});
console.log(`VMs Present are `, vms);
}
listVMs();
}
Upvotes: 0
Views: 109
Reputation: 15266
If we look at the example code found at the getVMs() call we see that we have the ability to read the VMs in batches rather get all the VMs in one shot. What this means is that we can get them a "page at a time". Looking at the example, it appears that the callback function invoked when results (a page) are ready are:
When you get this response and you want the next page of results, you invoke getVMs()
again but this time pass the previously returned nextQuery
as the input parameter to getVMs()
. This time, you will get the next page of results returned to you.
Upvotes: 1