Ask Your Question

get_attr to retrieve IP address allocated to an instance

asked 2014-09-08 06:33:47 -0600

spradeepv gravatar image

updated 2014-09-09 05:54:44 -0600

I have been trying to deploy an application in 2 different subnets using heat template. I successfully deployed web server instance and database server instance. In the heat template I use the following function to get the IP address of the database server instance - to configure the DB server in web server instance.

        template: |
          db_ipaddr: {get_attr: [database_server, networks, private, 0]} 
    depends_on: database_server

The IP address of the database server is not set in the web server's configuration file. It is empty.

How do I solve this issue?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2014-09-09 08:45:44 -0600

larsks gravatar image

The documentation for the OS::Nova::Server resource indicates that the networks attribute is:

A dict of assigned network addresses of the form: {“public”: [ip1, ip2...], “private”: [ip3, ip4]}.

What they don't make clear is that "public" and "private" are just examples; the keys to this dict are the names of your networks. So, for example, in my environment I have a network named net0:

$neutron net-list|grep net0
| 18fc1b31-9b2c-4b6e-8dea-7e04bfd1eb43 | net0                              | 55c6da11-cfbe-4443-bb5f-19c4d0ea041a |

If I deploy an OS::Nova::Server resource associated with that network:

    type: "OS::Nova::Server"
      image: fedora
      flavor: m1.small
      key_name: lars
        - network: 18fc1b31-9b2c-4b6e-8dea-7e04bfd1eb43

Then I can get the ip address like this:

    description: fixed ip assigned to the server
    value: { get_attr: [my_server, networks, net0, 0]}

Which will give me:

$ heat output-show ask server_ip
edit flag offensive delete link more


Thank You larsks. I provided the network name and it worked as expected.

spradeepv gravatar imagespradeepv ( 2014-09-11 02:16:26 -0600 )edit

Also, you don't need the depends_on: database_server since calling get_attr: database_server... creates a dependency anyway

Steve Baker gravatar imageSteve Baker ( 2014-09-18 22:26:07 -0600 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-09-08 06:33:47 -0600

Seen: 6,847 times

Last updated: Sep 09 '14