【问题标题】:nested yaml templates for stack create in python用于在 python 中创建堆栈的嵌套 yaml 模板
【发布时间】:2017-05-29 12:33:06
【问题描述】:

我有一个 yaml 模板(我们称之为 main.yaml),它调用另一个 yaml 模板,如下所示。 VM1.yaml 模板是创建另一个堆栈的普通模板。 (它就像一个嵌套模板)

main.yaml

resources:
  VM1:
    type: OS::Heat::Stack
    properties:
      template: {get_file: vm/VM1.yaml}
      parameters:
        name: { list_join: ["_", [ { get_param: 'OS::stack_name' }, "VM1"]] }

下面是文件夹结构

  1. StackCreation.py => 这需要使用 MAIN_VM1_MOUNTED.yaml 创建堆栈
  2. MAIN_VM1_MOUNTED.yaml
  3. vm/VM1.yaml
  4. vm/parameter.yaml => 这是我传递参数的参数文件。

    template_file = 'MAIN_VM1_MOUNTED.yaml'
    template = open(template_file, 'r')
    stack_name = 'HeenaStack' + sys.argv[5]
    
    heat_parameters = open('vm/parameter.yaml')
    temp_params = yaml.load(heat_parameters)
    heat_parameters.close()
    
    try:
        #hc.stacks.create(stack_name=stack_name, template=template.read(), parameters=temp_params["parameters"])
        stackCreate = hc.stacks.create(stack_name=stack_name, template=template.read(), parameters=temp_params["parameters"])
        print("Stack Created successfully", "Stack ID:", str(hc.stacks.get(stack_name).id))
    

当我使用这个嵌套的 yaml 模板运行 openstack stack create 时,堆栈会成功创建。在 python 中没有发生同样的情况。 我遇到了错误。

Bad request :  {'explanation': 'The server could not comply with the request since it is either malformed or otherwise incorrect.', 'code': 400, 'error': {'message': 'Property error: : resources.VM1.properties.template: : No content found in the "files" section for get_file path: C:/Users/xxx/PycharmProjects/xxx/vm/VM1.yaml', 'traceback': None, 'type': 'StackValidationFailed'}, 'title': 'Bad Request'

我不明白我需要做什么。

【问题讨论】:

    标签: python-2.7 openstack heat openstack-heat


    【解决方案1】:

    使用文件解决它,template = template_utils.process_template_path(template_file)

    【讨论】:

      猜你喜欢
      • 2017-05-16
      • 2021-08-18
      • 2022-01-16
      • 1970-01-01
      • 2019-03-09
      • 2021-12-29
      • 2021-04-30
      • 1970-01-01
      • 2021-10-06
      相关资源
      最近更新 更多