2017-05-29 74 views
0

我有一個yaml模板(讓我們稱之爲main.yaml),它調用像下面這樣的另一個yaml模板。 VM1.yaml模板是創建另一個堆棧的普通模板。 (這將是象嵌套模板)嵌套yaml模板的堆棧創建在python

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.y aml =>這是一個參數文件,我傳遞參數。

    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我運行OpenStack的疊加與此嵌套YAML模板創建,堆棧被成功創建。 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' 

我不明白我需要做什麼。

回答

0

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