简体   繁体   English

PHP:在 Google Cloud Compute 中创建服务器实例时出错

[英]PHP: Error in creating Server Instance in Google Cloud Compute

While using Google Cloud Compute's API in PHP, I am able to start, stop, delete instances as well as create and delete disks.在 PHP 中使用 Google Cloud Compute 的 API 时,我能够启动、停止、删除实例以及创建和删除磁盘。

However, when trying to create an Instance, I keep getting this error但是,在尝试创建实例时,我不断收到此错误

Invalid value for field 'resource.disks'字段“resource.disks”的值无效

PHP Fatal error:  Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/compute/v1/projects/project/zones/zone/instances: (400) Invalid value for field 'resource.disks': ''.  Boot disk must be specified.' in /var/www/html/google/google-api-php-client/src/Google/Http/REST

Here is the request I am making这是我提出的要求

self::connectClient();

$computeService = new Google_Service_Compute($this->client);

if ($this->client->getAccessToken()) 
{
    $googleNetworkInterfaceObj = new Google_Service_Compute_NetworkInterface();
    $network = self::DEFAULT_NETWORK;
    $googleNetworkInterfaceObj->setNetwork($network);

    $diskObj = self::getDisk($instance_name);

    $new_instance = new Google_Service_Compute_Instance();
    $new_instance->setName($instance_name);
    $new_instance->setMachineType(self::DEFAULT_MACHINE_TYPE);
    $new_instance->setNetworkInterfaces(array($googleNetworkInterfaceObj));
    $new_instance->setDisks(array(
                    "source"=>$diskObj->selfLink,
                    "boot"=>true,
                    "type"=>"PERSISTENT",
                    "deviceName"=>$diskObj->name,
                   ));

   $insertInstance = $computeService->instances->insert(self::DEFAULT_PROJECT,self::DEFAULT_ZONE_NAME, $new_instance);

Any help will be highly appreciated, thank you.任何帮助将不胜感激,谢谢。

Ok the solution was really simple (and silly)好的解决方案非常简单(而且很愚蠢)

Instead of代替

$new_instance->setDisks(array(
                    "source"=>$diskObj->selfLink,
                    "boot"=>true,
                    "type"=>"PERSISTENT",
                    "deviceName"=>$diskObj->name,
                   ));

It's supposed to be应该是

$new_instance->setDisks(array(
         array(
            'source'=>self::getDisk($instance_name)->selfLink,
            'boot'=>true,
            'type' => "PERSISTENT",
            'deviceName'=>self::getDisk($instance_name)->name,
            )
          ));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 500(内部服务器错误)在 Google Cloud 中托管 Web - Compute Engine VM + Firestore + PHP + Apache2 - 500 (Internal Server Error) Hosting Web in Google Cloud - Compute Engine VM + Firestore + PHP + Apache2 从 Cloud Run PHP 连接到 Google Cloud Compute Engine 虚拟机上的 MySQL 实例 - Connect to MySQL instance on Google Cloud Compute Engine VM from Cloud Run PHP PHP在localhost上运行,在Google Cloud服务器上出错 - PHP works on localhost, error on Google Cloud server 谷歌云计算负载均衡器504错误 - google cloud compute load balancer 504 error 在 Google Cloud Compute Engine 虚拟机实例上设置 MySQL - Setting up MySQL on a Google Cloud Compute Engine VM instance Google Cloud Console 虚拟机实例上的 Apache 服务器 - Apache Server on Google Cloud Console VM Instance Google Cloud Compute Engine-无法在php文件中使用mysqli函数 - Google Cloud Compute Engine - unable to use mysqli functions in php files 从不成功的Google Compute Engine实例启动中获取错误消息 - get error message from unsuccessful Google Compute Engine instance start 无法在Google Cloud Compute引擎实例中获得访问者的公共IP(已创建容器集群) - Cannot get visitor's public IP in Google Cloud Compute engine instance (container cluster created) 无法通过 Google Compute Engine 使用 PHP 在 Google Cloud Storage 上上传文件 - Unable to upload files on Google Cloud Storage using PHP via Google Compute Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM