【发布时间】:2019-06-22 00:22:26
【问题描述】:
我正在使用以下代码使用 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"
}
你建议我做什么?切换到不同的区域可能是最好的解决方案。但是有一个问题,我什至不知道实例没有成功启动,所以我无法对此做出反应。这是预期的行为吗?您采取了哪些措施来缓解这个问题?
【问题讨论】:
-
我也有同样的问题,API调用响应
"status": "RUNNING"。 -
GCE 不会报告失败,因为它会等到给定区域中的一些资源可用,这就是为什么
"status": "PENDING" -
您可以设置 stackdriver 运行状况检查,或者您可以包含一个启动脚本,该脚本调用一个单独的 webhook 关于创建状态。
标签: php google-cloud-platform google-compute-engine gcloud