Ask Your Question
0

Adding dynamic network interfaces using HEAT template

asked 2019-01-21 11:40:11 -0500

Subeesh KK gravatar image

updated 2019-01-23 09:48:34 -0500

HI - Request a help. I need to add dynamic number of network interfaces to an instance via HEAT template. As of now, I have a template which adds one network interface for an instance using OS::Neutron::Port as below.

    #Create a port on the external public network    
        extPort:
            type: OS::Neutron::Port
            properties:
                network: { get_param: extPublicNetwork }
                port_security_enabled: false

# Create a single signaling server
extServer:
    type: OS::Nova::Server
    depends_on: [ extPort ]
    properties:
        image: { get_param: image }
        flavor: { get_param: flavor }
        name:  { get_param: [ vmNames, get_param: index ] }

        networks:
            - port: { get_resource: extPort }

Now I have a requirement that based on the input via the environment file, I need to add that many number of same network interfaces. I have tried like this:

        environment file:
        # Network name is ext-public
        networklist: ext-public,ext-public,ext-public

        Template file:

        # Create a port on the external public network
        extPort:
            type: OS::Neutron::Port
            properties:
                network: { get_param: extPublicNetwork }
                port_security_enabled: false

        # Create a single signaling server
        extServer:
            type: OS::Nova::Server
            depends_on: [ extPort ]
            properties:
                image: { get_param: image }
                flavor: { get_param: flavor }

                networks:
                    repeat:
                        for_each:
                            <%port%>: { get_param: networklist }      
                        template:
                            port: { get_resource: <%port%> }

This code gives the following error:

ERROR: Failed to validate: Failed to validate: resources[0]: The specified reference "<%port%>" (in signalingServer.Properties.networks.repeat.template.port) is incorrect.

How can I make it work to achieve dynamic number of interfaces from a OS::Neutron::Port resource?

Thank You, Subeesh

UPDATE: I have 2 more questions, related. Kindly help:

1) If I create dynamic number of networks, I have a requirement of making a JSON file and provide these interface details in the json and place it in the created instance via user data. Something like:

etho : ip1, eth1 : ip2, eth2 : ip3, .............

How can I do this? Do we have a "loop" in outputs section also? If yes, can I loop through the networks via get_attr and assign to dynamically created variables in the stack output?

2) My requirement is to create multiple interfaces. Among these, can I make 2 interfaces static. And rest of the networks creation based on the user input from environment file ?

Like , etho = ext-net1 (This is known in advance, and hence I can hard-code this)
eth1 = ext-net2 (This is known in advance, and hence I can hard-code this)
eth2 = To be configured based on the network provided by user in environment file
eth3 = To be configured based on the network provided by user in environment file
.....................................................................................................

Sorry for long questions. Any help/direction will be really helpful. Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-01-21 22:08:50 -0500

zaneb gravatar image

Intrinsic functions (like get_resource and repeat) are evaluated from the inside out, so in this case Heat will try to resolve {get_resource: <%port%>}, which obviously fails.

Some options:

  • Don't explicitly create an OS::Neutron::Port, but instead allow OS::Nova::Server to create the ports you need.
  • Generate the template externally to Heat with only the port resources you need and reference only those in the Server network config.
  • Include all potential ports in the template and enable or disable them from the environment with conditionals, then use the if macro to choose to reference them or not in the Server network config.
edit flag offensive delete link more

Comments

Thanks zaneb for the reply. I am using OS:;Nova:Server approach and it is working fine.

Subeesh KK gravatar imageSubeesh KK ( 2019-01-23 01:17:39 -0500 )edit

One more question please: If I dynamically create networks, how to assign these IPs to separate stack output variables? Can I use any loop in the "outputs" section, so that I can assign int1 = <ip1>, int2=<ip2> etc.Basically I wanted to get what IP is assigned to what interface from stack output.

Subeesh KK gravatar imageSubeesh KK ( 2019-01-23 09:12:10 -0500 )edit

Please open a new question, but the short answer is you can use the addresses attribute of the server.

zaneb gravatar imagezaneb ( 2019-01-27 17:49:16 -0500 )edit

Sure. Please check here : https://ask.openstack.org/en/question/119293/circulardependencyexception-accessing-a-property-within-the-resource/

Subeesh KK gravatar imageSubeesh KK ( 2019-01-30 00:17:40 -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: 2019-01-21 11:40:11 -0500

Seen: 46 times

Last updated: Jan 23