Ask Your Question
1

nested yaml templates for stack create in python

asked 2017-05-30 10:25:46 -0500

heena gravatar image

I have a yaml template (lets call it main.yaml) which calls another yaml template like below. the VM1.yaml template is a normal template that creates another stack. (It will be like a nested template)

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"]] }

Below is the folder structure

  1. StackCreation.py => this calls for stack create using MAIN_VM1_MOUNTED.yaml
  2. MAIN_VM1_MOUNTED.yaml
  3. vm/VM1.yaml
  4. vm/parameter.yaml => this is a parameter file where I am passing the parameters.

    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))
    

Whn I am running openstack stack create with this nested yaml templates, the stack gets created successfully. The same is not happening in python. I am getting below error.

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'

I dont understand what I need to do.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-05-31 11:03:10 -0500

zaneb gravatar image

The python-heatclient does some extra magic for you when you call it from the command line, to scan the template for any files that are referenced using get_file and ensure they get included in the request. The functions to do this are available in the client library, but you have to call them explicitly:

from heatclient.common import template_utils

files, template = template_utils.process_template_path(template_file)
stackCreate = hc.stacks.create(stack_name=stack_name, template=template, parameters=temp_params["parameters"], files=files)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2017-05-30 10:25:46 -0500

Seen: 322 times

Last updated: May 31 '17