Ask Your Question
1

How can I get information on other instances created in a Heat template

asked 2014-11-28 19:12:21 -0600

don gravatar image

updated 2014-11-29 10:04:15 -0600

I have a Heat template which creates 2 instances, A & B. I want A to know about B (e.g. its IP address / assigned hostname, whatever).

I don't see how to do this? If i looked @ the metadata in e.g. /openstack/latest/meta_data.json, i see all the info about the instance I'm running on, but not about the other instance.

What am I missing? I would like to get the meta data for the entire Heat template as instantiated, not just the one instance i'm looking from.

[additional data on use case] I have a virtual network function which has 3 types of instance in it. Each needs to be configured with the IP of the others due to an internal messaging bus they share. e.g. type A needs to be configured with the list of all the IP of type B, etc. I also need the hostnames allocated to the other instances.

One clumsy way to do this is a user_data script, using str_replace:

  user_data_format: RAW
  user_data:
    str_replace:
      template: |
        #!/bin/bash
        ifup eth1
        sed -i -e 's?spb_spb_servers=.*??' /usr/local/sandvine/etc/rc.conf
        echo spb_spb_servers=SPB >> /usr/local/sandvine/etc/rc.conf
      params:
        SPB: { get_attr: [ spb_ctrl_port, fixed_ips, 0, ip_address ] }

but the problem is this scales poorly if i want to get other attributes. Ideally I would be able to get the metadata: fields from other other instances, by their name.

I had assumed there was a way to get all of the metadata for my stack from any instance, but in fact it seems i can only get the metadata associated with my instance within the stack.

edit retag flag offensive close merge delete

Comments

it would be helpful if the use case is more elaborated because it is possible to get some of the data in certain ways but not all of them in a convenient way.

Qiming gravatar imageQiming ( 2014-11-28 20:49:55 -0600 )edit

additional info added to body

don gravatar imagedon ( 2014-11-29 10:04:39 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2014-11-29 12:53:19 -0600

miguelgrinberg gravatar image

There are a few ways to do what you want.

If you pass your instances the user's credentials, then then they can connect to your OpenStack controller and use standard Heat and/or Nova APIs to obtain all the information that they need.

Another option is to use SoftwareConfig + SoftwareDeployment resources in your template to push a config file with all the information to all your instances after all of them are created and their properties known. This method has a complication though; you can't use regular images, as the software config resources need a little service running on the instances that polls for commands to execute after creation. The procedure to create a software config enabled image for Heat is explained in the documentation.

I hope this helps.

edit flag offensive delete link more

Comments

right... but that technique doesn't have a convenient way to 'fetch all the config that was created by Heat', i would have to write some file out to each system, and put a set of getresource/getattr... effectively every resource in my heat template will need a second line in every other resource.

don gravatar imagedon ( 2014-12-02 08:10:54 -0600 )edit
0

answered 2014-12-08 09:50:16 -0600

zaneb gravatar image

The metadata you're referring to is supplied by Nova, not Heat. Not only does Nova not know about the rest of the template, it wouldn't make sense for it to supply metadata to an instance other than the one to which it applies.

The 'clumsy' way to do this using get_attr and str_replace in the user_data script is the correct one, although it can be made considerably less clumsy by using SoftwareDeployment resources. That also solves many of the circular dependency issues, and for clusters the SoftwareDeployments (plural) resource solves the rest.

edit flag offensive delete link more
0

answered 2014-12-02 08:15:07 -0600

don gravatar image

updated 2014-12-02 08:17:14 -0600

What i have done in the meanwhile research this is create a metadata tag, as below, which has an array for each other resource-type in my template, and an entry in that array for each instance, with in turn a struct of all the config items i want to pass between them.

I'll look more @ the SoftwareConfig but i think it has the same issue, its a bit clumsy to fill all this stuff in, i'd rather be able to to a 'fetch the decisions you made' call, or better, have a metadata auto constructed that is just there.

I don't want to pass the username/password in, then i have to add a second set of config vars in heat and its confusing for the user not to mention a security issue since they would be stored in cleartext.

I had to use 'ports' pre-configured w/ IP for each resource else I ended up with a circular reference.

  pts:
    type: OS::Nova::Server
    properties:
      name: { str_replace: { params: { $stack_name: { get_param: 'OS::stack_name' } }, template: '$stack_name-pts' } }
      key_name: { get_param: 'ssh_key' }
      image: { get_param: 'pts_image' }
      metadata:
        {
          sandvine:
          {
            auto_config: { get_param: 'config' },
            sde:
            {
              1:
              {
                ip:     { get_attr: [ sde_ctrl_port, fixed_ips, 0, ip_address ] },
              }
            },
            pts:
            {
              1:
              {
                ip:     { get_attr: [ pts_ctrl_port, fixed_ips, 0, ip_address ] }
              }
            },
            spb:
            {
              1:
              {
                ip:     { get_attr: [ spb_ctrl_port, fixed_ips, 0, ip_address ] },
              }
            },
            int_subnet:  { get_attr: [data_int_subnet, cidr] }
          }
        }
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: 2014-11-28 19:12:21 -0600

Seen: 1,609 times

Last updated: Dec 08 '14