Ask Your Question
0

Heat get_param Processing Array of Object

asked 2015-07-06 15:34:39 -0600

Nastooh gravatar image

Hi
Have a template that consists of 2 parts: Part 1 that allocates a number of private IPs, and Part 2 that tries to assign each IP to a nova instance. I am using ResourceGroup class to instantiate proper number of objects:

heat_template_version: 2013-05-23

description: Template X.

parameters:
  ...
  cluster_size:
    type: number
    label: Cluster size
    description: Number of  instances.
    default: 2

resources:
  masters_ip:
    type: OS::Heat::ResourceGroup
    properties:
      count: { get_param: cluster_size }
      resource_def:
        type: Lib::GET_IP::GetIp
        properties:
          private_network: { get_param: private_network }
  masters:
    type: OS::Heat::ResourceGroup
    properties:
      count: { get_param: cluster_size }
      resource_def:
        type: Lib::MASTER::Master
        properties:
          ...
          private_ips: { get_attr: [masters_ip,ip] }
          indx: "%index%"
outputs:
  ip:
    description: The IP address of the master instances.
    value: { get_attr: [masters_ip,ip] }

Where GetIP:

heat_template_version: 2013-05-23

description: Template that gets an ip.

parameters:
  private_network:
    type: string
    label: Private network name or ID
    description: Network to attach server to.
    default: priv01

resources:
  ip_instance:
    type: OS::Neutron::Port
    properties:
      network: { get_param: private_network }

outputs:
  ip:
    description: The IP address of the instance.
    value: { get_attr: [ip_instance, fixed_ips,0,ip_address] }

Looking at the heat show-stack, I see the properly allocated IPs:

...
 links                 | http://10.4.0.64:8004/v1/8f3633c4ba1640abbab3be608b6bcc88/stacks/masters/aad06669-90b9-4f02-808b-fa65b62a8e89 (self) |
| notification_topics   | []                                                                                                                   |
| outputs               | [                                                                                                                    |
|                       |   {                                                                                                                  |
|                       |     "output_value": [                                                                                                |
|                       |       "10.40.50.157",                                                                                                |
|                       |       "10.40.50.156"                                                                                                 |
|                       |     ],                                                                                                               |
|                       |     "description": "The IP address of the master instances.",                                                        |
|                       |     "output_key": "ip"                                                                                               |
|                       |   }                                                                                                                  |
|                       | ]                                                                                                                    |
| parameters            | {   
...

In my nested nova sack, tried to pick up the ip using the following:

heat_template_version: 2013-05-23

description: Template  masters.

parameters:
 ...
  private_ips:
    type: comma_delimited_list
    label: Private network name or ID
    description: Network to attach server to.
  indx:
    type: number
    label: Id
    description: Index of the current instance
    default: 0

resources:
  instance:
    type: OS::Nova::Server
    properties:
      networks:
           - port: { get_param: [ private_ips, indx ] }
      ...

This however gives the following error:

Resource CREATE failed: ResourceUnknownStatus: Resource                                                              |
|                       | failed - Unknown status FAILED due to "Resource CREATE                                                               |
|                       | failed: StackValidationFailed: Property error :                                                                      |
|                       | master_instance: networks Property error : networks: 0                                                               |
|                       | Property error : 0: port Multiple port matches found                                                                 |
|                       | for name '', use an ID to be more specific."

Looking at the nova resource template, I see that the right array has been passed to both instances:

heat_template_version: '2013-05-23'
resources:
  '0':
    properties:
      ...
      private_ips: [10.40.50.157, 10.40.50.156]
    type: Lib::MASTER::Master
  '1':
    properties:
      ...
      indx: '1'
      key: lab_admin
      private_ips: [10.40.50.157, 10.40.50.156]
    type: Lib::MASTER::Master

Also tried json type, in nova stack, while defining the "outputs" Section of GetIp as "get_attr: [ip_instance, fixed_ips]", and attempted to access instance's IP's via "port: { get_param: [ private_ips,ip_address, indx ] }" to no avail.
Any thoughts?
Cheers,

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2015-07-06 18:15:25 -0600

asalkeld gravatar image

It might be that you version of heat does not support selecting within the get_param. Try using "Fn::Select" on the result and see how that goes.

http://docs.openstack.org/developer/h...

edit flag offensive delete link more

Comments

Thank you for earlier support in IRC. Got it to work by changing from get_attr to get_resource in Neutron nested stack and using { "Fn::Select" : [ { get_param: indx }, { get_param: [private_ips] } ] }, in nova stack

Nastooh gravatar imageNastooh ( 2015-07-06 18:35:23 -0600 )edit
0

answered 2015-07-06 19:14:31 -0600

Steve Baker gravatar image

Its not clear that you have a requirement to have ports and servers in separate resource groups - can you describe why you want to do this. I would recommend putting the port resource directly inside Lib::MASTER::Master.

edit flag offensive delete link more

Comments

1

Motivation is to have a "class" that I can instantiate with different parameters, in this case number of requested IP. This would allow me roll out different number of masters and slaves, using the same code.

Nastooh gravatar imageNastooh ( 2015-07-06 20:41:51 -0600 )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: 2015-07-06 15:34:39 -0600

Seen: 3,129 times

Last updated: Jul 06 '15