Ask Your Question
0

Dynamic Network List Creation for OS::Server::Create

asked 2019-04-02 13:18:01 -0500

Axiom gravatar image

Hello, I am working on solving an issue that seems fairly simple yet I am unable to figure it out. I'm hoping that someone who has done this before could share some wisdom! The idea is to provide a comma separated list of network names as an input parameter and based on this list of names, create a network port for each network defined. This will basically allow a variable number of virtual NICs inside the VM. I have seen a few examples of this being done (https://ask.openstack.org/en/question/119085/adding-dynamic-network-interfaces-using-heat-template/ (https://ask.openstack.org/en/question...)) but i am not able to get any results. I have come to the conclusion that creating a dynamic list using 'list_join' or like may be my best and most simple option before presenting that list to OS::Server::Create for the VM creation. If anyone is doing this in a better way I am also interested in learning about that.

Here is some of the static code i am testing with. the goal is to make the 'networks' list value to be dynamic :

heat_template_version: 2017-02-24
parameters:

 internal_nets:
  type: comma_delimited_list
  label: Networks
  description: Comma Separated List of Networks

resources:

  TestVM:
    type: OS::Nova::Server
    properties:
      flavor: m1.tiny
      image: cirros
      *networks: [{"network": "public","port_extra_properties": {"port_security_enabled": false}},{"network": "dmz","port_extra_properties": {"port_security_enabled": false}}]*

For those who may have tried this before, does it make sense to create some form of loop to list_join each network defined in the internal_nets parameter and present that to the 'networks' parameter in TestVM?

I would imagine looping through all the provided networks and creating one long list would look something like this:

repeat:
      for_each:
        <%network%>: { get_param: internal_nets }
      template:
        list_join: [','<%network%>, "port_extra_properties": {"port_security_enabled": false}}]

Any help, suggestions or direction would be greatly appreciated, thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-04-03 10:50:46 -0500

Axiom gravatar image

I managed to solve this issue today and I want to post it for anyone who is looking to do the same or similar.

NOTE: There are some modifications from my original question.I'm now using subnet UUIDs, and not network, or subnet names.

This example template will take a comma separated input parameter of any subnet UUIDs I want to attach an interface to, and loop through them to create a port attached to the VM instance. In this example I am attaching 5 network ports to my Cirros image, each with port security disabled (no security group).

'internal_nets' input parameter (test input data)

a6c4eb4c-ecaa-4b03-bcb3-7012ec35c5b0,98b3aad4-9a4d-489e-94a6-90a0bdd6e75a,708bfeae-187e-4a85-9a1b-19b3b00c0036,839cb1e1-f429-4bf6-966a-ecefee0819a4,57fa3933-67e3-41ad-8197-eb987a37bb5f

Heat Template

heat_template_version: 2017-02-24
parameters:

    internal_nets:
      type: comma_delimited_list
      label: Subnet UUIDs
      description: Comma Separated List of Subnet UUIDs

    resources:

      TestVM:
        type: OS::Nova::Server
        properties:
          flavor: m1.tiny
          image: cirros
          config_drive: true
          networks:
            repeat:
              for_each:
                <%subnet%>: { get_param: internal_nets }
              template:
                subnet: <%subnet%>
                port_extra_properties:
                  port_security_enabled: false
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: 2019-04-02 13:18:01 -0500

Seen: 26 times

Last updated: Apr 02