我使用以下代码使用PHP启动实例:
function startInstance($g_project,$g_instance, $g_zone){ $client = new Google_Client(); $client->setApplicationName('Google-ComputeSample/0.1'); $client->useApplicationDefaultCredentials(); $client->addScope('https://www.googleapis.com/auth/cloud-platform'); $service = new Google_Service_Compute($client); $response = $service->instances->start($g_project, $g_zone, $g_instance); echo json_encode($response); }
今天,我很幸运地意识到,由于未知原因,我想启动的实例未能成功。我尝试使用GUI启动它,并通过GUI得到一个错误:Zone "some-zone" does not have enough resources available to fulfill the request. Try a different zone, or try again later.
我回显了PHP响应,并将其与实例成功启动时得到的响应进行了比较。我的发现令人震惊。响应完全相同(不计算时间戳和ID)。如果响应相同,我该如何区分失败的实例启动和成功?
https://cloud.google.com/compute/docs/reference/rest/v1/instances/start建议在出现error
错误的情况下将存在一个对象。我可以确认没有。
两者的响应均未成功启动:
{ "clientOperationId": null, "creationTimestamp": null, "description": null, "endTime": null, "httpErrorMessage": null, "httpErrorStatusCode": null, "id": "id", "insertTime": "2019-01-28T14:22:36.664-08:00", "kind": "compute#operation", "name": "operation-name", "operationType": "start", "progress": 0, "region": null, "selfLink": "link/operation-name", "startTime": null, "status": "PENDING", "statusMessage": null, "targetId": "targetIdHere", "targetLink": "linkhere", "user": "user", "zone": "zone-in-question" }
你建议我做什么?切换到其他区域可能是最好的解决方案。但是有一个问题,我什至没有实例没有成功启动,所以我无法对此做出反应。这是预期的行为吗?您做了什么缓解这个问题?