在 openstack heat 模板中加入变量

chr*_*ley 2 openstack

假设我想根据 2 个变量命名资源,所以我有类似的东西:

heat_template_version: 2013-05-23

描述:创建网络

参数:
  客户代码:
    类型:字符串
    描述:4 个字符的客户代码。将用于实例命名
  项目代码:
    类型:字符串
    描述:3 个字符的项目代码

现在我想根据客户和项目的名称创建资源:

资源:
  测试:
    类型:OS::Neutron::Net
    特性:
      名称:{get_param: client_code}{get_param: project_code}

该资源创建给了我一个解析错误。无论如何我可以做到这一点,还是我需要使用预脚本来生成我的模板?

chr*_*ley 5

我找到了一个使用str_replace. 我的代码看起来像:

heat_template_version: 2013-05-23

description: Create network with

parameters:
  client_code:
    type: string
    description: 4 character customer code. Will be used for instance naming
  project_code:
    type: string
    description: 3 character project code

resources:
  test:
    type: OS::Neutron::Net
    properties:
      name:
        str_replace:
        template: cust%-proj%
        params:
          "cust%": { get_param: client_code } 
          "proj%": { get_param: project_code }
Run Code Online (Sandbox Code Playgroud)


小智 5

我找到了一个使用“list_join”的解决方案:

heat_template_version: 2013-05-23

  int_network:
    type: OS::Neutron::Net
    properties:
    name:
       list_join: ['-', [ {get_param: tenant}, 'net']]
Run Code Online (Sandbox Code Playgroud)