[Heat] Reg accessing variables of resource group heat api

Zane Bitter zbitter at redhat.com
Mon Feb 11 20:32:59 UTC 2019


On 12/02/19 4:32 AM, NANTHINI A A wrote:
> Hi ,
>     I have tried the below .But getting error .Please let me know how I can proceed further .
> 
> root at cic-1:~# cat try1.yaml
> heat_template_version: 2013-05-23
> description:
>    This is the template for I&V R6.1 base configuration to create neutron  resources other than sg and vm for vyos vms
> parameters:
>    resource_name_map:
>      - network1: NetworkA1
>        network2: NetworkA2
>      - network1: NetworkB1
>        network2: NetworkB2
> 
> resources:
>    neutron_Network_1:
>      type: OS::Neutron::Net
>      properties:
>        name: {get_param: [resource_name_map, %index%, network1]}
>    neutron_Network_2:
>      type: OS::Neutron::Net
>      properties:
>        name: {get_param: [resource_name_map, %index%, network2]}
> root at cic-1:~# cat tryrepeat.yaml
> 
> heat_template_version: 2013-05-23
> 
> resources:
>    rg:
>      type: OS::Heat::ResourceGroup
>      properties:
>        count: 2
>        resource_def:
>          type: try1.yaml
> root at cic-1:~#
> 
> root at cic-1:~# heat stack-create tests -f tryrepeat.yaml
> WARNING (shell) "heat stack-create" is deprecated, please use "openstack stack create" instead
> ERROR: resources.rg<nested_stack>: : Error parsing template file:///root/try1.yaml while scanning for the next token
> found character '%' that cannot start any token
>    in "<unicode string>", line 15, column 45:
>       ... {get_param: [resource_name_map, %index%, network1]}

That's a yaml parsing error. You just need to put quotes around the 
thing that starts with %, like "%index%"

>      Thanks in advance .
> 
> 
> Thanks,
> A.Nanthini
> -----Original Message-----
> From: Harald Jensås [mailto:hjensas at redhat.com]
> Sent: Monday, February 11, 2019 7:47 PM
> To: NANTHINI A A <nanthini.a.a at ericsson.com>; openstack-dev at lists.openstack.org
> Subject: Re: [Heat] Reg accessing variables of resource group heat api
> 
> On Wed, 2019-02-06 at 06:12 +0000, NANTHINI A A wrote:
>> Hi ,
>>      We are developing heat templates for our vnf deployment .It
>> includes multiple resources .We want to repeat the resource and hence
>> used the api RESOURCE GROUP .
>>      Attached are the templates which we used
>>   
>> Set1.yaml -> has the resources we want to repeat Setrepeat.yaml -> has
>> the resource group api with count .
>>    
>>       We want to access the variables of resource in set1.yaml while
>> repeating it with count .Eg . port name ,port fixed ip address we want
>> to change in each set .
>>     Please let us know how we can have a variable with each repeated
>> resource .
>>   
> 
> Sounds like you want to use the index_var variable[1] to prefix/suffix reource names?
> 
>   I.e in set1.yaml you can use:
> 
>     name:
>      list_join:
>        - '_'
>        - {get_param: 'OS::stack_name'}
>        - %index%
>        - <resource_name>
> 
> 
> The example should resulting in something like:
>    stack_0_Network3, stack_0_Subnet3
>    stack_1_Network0, stack_1_Subnet0
>    [ ... ]
> 
> 
> If you want to be more advanced you could use a list parameter in the set1.yaml template, and have each list entry contain a dictionaly of each resource name. The %index% variable would then be used to pick the correct entry from the list.
> 
> 
> parameters:
>    resource_name_map:
>      - network1: foo_custom_name_net1
>        network2: foo_custom_name_net2
>      - network1: bar_custom_name_net1
>        network2: bar_custom_name_net2    -
> 
> resources:
>    neutron_Network_1:
>      type: OS::Neutron::Net
>      properties:
>        name: {get_param: [resource_name_map, %index%, network1]}
>    neutron_Network_2:
>      type: OS::Neutron::Net
>      properties:
>        name: {get_param: [resource_name_map, %index%, network2]}
> 
> 
>   %index% is the "count" picking the 'foo' entries when %index% is 0, and 'bar' entries when %index% is 1 and so on.
> 
> 
> 
> 
> 
> [1]
> https://docs.openstack.org/heat/latest/template_guide/openstack.html#OS::Heat::ResourceGroup-props-opt
> 
> 
> 




More information about the openstack-discuss mailing list