[openstack-dev] [Heat] [TripleO] Better handling of lists in Heat - a proposal to add a map function

Clint Byrum clint at fewbar.com
Wed Feb 19 07:48:47 UTC 2014


Since picking up Heat and trying to think about how to express clusters
of things, I've been troubled by how poorly the CFN language supports
using lists. There has always been the Fn::Select function for
dereferencing arrays and maps, and recently we added a nice enhancement
to HOT to allow referencing these directly in get_attr and get_param.

However, this does not help us when we want to do something with all of
the members of a list.

In many applications I suspect the template authors will want to do what
we want to do now in TripleO. We have a list of identical servers and
we'd like to fetch the same attribute from them all, join it with other
attributes, and return that as a string.

The specific case is that we need to have all of the hosts in a cluster
of machines addressable in /etc/hosts (please, Designate, save us,
eventually. ;). The way to do this if we had just explicit resources
named NovaCompute0, NovaCompute1, would be:

  str_join:
    - "\n"
    - - str_join:
        - ' '
        - get_attr:
          - NovaCompute0
          - networks.ctlplane.0
        - get_attr:
          - NovaCompute0
          - name
      - str_join:
        - ' '
        - get_attr:
          - NovaCompute1
          - networks.ctplane.0
        - get_attr:
          - NovaCompute1
          - name

Now, what I'd really like to do is this:

map:
  - str_join:
    - "\n"
    - - str_join:
      - ' '
      - get_attr:
        - "$1"
        - networks.ctlplane.0
      - get_attr:
        - "$1"
        - name
  - - NovaCompute0
    - NovaCompute1

This would be helpful for the instances of resource groups too, as we
can make sure they return a list. The above then becomes:


map:
  - str_join:
    - "\n"
    - - str_join:
      - ' '
      - get_attr:
        - "$1"
        - networks.ctlplane.0
      - get_attr:
        - "$1"
        - name
  - get_attr:
      - NovaComputeGroup
      - member_resources

Thoughts on this idea? I will throw together an implementation soon but
wanted to get this idea out there into the hive mind ASAP.



More information about the OpenStack-dev mailing list