1

我正在尝试使用 gcloud 部署管理器部署自定义实例模板,但我不断收到此错误:

错误:(gcloud.deployment-manager.deployments.update)操作错误 [operation-1507833758152-55b5de788f540-e3be8bf6-a792d98e]:错误:
- 代码:RESOURCE_ERROR
  位置:/deployments/my-project/resources/worker-template
  消息:'{"ResourceType":"compute.v1.instanceTemplate","ResourceErrorCode":"400","ResourceErrorMessage":{"code":400,"errors":[{"domain":"global","消息":"无效
    字段''resource.properties''的值:''''。实例模板必须提供
    实例属性。","re​​ason":"invalid"}],"message":"字段值无效
    ''resource.properties'':''''。实例模板必须提供实例属性。","statusMessage":"Bad
    请求","re​​questPath":"https://www.googleapis.com/compute/v1/projects/my-project/global/instanceTemplates","httpMethod":"POST"}}'

我的 python generate_config 函数是这样的:

def generate_config(上下文):

    资源 = [{
        'type': 'compute.v1.instanceTemplate',
        '名称':'工人模板',
        '特性': {
            'zone': context.properties['zone'],
            'description': '工人模板',
            'machineType': context.properties['machineType'],
            “磁盘”:[{
                'deviceName': '启动',
                '类型':'持久',
                “引导”:是的,
                “自动删除”:是的,
                “初始化参数”:{
                    'sourceImage': '/'.join([
                        context.properties['compute_base_url'],
                        '项目',context.properties ['os_project'],
                        'global/images/family', context.properties['os_project_family']
                    ])
                }
            }],
            “网络接口”:[{
                'network': '$(ref.' + context.properties['network'] + '.selfLink)',
                “访问配置”:[{
                    'name': '外部 NAT',
                    “类型”:“ONE_TO_ONE_NAT”
                }]
            }]
        }
    }]

    返回{'资源':资源}

属性不为空,因此错误消息没有多大意义。有任何想法吗?

谢谢!

4

1 回答 1

1

看完这个例子,我才发现compute.v1.instanceTemplate的正确结构是:

  ...
  'type': 'compute.v1.instanceTemplate',
  '名称':'工人模板',
  '特性': {
      “项目”:“我的项目”,
      '特性': {
           “区域”:context.properties[“区域”],
           ...
      }
  }
  ...

结构遵循此文档

于 2017-10-13T01:39:38.230 回答