str_replace with get_attr in Openstack Icehouse [closed]

asked 2016-05-18 11:06:13 -0600

giagiannis gravatar image

updated 2016-05-18 11:06:59 -0600

Hi everyone,

I have the following HOT template

heat_template_version: 2013-05-23
description: Simple HOT template with dependencies
resources:
  instance1:
    type: OS::Nova::Server
    depends_on: instance2
    properties:
      key_name: default
      image: 80a652ae-5b08-48c8-b069-b4c02c1b24fe
      flavor: singles.1
      user_data_format: RAW
      user_data: 
        str_replace:
          template: |
            #!/bin/bash
            echo "$FOO" > /tmp/message
            exit 0
          params:
            $FOO: { get_attr: [ instance2, networks, private-net ] }
  instance2:
    type: OS::Nova::Server
    properties:
      key_name: default
      image: 80a652ae-5b08-48c8-b069-b4c02c1b24fe
      flavor: singles.1

outputs:
  instance_ip1:
    value: { get_attr: [instance1, networks, private-net] }

When I am trying to launch the stack, I get the following error:

Resource CREATE failed: StackValidationFailed: Property
error : instance1: user_data "str_replace" params must
be strings or numbers

and from http://docs.openstack.org/developer/heat/template_guide/hot_spec.html#str-replace (here) I can conclude that in version 2013-05-23 str_replace does not support replacing between stringes and JSON objects. Is this correct? If this is the case, how can I dynamically inject the IP address of instance2 into the script executed at instance1?

I attach the heat version I am running:

ii  heat-api                             2014.1.5-0ubuntu1                     all          OpenStack orchestration service - ReST API
ii  heat-api-cfn                         2014.1.5-0ubuntu1                     all          OpenStack orchestration service - CFN API
ii  heat-common                          2014.1.5-0ubuntu1                     all          OpenStack orchestration service - common files
ii  heat-engine                          2014.1.5-0ubuntu1                     all          OpenStack orchestration service - engine
ii  python-heat                          2014.1.5-0ubuntu1                     all          OpenStack orchestration service - Python files
ii  python-heatclient                    0.2.8-0ubuntu1                        all          client library and CLI for OpenStack Heat

Thank you in advance.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by giagiannis
close date 2016-05-19 04:01:57.063316

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-19 04:01:45 -0600

giagiannis gravatar image

After some research, it turns out that the problem is not related to the usage of the get_attr function inside the str_replace function! The problem is that the tag

get_attr: [ instance2, networks, private-net ]

returns a list of IP addresses rather than a string. The problem was solved by appending the index 0 in the get_attr function

    get_attr: [ instance2, networks, private-net, 0]

and the (single) IP address that is returned is now considered a string and the above example works!

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2016-05-18 11:06:13 -0600

Seen: 705 times

Last updated: May 19 '16