Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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/) 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.