python - Google 部署管理器问题 : Can not create Instance Template

标签 python gcloud google-deployment-manager

我尝试使用 gcloud deployment-manager 部署自定义实例模板,但不断收到此错误:

ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1507833758152-55b5de788f540-e3be8bf6-a792d98e]: errors:
- code: RESOURCE_ERROR
  location: /deployments/my-project/resources/worker-template
  message: '{"ResourceType":"compute.v1.instanceTemplate","ResourceErrorCode":"400","ResourceErrorMessage":{"code":400,"errors":[{"domain":"global","message":"Invalid
    value for field ''resource.properties'': ''''. Instance Templates must provide
    instance properties.","reason":"invalid"}],"message":"Invalid value for field
    ''resource.properties'': ''''. Instance Templates must provide instance properties.","statusMessage":"Bad
    Request","requestPath":"https://www.googleapis.com/compute/v1/projects/my-project/global/instanceTemplates","httpMethod":"POST"}}'

我的pythongenerate_config函数是这样的:

def generate_config(context):

    resources = [{
        'type': 'compute.v1.instanceTemplate',
        'name': 'worker-template',
        'properties': {
            'zone': context.properties['zone'],
            'description': 'Worker Template',
            'machineType': context.properties['machineType'],
            'disks': [{
                'deviceName': 'boot',
                'type': 'PERSISTENT',
                'boot': True,
                'autoDelete': True,
                'initializeParams': {
                    'sourceImage': '/'.join([
                        context.properties['compute_base_url'],
                        'projects', context.properties['os_project'],
                        'global/images/family', context.properties['os_project_family']
                    ])
                }
            }],
            'networkInterfaces': [{
                'network': '$(ref.' + context.properties['network'] + '.selfLink)',
                'accessConfigs': [{
                    'name': 'External NAT',
                    'type': 'ONE_TO_ONE_NAT'
                }]
            }]
        }
    }]

    return {'resources': resources}

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

谢谢!

最佳答案

阅读后this example ,我刚刚发现compute.v1.instanceTemplate的正确结构是:

  ...
  'type': 'compute.v1.instanceTemplate',
  'name': 'worker-template',
  'properties': {
      'project': 'my-project',
      'properties': {
           'zone': context.properties['zone'],
           ...
      }
  }
  ...

结构如下this doc

关于python - Google 部署管理器问题 : Can not create Instance Template,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46717233/

相关文章:

python - 替换所有列 pandas df 中的多个字符

Python/Linux 定时任务

python - 在不重新绘制整个图形的情况下更新图形上的艺术家 (Line2D) - axes.draw_artist() 崩溃

android - 从 CLI 测试后如何获取 gcloud Firebase 测试实验室 Android Espresso 结果?

docker - 阻止Google容器注册表保留 “overwritten”图像

google-cloud-run - 使用 Deployment Manager 创建 Cloud Run 服务

Python - 数据框 - 无法删除重复项

python - 如何在 google ml api python 客户端中设置请求超时?

google-cloud-platform - 有没有办法在 GCP 部署管理器中设置项目元数据

java - 无法使用 Java 部署管理器 SDK 更新 GCP 部署