Ask Your Question
1

How to display child attributes from parent yaml files? Without modifying child.yaml

asked 2017-03-28 02:34:09 -0500

udayutkarsh gravatar image

updated 2017-03-28 04:43:17 -0500

This is a followup question of https://ask.openstack.org/en/question...

 I have a child yaml file named child.yaml::
 ======================================

    heat_template_version: 2015-04-30

    description: Simple template to deploy a single compute instance

    parameters:
      key_name:
        type: string
      image_id:
        type: string
      flavor_id:
        type: string
      network_id:
        type: string
      vm_name:
        type: string

    resources:
      my_instance:
        type: OS::Nova::Server
        properties:
          name: { get_param: vm_name }
          key_name: { get_param: key_name }
          image: { get_param: image_id }
          flavor: { get_param: flavor_id }
          networks:
           - network: { get_param: network_id }

    The parent file which looks like as under (parent.yaml )::
    =====================================================

    heat_template_version: 2015-04-30

    description: Simple template to deploy a single compute instance

    parameters:

      key_name:
        type: string
        label: Key Name
        description: Name of key-pair to be used for compute instance
        default: keypair-01

      image_id:
        type: string
        label: Image ID
        description: Image to be used for compute instance
        default: cirros

      flavor_id:
        type: string
        label: Instance Type
        description: Type of instance (flavor) to be used
        default: m1.tiny

      network_id:
        type: string
        label: Instance Type
        description: Type of instance (flavor) to be used
        default: private

      vm_name1:
        type: string
        default: vm1

      vm_name2:
        type: string
        default: vm2    

    resources:
      my_instance1:
        type: ./child.yaml
        properties:
          vm_name: {get_param: vm_name1 }
          key_name: { get_param: key_name }
          image_id: { get_param: image_id }
          flavor_id: { get_param: flavor_id }
          network_id: { get_param: network_id }

     my_instance2:
         type: ./child.yaml
         properties:
            vm_name: {get_param: vm_name2 }
            key_name: { get_param: key_name }
            image_id: { get_param: image_id }
            flavor_id: { get_param: flavor_id }
            network_id: { get_param: network_id }


Now i need to create a stack from parent.yaml file (which invokes child.yaml two times in order to create two vms) to display ip addresses (or any other attributes) of both VMs (vm1 and vm2). 

Is there any way to modify only parent.yaml file without touching child.yaml and still display the its attributes from parent?

I have been following section "Get access to nested attributes" on this link https://docs.openstack.org/developer/heat/template_guide/composition.html
 but could not crack it.

heat_template_version: 2015-04-30

resources:
  my_server:
    type: my_nova.yaml

outputs:
  test_out:
    value: {get_attr: my_server, resource.server, first_address}

Here resource.server has value "null"

                                                                                                                    |
|                       |   {                                                                                                                  |
|                       |     "output_value": {                                                                                                |
|                       |       "get_attr": "servers",                                                                                         |
|                       |       "resource.server": null                                                                                        |
|                       |     },                                                                                                               |
|                       |     "output_key": "server_ips",                                                                                      |
|                       |     "description": "From calling ip adress of server"                                                                |
|                       |   }
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-28 05:01:40 -0500

udayutkarsh gravatar image

updated 2017-03-28 05:02:05 -0500

Hi I have found the answer I guess . it should be as follows:

In parent.yaml
============

outputs:
  server_ips:
    description: From calling ip adress of server
    value: { get_attr:  [ servers, resource.my_instance, first_address ] }
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: 2017-03-28 02:34:09 -0500

Seen: 104 times

Last updated: Mar 28 '17