[Heat] Reg accessing variables of resource group heat api

NANTHINI A A nanthini.a.a at ericsson.com
Tue Feb 12 05:44:22 UTC 2019


Hi ,
   May I know in the following example given

parameters:
  resource_name_map:
    - network1: foo_custom_name_net1
      network2: foo_custom_name_net2
    - network1: bar_custom_name_net1
      network2: bar_custom_name_net2
   what is the parameter type ?


Thanks,
A.Nanthini

From: Rabi Mishra [mailto:ramishra at redhat.com]
Sent: Tuesday, February 12, 2019 10:45 AM
To: NANTHINI A A <nanthini.a.a at ericsson.com>
Cc: hjensas at redhat.com; openstack-dev at lists.openstack.org
Subject: Re: [Heat] Reg accessing variables of resource group heat api

On Mon, Feb 11, 2019 at 9:23 PM NANTHINI A A <nanthini.a.a at ericsson.com<mailto:nanthini.a.a at ericsson.com>> 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]}

I don't think you can use %index% directly in this template. You have to pass it as resource property from tryreapet.yaml.  Please check the example[1] in heat-templates repo (resource_group_index_lookup.yaml and random.yaml).

[1] https://github.com/openstack/heat-templates/blob/master/hot/resource_group/resource_group_index_lookup.yaml

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



    Thanks in advance .


Thanks,
A.Nanthini
-----Original Message-----
From: Harald Jensås [mailto:hjensas at redhat.com<mailto:hjensas at redhat.com>]
Sent: Monday, February 11, 2019 7:47 PM
To: NANTHINI A A <nanthini.a.a at ericsson.com<mailto:nanthini.a.a at ericsson.com>>; openstack-dev at lists.openstack.org<mailto: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




--
Regards,
Rabi Mishra

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-discuss/attachments/20190212/bf4f3b51/attachment-0001.html>


More information about the openstack-discuss mailing list