列出虚拟机 - Google Compute Engine Node.js客户端库

问题描述 投票:-1回答:1

当我从Compute对象的构造函数中排除keyFilename时,我得到了所有VM的列表。

const Compute = require('@google-cloud/compute');
const compute = new Compute();
const vms = await compute.getVMs(); // populated with right results

但是,只要我在Compute对象的构造函数中指定了keyFilename,虽然它们共享了与keyFilename中指定的相同的Google Cloud Project ID,但我的所有VM都不会显示在结果中。

const Compute = require('@google-cloud/compute');
const compute = new Compute({
    keyFilename: 'gcp.json'
});
const vms = await compute.getVMs(); // empty array

请帮忙!

google-cloud-platform google-compute-engine
1个回答
2
投票

也许最好为keyFilename使用绝对路径并添加参数

projectId: 'your-project-id'

到构造函数。

除此之外,根据documentation,你的代码看起来非常香草,所以我认为没有问题,应该工作。

© www.soinside.com 2019 - 2024. All rights reserved.