How to add multiple networks to application

Asked by Dave Johnston

I am trying to find a way to add multiple networks to a Murano application.
All the examples so far appear to create virtual machines with a single network interface.

i.e. in a heat template I would define this:

management_port
type: OS::Neutron::Port
    properties:
      network: management
      security_groups:
        - tenant_securitygroup
service_port
type: OS::Neutron::Port
    properties:
      network: service
      security_groups:
        - tenant_securitygroup

server:
    type: OS::Nova::Server
    properties:
      networks:
        - port: { get_resource: management_port }
        - port: { get_resource: service_port }

Some of the app UI contain the following section:

    networks:
      useEnvironmentNetwork: $.instanceConfiguration.network[0]=null
      useFlatNetwork: false
      customNetworks: switch($.instanceConfiguration.network[0], $=null=>list(), $!=null=>$customJoinNet)

But there is no indication of how to create more than one network interface in a application.

Is this possible or should an enhancement be raised ?

Question information

Language:
English Edit question
Status:
Solved
For:
Murano Edit question
Assignee:
No assignee Edit question
Solved by:
Dave Johnston
Solved:
Last query:
Last reply:
Revision history for this message
Stan Lagun (slagun) said :
#1

It is possible.

Actually if you take a look at the code you paste

networks:
      useEnvironmentNetwork: $.instanceConfiguration.network[0]=null
      useFlatNetwork: false
      customNetworks: switch($.instanceConfiguration.network[0], $=null=>list(), $!=null=>$customJoinNet)

(I know it a little bit ugly but there's a good reason for that)

and see how networks property is declared in Instance class https://github.com/openstack/murano/blob/master/meta/io.murano/Classes/resources/Instance.yaml#L45-L50
you will find that customNetworks is a list rather than a scalar

expression switch($.instanceConfiguration.network[0], $=null=>list(), $!=null=>$customJoinNet) returns empty list (list()) if $.instanceConfiguration.network[0] is null or a list with a single item $customJoinNet which is usually defined in UI.yaml above that code.

So if instead I add 2 network selection controls (network1 and network2) and have UI.yaml code that looks like:

Templates:
  customJoinNet1:
    ?:
        type: io.murano.resources.ExistingNeutronNetwork
      internalNetworkName: $.instanceConfiguration.network1[0]
      internalSubnetworkName: $.instanceConfiguration.network1[1]

  customJoinNet2:
    ?:
        type: io.murano.resources.ExistingNeutronNetwork
      internalNetworkName: $.instanceConfiguration.network2[0]
      internalSubnetworkName: $.instanceConfiguration.network2[1]

...

networks:
      useEnvironmentNetwork: $.instanceConfiguration.network1[0]=null and $.instanceConfiguration.network2[0]=null
      useFlatNetwork: false
      customNetworks: list(switch($.instanceConfiguration.network1[0], $=null=>null, $!=null=>$customJoinNet1), switch($.instanceConfiguration.network2[0], $=null=>null, $!=null=>$customJoinNet2)).where($ != null)

you will get several elements in 'customNetworks' field (those, who have $.instanceConfiguration.networkX[0] != null).
Note, that I changed customJoinNet1/customJoinNet2 type from list to dictionary be removing the dash because we don't want to end up having list of single-element lists.

There's going to be a more convenient way to do that in the future but that's what can be done right now.

Revision history for this message
Dave Johnston (dave-johnston) said :
#2

Excelent That works exactly as described.