From 5b3878580a9768be7c7c39d3062f567eb5e13767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Mon, 21 Sep 2020 12:56:50 +0200 Subject: [PATCH] Add attr of networks and subnets to Networks resource In the Networks resource tempaltes add the full resource attributes to net_attributes_map. Use the attributes to build per-role GroupVars. Change-Id: I603521bd00dc100e03c765c25503b5e01f3383e4 --- network/network.j2 | 10 ++++++++++ network/networks.j2.yaml | 10 +++++++++- overcloud.j2.yaml | 27 +++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/network/network.j2 b/network/network.j2 index f8115fef63..d4d7ee764d 100644 --- a/network/network.j2 +++ b/network/network.j2 @@ -284,4 +284,14 @@ outputs: {%- else %} - "{{network.subnets[subnet]['ip_subnet']|default("")}}" {%- endif %} +{%- endfor %} + network_attrs: + description: {{network.name}} network's attributes + value: {get_attr: [{{network.name}}Network]} + subnet_attrs: + description: Map of attributes for subnets in the {{network.name}} network + value: + {{network.name_lower}}_subnet: {get_attr: [{{network.name}}Subnet]} +{%- for subnet in network.subnets|default({}) if network.subnets[subnet].enabled|default(true) %} + {{subnet}}: {get_attr: [{{network.name}}Subnet_{{subnet}}]} {%- endfor %} diff --git a/network/networks.j2.yaml b/network/networks.j2.yaml index c689c7c817..fcacf8eb2b 100644 --- a/network/networks.j2.yaml +++ b/network/networks.j2.yaml @@ -39,5 +39,13 @@ outputs: value: {%- for network in networks if network.enabled|default(true) %} {%- set network_name = network.compat_name|default(network.name) %} - {{network.name_lower}}: {get_attr: [{{network_name}}Network, ip_version]} + {{network.name_lower}}: {get_attr: [{{network_name}}Network, ip_version]} + {%- endfor %} + net_attributes_map: + value: + {%- for network in networks if network.enabled|default(true) %} + {%- set network_name = network.compat_name|default(network.name) %} + {{network.name_lower}}: + network: {get_attr: [{{network_name}}Network, network_attrs]} + subnets: {get_attr: [{{network_name}}Network, subnet_attrs]} {%- endfor %} diff --git a/overcloud.j2.yaml b/overcloud.j2.yaml index 0a06f5e5b5..c806997965 100644 --- a/overcloud.j2.yaml +++ b/overcloud.j2.yaml @@ -919,14 +919,33 @@ resources: type: OS::Heat::Value properties: value: + {%- for network in networks if network.enabled|default(true) and network.name in role.networks|default([]) %} + {{network.name_lower}}_mtu: {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, network, mtu]} + {%- if role.networks is mapping %} + {{network.name_lower}}_gateway_ip: {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, subnets, {{role.networks[network.name]['subnet']}}, gateway_ip]} + {{network.name_lower}}_host_routes: {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, subnets, {{role.networks[network.name]['subnet']}}, host_routes]} + {{network.name_lower}}_cidr: {str_split: ['/', {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, subnets, {{role.networks[network.name]['subnet']}}, cidr]}, 1]} + {%- else %} + {{network.name_lower}}_gateway_ip: {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, subnets, {{network.name_lower}}_subnet, gateway_ip]} + {{network.name_lower}}_host_routes: {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, subnets, {{network.name_lower}}_subnet, host_routes]} + {{network.name_lower}}_cidr: {str_split: ['/', {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, subnets, {{network.name_lower}}_subnet, cidr]}, 1]} + {%- endif %} + {%- endfor %} + network_cidrs: + {%- for network in networks if network.enabled|default(true) and network.name in role.networks|default([]) %} + {%- if role.networks is mapping %} + {{network.name}}_cidr: {str_split: ['/', {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, subnets, {{role.networks[network.name]['subnet']}}, cidr]}, 1]} + {%- else %} + {{network.name}}_cidr: {str_split: ['/', {get_attr: [Networks, net_attributes_map, {{network.name_lower}}, subnets, {{network.name_lower}}_subnet, cidr]}, 1]} + {%- endif %} + {%- endfor %} role_networks: - {%- for network in networks %} - {%- if network.enabled|default(true) and network.name in role.networks|default([]) %} + {%- for network in networks if network.enabled|default(true) and network.name in role.networks|default([]) %} - {{network.name}} - {% endif %} - {% endfor %} + {%- endfor %} service_metadata_settings: {get_attr: [{{role.name}}ServiceChainRoleData, value, service_metadata_settings]} + {% endfor %} ControlVirtualIP: