Refactor ml2 template

Removes unnecessary if blocks that make logic hard to read.

Change-Id: Ibffee34e26aace3008047a86077cf665f2844f64
Closes-Bug: #1423235
This commit is contained in:
Hugh Saunders 2015-02-18 16:05:05 +00:00
parent 73afafbff4
commit 6b7e47822b

View File

@ -1,4 +1,7 @@
# {{ ansible_managed }} # {{ ansible_managed }}
{%- macro append(target_list, item) %}
{%- set _ = target_list.append(item) %}
{%- endmacro %}
{%- set network_vlan_ranges = [] %} {%- set network_vlan_ranges = [] %}
{%- set network_vxlan_ranges = [] %} {%- set network_vxlan_ranges = [] %}
@ -9,46 +12,45 @@
{%- for net in provider_networks %} {%- for net in provider_networks %}
{%- if net.network.type == "vlan" %} {%- if net.network.type == "vlan" %}
{%- if "vlan" not in network_types %} {%- if "vlan" not in network_types %}
{%- if network_types.append("vlan") %}{%- endif %} {{ append(network_types, "vlan") }}
{%- endif %} {%- endif %}
{%- set vlan_pair = [] %} {%- set vlan_pair = [] %}
{%- if vlan_pair.append(net.network.net_name) %}{%- endif %} {{ append(vlan_pair, net.network.net_name) }}
{%- if vlan_pair.append(net.network.range) %}{%- endif %} {{ append(vlan_pair, net.network.range) }}
{%- if vlan_pair|join(':') not in network_vlan_ranges%} {%- if vlan_pair|join(':') not in network_vlan_ranges%}
{%- if network_vlan_ranges.append(vlan_pair|join(':')) %}{%- endif %} {{ append(network_vlan_ranges, vlan_pair|join(':')) }}
{%- endif %} {%- endif %}
{%- elif net.network.type == "vxlan" %} {%- elif net.network.type == "vxlan" %}
{%- if "vxlan" not in network_types %} {%- if "vxlan" not in network_types %}
{%- if network_types.append("vxlan") %}{%- endif %} {{ append(network_types, "vxlan") }}
{%- endif %} {%- endif %}
{%- if net.network.range not in network_vxlan_ranges %} {%- if net.network.range not in network_vxlan_ranges %}
{%- if network_vxlan_ranges.append(net.network.range) %}{%- endif %} {{ append(network_vxlan_ranges, net.network.range) }}
{%- endif %} {%- endif %}
{%- elif net.network.type == "flat" %} {%- elif net.network.type == "flat" %}
{%- if "flat" not in network_types %} {%- if "flat" not in network_types %}
{%- if network_types.append("flat") %}{%- endif %} {{ append(network_types, "flat") }}
{%- endif %} {%- endif %}
{%- if net.network.net_name not in network_flat_networks %} {%- if net.network.net_name not in network_flat_networks %}
{%- if network_flat_networks.append(net.network.net_name) %}{%- endif %} {{ append(network_flat_networks, net.network.net_name) }}
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
{% if net.network.type != 'raw' and net.network.type != 'vxlan' %} {% if net.network.type != 'raw' and net.network.type != 'vxlan' %}
{%- set map_pair = [] %} {%- set map_pair = [] %}
{%- if 'net_name' in net.network %} {%- if 'net_name' in net.network %}
{%- if map_pair.append(net.network.net_name) %}{%- endif %} {{ append(map_pair, net.network.net_name) }}
{%- endif %} {%- endif %}
{%- if is_metal == true or is_metal == "True" %} {%- if is_metal == true or is_metal == "True" %}
{%- if net.network.host_bind_override is defined %} {%- if net.network.host_bind_override is defined %}
{%- if map_pair.append(net.network.host_bind_override) %}{%- endif %} {{ append(map_pair, net.network.host_bind_override) }}
{%- else %} {%- else %}
{%- if map_pair.append(net.network.container_bridge) %}{%- endif %} {{ append(map_pair, net.network.container_bridge) }}
{%- endif %} {%- endif %}
{%- else %} {%- else %}
{%- if map_pair.append(net.network.container_interface) %}{%- endif %} {{ append(map_pair, net.network.container_interface) }}
{%- endif %} {%- endif %}
{%- if map_pair|join(':') not in network_mappings %} {%- if map_pair|join(':') not in network_mappings %}
{%- if network_mappings.append(map_pair|join(':')) %}{%- endif %} {{ append(network_mappings, map_pair|join(':')) }}
{%- endif %} {%- endif %}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}