是否有办法获得所有可用虚拟机的规格(CPU, RAM,存储,…)?我尝试使用Compute API,但是,据我所知,我们只得到我们在项目中使用的虚拟机。
我使用他们的网站和。net SDK尝试了他们的API,结果都给我发送了null
:
{
kind: "some response",
id: "some response",
selfLink: "Google apis link"
// but no "items" element such as the element they describe in their documentation
}
ComputeService computeService = new ComputeService(new BaseClientService.Initializer
{
HttpClientInitializer = GetCredential(),
ApplicationName = "Google-ComputeSample/0.1",
});
// Project ID for this request.
string project = "fit-guide-347306";
// The name of the zone for this request.
string zone = "europe-west2-a";
InstancesResource.ListRequest request = computeService.Instances.List(project, zone);
Google.Apis.Compute.v1.Data.InstanceList response;
do
{
// To execute asynchronously in an async method, replace `request.Execute()` as shown:
// response = request.Execute();
response = await request.ExecuteAsync();
if (response.Items == null)
{
continue;
}
foreach (Google.Apis.Compute.v1.Data.Instance instance in response.Items)
{
// TODO: Change code below to process each `instance` resource:
Console.WriteLine(JsonConvert.SerializeObject(instance));
}
request.PageToken = response.NextPageToken;
} while (response.NextPageToken != null);
public static GoogleCredential GetCredential()
{
return GoogleCredential.FromFile("myPath/myFile.json");
}
但问题是,我想知道可用的虚拟机的规格为每个人,而不是谷歌云上的特定项目。
谢谢!
使用实例列表API列出所有实例。如果你想要细节,你必须使用instance get API。