Ask Your Question
0

get_attr to retrieve IP address allocated to an instance

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

spradeepv gravatar image

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

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.

    userdata:
      str_replace:
        template: |
          ...
          ...
        params:
          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
1

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

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 10.0.0.0/24 |

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

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

Then I can get the ip address like this:

outputs:
  server_ip:
    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
"10.0.0.34"
edit flag offensive delete link more

Comments

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

spradeepv gravatar imagespradeepv ( 2014-09-11 02:16:26 -0500 )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 -0500 )edit

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: 2014-09-08 06:33:47 -0500

Seen: 6,724 times

Last updated: Sep 09 '14