Ask Your Question
0

Heat/Yaml: get_param not working for lists in for_each construct

asked 2015-06-17 05:59:53 -0500

Murali G D gravatar image

updated 2015-06-17 06:00:48 -0500

Hi I am using following template to create security-group actually to understand repeat/for_each construct

heat_template_version: 2015-04-30

parameters:
  ports:
    label: ports
    type: comma_delimited_list
    default: "80,443,8080"

resources:
  security_group:
    type: OS::Neutron::SecurityGroup
    properties:
      name: web_server_security_group
      rules:
        repeat:
          for_each:
           "port%": { get_param: ports }
          template:
            protocol: tcp
            port_range_min: port%
            port_range_max: port%

But when I try to execute I get following error.

root@controller:~# heat stack-create -f templates/secgroup_v1.yaml secTest234
ERROR: The values of the "for_each" argument to "repeat" must be list

It looks get_param is not treating "ports" as list.

If I replace get_param line like below hard-coded port%: ['22','32'] Heat is creating security-group successfully. So suspect it around get_param.

Any clue ?

OpenStack Version: Kilo and Heat Version: 0.3.0

Regards Murali G D

edit retag flag offensive close merge delete

Comments

In the example in the documenation http://docs.openstack.org/developer/heat/template_guide/hot_spec.html?highlight=for_each#repeat there is %'s on both sides of the variable i.e.

 %port%: { get_param: ports }
 template:
 port_range_min: %port%
 port_range_max: %port%

could that be it?

Jet gravatar imageJet ( 2015-06-17 14:40:23 -0500 )edit

No Jet. With % in front to port variable we get heat parsing error. So I removed it based on other sample templates.

Murali G D gravatar imageMurali G D ( 2015-06-17 19:35:57 -0500 )edit

Any luck with this? I was hoping to make this work without hacking the python...

apu123 gravatar imageapu123 ( 2015-07-17 15:58:02 -0500 )edit

Hi, I have similar problem but with little more added complexity. Is there a way, I can add two types of protocol under rules, for example I want to add something like

  rules:
    protocol: ip
    port_range_min: 500
    port_range_max: 500
    repeat:
      for_each:
prat gravatar imageprat ( 2016-09-20 08:52:21 -0500 )edit

adding the truncated part

  rules:
    protocol: ip
    port_range_min: 500
    port_range_max: 500
    repeat:
      for_each:
        <%port%>: { get_param: ports }
      template:
        protocol: tcp
        port_range_min: <%port%>
        port_rang
prat gravatar imageprat ( 2016-09-20 08:53:11 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2015-06-18 23:57:17 -0500

Murali G D gravatar image

In file : /usr/lib/python2.7/dist-packages/heat/engine/hot/functions.py In function: class Repeat(function.Function):

commented following check and I was able to use for_each with get_param as mentioned in my question.

#        for v in six.itervalues(for_each):
#            if not isinstance(v, list):
#                raise TypeError(_('The values of the "for_each" argument to '
#                                  '"%s" must be lists') % self.fn_name)

Regards, Murali G D

edit flag offensive delete link more

Comments

Note that this was fixed upstream in Liberty and backported to the 2015.1.3 stable release of Kilo: https://bugs.launchpad.net/heat/+bug/...

zaneb gravatar imagezaneb ( 2016-07-29 11:13:45 -0500 )edit
0

answered 2015-07-05 18:22:11 -0500

Steve Baker gravatar image

Can you make the default value a YAML list instead of a comma delimited string? ie

  ports:
    label: ports
    type: comma_delimited_list
    default: [80, 443, 8080]
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: 2015-06-17 05:59:53 -0500

Seen: 1,850 times

Last updated: Jul 05 '15