使用gcloud api gem插入实例时出错

时间:2016-02-17 13:39:35

标签: ruby google-cloud-platform google-api-ruby-client

尝试使用google-api-client 0.9.2在Google Cloud中启动实例 我正在跑步:

compute.insert_instance(project, zone, instance_opts)

instance_opts的位置:

---
machineType: https://www.googleapis.com/compute/v1/projects/openshift-gce-devel/zones/us-central1-a/machineTypes/n1-standard-1
disks:
- initializeParams:
    sourceImage: https://www.googleapis.com/compute/v1/projects/myproject/global/images/myimage
  type: SCRATCH
networkInterfaces:
- network: projects/myproject/global/networks/default
  accessConfigs:
  - name: external
name: mytest

但是我从服务器收到错误:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required field 'resource.name' not specified"
   }
  ],
  "code": 400,
  "message": "Required field 'resource.name' not specified"
 }
}

即使我只提出instance_opts,我也会遇到完全相同的问题:

{"name": "mytest"}

我收到了未知字段的错误"资源"或" resource.name"如果我尝试在instance_opts中设置它们。设置磁盘名称也没有帮助。所以我想知道问题是什么。

1 个答案:

答案 0 :(得分:1)

嗯,可能是愚蠢但我无法理解它实际上我必须创建一个Instance对象并将其用于呼叫。

io = Google::Apis::ComputeV1::Instance.new(instance_opts)
compute.insert_instance(project, zone, io)

但还有一个细节。哈希值应为:machine_type而不是"machineType"。所有哈希键都是一样的。