Iterate once in network-environment.yaml

This replaced multiple for loops with a single loop.
This changes the ordering in the rendered file to have
one section per network, instead of one section per
perameter such as VLAN, AllocationPools.

It also reduces the use of jinja conditionals. This
results in some duplicated comment strings in the
jinja template.

This is a micro optimization, but this makes sense
as a follow on will add the possibility to add
multiple subnets on each network in network_data.yaml.
I.e we avoid additional nested loops over the subnets.

Related: blueprint tripleo-routed-networks-templates
Change-Id: I0f11acaf7c25ff5d240db1daae2dc2b051c0a3b2
This commit is contained in:
Harald Jensås 2018-07-12 11:01:55 +02:00
parent 445d45384e
commit 4564109600
2 changed files with 41 additions and 51 deletions

View File

@ -21,37 +21,31 @@ parameter_defaults:
# Gateway router for the provisioning network (or Undercloud IP)
ControlPlaneDefaultRoute: 192.168.24.254
EC2MetadataIp: 192.168.24.1 # Generally the IP of the Undercloud
{% for network in networks if network.enabled|default(true) %}
{%- if network.name != 'Tenant' %}
# Customize the IP subnets to match the local environment
{%- for network in networks if network.enabled|default(true) %}
{%- if network.name != 'Tenant' %}
{{network.name}}NetCidr: '{{network.ipv6_subnet}}'
{%- else %}
# Tenant tunneling network is IPv4 until IPv6 is fully supported
{{network.name}}NetCidr: '{{network.ip_subnet}}'
{%- endif %}
{%- endfor %}
# Customize the VLAN IDs to match the local environment
{%- for network in networks if network.enabled|default(true) %}
{%- if network.vlan is defined %}
{{network.name}}NetworkVlanID: {{network.vlan}}
{%- endif %}
{%- endfor %}
# Customize the IP ranges on each network to use for static IPs and VIPs
{%- for network in networks if network.enabled|default(true) %}
{%- if network.name == 'External' %}
# Customize the IP range to use for static IPs and VIPs
{%- if network.name == 'External' %}
# Leave room if the external network is also used for floating IPs
{%- endif %}
{%- if network.name != 'Tenant' %}
{%- endif %}
{{network.name}}AllocationPools: {{network.ipv6_allocation_pools}}
{%- else %}
# Tenant tunneling network should be IPv4
{{network.name}}AllocationPools: {{network.ip_allocation_pools}}
{%- endif %}
{%- endfor %}
# Gateway routers for routable networks
{%- for network in networks if network.enabled|default(true) and network.gateway_ipv6|default(false) %}
{%- else %}
# Tenant tunneling network is IPv4 until IPv6 is fully supported
# Customize the IP subnets to match the local environment
{{network.name}}NetCidr: '{{network.ip_subnet}}'
# Customize the IP range to use for static IPs and VIPs
{{network.name}}AllocationPools: {{network.allocation_pools}}
{%- endif %}
{%- if network.enabled|default(true) and network.gateway_ipv6|default(false) %}
# Gateway router for routable networks
{{network.name}}InterfaceDefaultRoute: '{{network.gateway_ipv6}}'
{%- endfor %}
{%- endif %}
{%- if network.vlan is defined %}
# Customize the VLAN ID to match the local environment
{{network.name}}NetworkVlanID: {{network.vlan}}
{%- endif %}
{% endfor %}
{#- FIXME: These global parameters should be defined in a YAML file, e.g. network_data.yaml. #}
# Define the DNS servers (maximum 2) for the overcloud nodes
DnsServers: ["8.8.8.8","8.8.4.4"]

View File

@ -17,38 +17,34 @@ parameter_defaults:
# Gateway router for the provisioning network (or Undercloud IP)
ControlPlaneDefaultRoute: 192.168.24.254
EC2MetadataIp: 192.168.24.1 # Generally the IP of the Undercloud
# Customize the IP subnets to match the local environment
{%- for network in networks if network.enabled|default(true) %}
{%- if network.ipv6|default(false) %}
{% for network in networks if network.enabled|default(true) %}
# Customize the IP subnet to match the local environment
{%- if network.ipv6|default(false) %}
{{network.name}}NetCidr: '{{network.ipv6_subnet}}'
{%- else %}
{%- else %}
{{network.name}}NetCidr: '{{network.ip_subnet}}'
{%- endif %}
{%- endfor %}
# Customize the VLAN IDs to match the local environment
{%- for network in networks if network.enabled|default(true) %}
{%- if network.vlan is defined %}
{{network.name}}NetworkVlanID: {{network.vlan}}
{%- endif %}
{%- endfor %}
{%- for network in networks if network.enabled|default(true) %}
{%- if network.name == 'External' %}
{%- endif %}
# Customize the IP range to use for static IPs and VIPs
{%- if network.name == 'External' %}
# Leave room if the external network is also used for floating IPs
{%- endif %}
{%- if network.ipv6|default(false) %}
{%- endif %}
{%- if network.ipv6|default(false) %}
{{network.name}}AllocationPools: {{network.ipv6_allocation_pools}}
{%- else %}
{%- else %}
{{network.name}}AllocationPools: {{network.allocation_pools}}
{%- endif %}
{%- endfor %}
# Gateway routers for routable networks
{%- for network in networks if network.enabled|default(true) %}
{%- if network.ipv6|default(false) and network.gateway_ipv6|default(false) %}
{%- endif %}
{%- if network.ipv6|default(false) and network.gateway_ipv6|default(false) %}
# Gateway router for routable networks
{{network.name}}InterfaceDefaultRoute: '{{network.gateway_ipv6}}'
{%- elif network.gateway_ip|default(false) %}
{%- elif network.gateway_ip|default(false) %}
# Gateway router for routable networks
{{network.name}}InterfaceDefaultRoute: '{{network.gateway_ip}}'
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if network.vlan is defined %}
# Customize the VLAN ID to match the local environment
{{network.name}}NetworkVlanID: {{network.vlan}}
{%- endif %}
{% endfor %}
{#- FIXME: These global parameters should be defined in a YAML file, e.g. network_data.yaml. #}
# Define the DNS servers (maximum 2) for the overcloud nodes
DnsServers: ["8.8.8.8","8.8.4.4"]