小编Dan*_*ter的帖子

如果启动计算引擎实例失败,如何获取错误

我使用以下代码使用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);

}
Run Code Online (Sandbox Code Playgroud)

今天,我很幸运地意识到,由于未知原因,我想启动的实例未能成功。我尝试使用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": …
Run Code Online (Sandbox Code Playgroud)

php google-compute-engine google-cloud-platform gcloud

6
推荐指数
1
解决办法
384
查看次数