我想通过 java google-api-client 使用 InstanceTemplate 创建一个实例。执行操作后,新实例会显示在 GCP 的 Compute Engine 前端中,并已创建。10-15 秒后,实例消失。
按照参考手册,我无法理解为什么我的代码不起作用。
https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert
Compute.Instances.Insert insert = compute
.instances()
.insert("{{project-id}}","europe-west1-c",instance)
.setSourceInstanceTemplate("/compute/v1/projects/{{project-id}}/global/instanceTemplates/instance-template-1")
.setZone("europe-west1-c")
.setProject("{{project-id}}");
Operation op = insert.execute();
实例对象如下所示:
Instance instance = new Instance();
instance.setName(instanceName);
instance.setMachineType("zones/europe-west1-c/machineTypes/g1-small");
Gradle 依赖项
compile 'com.google.api-client:google-api-client:1.31.2'
compile group: 'com.google.apis', name: 'google-api-services-compute', version: 'v1-rev235-1.25.0'
来自 GCP 的日志:
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"status": {
"code": 3,
"message": "INVALID_PARAMETER"
},
"authenticationInfo": {
"principalEmail": "compute-dev-me@{{project-id}}.iam.gserviceaccount.com"
},
"requestMetadata": {
"callerIp": "12.34.56.78",
"callerSuppliedUserAgent": "redacted/0.1 Google-API-Java-Client/1.31.2 Google-HTTP-Java-Client/1.37.0 (gzip),gzip(gfe)"
},
"serviceName": "compute.googleapis.com",
"methodName": "v1.compute.instances.insert",
"resourceName": "projects/{{project-id}}/zones/europe-west1-c/instances/test-mit-richtig",
"request": {
"@type": "type.googleapis.com/compute.instances.insert"
}
},
"insertId": "-duwg4fde7a2",
"resource": {
"type": "gce_instance",
"labels": {
"instance_id": "redacted-number",
"zone": "europe-west1-c",
"project_id": "{{project-id}}"
}
},
"timestamp": "2021-02-xxTxx:xx:xx.565227Z",
"severity": "ERROR",
"logName": "projects/{{project-id}}/logs/cloudaudit.googleapis.com%2Factivity",
"operation": {
"id": "operation-1613xxxx41-xxxxxxxx-xxxxxxxx-xxxxxxx",
"producer": "compute.googleapis.com",
"last": true
},
"receiveTimestamp": "2021-02-xxTxx:xx:xx.569578819Z"
}