dongrui6787 2018-07-21 10:52
浏览 92

从失败的Google Compute Engine实例启动中获取错误消息

I am using the below code to start an instance. The code works as expected and starts an instance.

However, if $service->instances->start fails to start an instance due to an error at GCP end, I wont receive any notice. It will execute without any exceptions thrown. I've tested this by trying to run 2 instances with more then 8 cpus in a single zone (the free account is not allowed to own more than 8 cores in a zone). While the instances never started, I didn't receive any error in this script.

How can I recover from a general starting error? Should I use timers to check a minute later if everything is running as expected? Is there a more robust way of starting instances?

<?php
    require_once __DIR__ . '/vendor/autoload.php';
    $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);

    $project = 'project_id';  // TODO: Update placeholder value.
    $zone = 'us-east1-b';  // TODO: Update placeholder value.
    $instance = 'instance-1';  // TODO: Update placeholder value.

    $response = $service->instances->start($project, $zone, $instance);

    // TODO: Change code below to process the `response` object:
    echo '<pre>', var_export($response, true), '</pre>', "
";

On the other hand, CLI equivalent command gcloud compute instances start instance-1 --zone=us-east1-b does return an error. Is it possible to get the error message in PHP as well?

Error message in CLI:

Starting instance(s) instance-2...failed.                                                                                        
ERROR: (gcloud.compute.instances.start) Quota 'CPUS' exceeded.  Limit: 8.0 in region us-east1.
  • 写回答

1条回答 默认 最新

  • donglian4770 2018-07-27 19:29
    关注

    Please check the json tags of the response body to retrieve the error content. If you still don't see any output, you can file an issue here under 'Developer Tools'.

    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数