From 59c5e23c54d09e32e4197eb9ddcd8d6459c1e80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Thu, 21 Mar 2019 10:02:25 +0100 Subject: [PATCH] Jinja automation for %network%NetworkVlanId Per-subnet vlan id parameters are already rendered in network-environment.yaml. This change uses networks data and roles data so that per-subnet vlan id param is used when passing the relevant NetworkVlanId data to nic-config templates. By using the generic %network%NetworkVlanId (no subnet suffix) in nic-config templates instead of %network%NetworkVlanId_%subnet%, this allow homogeneous computes in multiple sites to use the same nic-config template. Also use type: number for all vlan parameters. Closes-Bug: #1821043 Change-Id: Id8e76ae7c41a562f5c47d911c42aa18001c11be1 --- .../net-config-multinode-os-net-config.yaml | 22 +++++++++++ ci/common/net-config-multinode.yaml | 22 +++++++++++ ci/common/net-config-simple-bridge.yaml | 22 +++++++++++ .../2-linux-bonds-vlans/role.role.j2.yaml | 2 +- .../controller-no-external.j2.yaml | 2 +- .../bond-with-vlans/controller-v6.j2.yaml | 2 +- .../config/bond-with-vlans/role.role.j2.yaml | 2 +- .../config/multiple-nics/compute-dvr.j2.yaml | 2 +- .../multiple-nics/controller-v6.j2.yaml | 2 +- .../config/multiple-nics/role.role.j2.yaml | 2 +- .../controller-v6.j2.yaml | 2 +- .../role.role.j2.yaml | 2 +- .../controller-no-external.j2.yaml | 2 +- .../single-nic-vlans/controller-v6.j2.yaml | 2 +- .../config/single-nic-vlans/role.role.j2.yaml | 2 +- network/network.j2 | 6 +-- puppet/role.role.j2.yaml | 37 +++++++++++++++++-- 17 files changed, 115 insertions(+), 18 deletions(-) diff --git a/ci/common/net-config-multinode-os-net-config.yaml b/ci/common/net-config-multinode-os-net-config.yaml index 8cdcf584b0..b918ab42af 100644 --- a/ci/common/net-config-multinode-os-net-config.yaml +++ b/ci/common/net-config-multinode-os-net-config.yaml @@ -174,6 +174,28 @@ parameters: description: The IP address of the EC2 metadata server. (The parameter is automatically resolved from the ctlplane subnet's host_routes attribute.) type: string + # NOTE(hjensas): We need these because the default network_data.yaml define + # vlan for all networks. + ExternalNetworkVlanID: + default: 10 + description: Vlan ID for the external network traffic. + type: number + InternalApiNetworkVlanID: + default: 20 + description: Vlan ID for the internal_api network traffic. + type: number + StorageNetworkVlanID: + default: 30 + description: Vlan ID for the storage network traffic. + type: number + StorageMgmtNetworkVlanID: + default: 40 + description: Vlan ID for the storage_mgmt network traffic. + type: number + TenantNetworkVlanID: + default: 50 + description: Vlan ID for the tenant network traffic. + type: number resources: diff --git a/ci/common/net-config-multinode.yaml b/ci/common/net-config-multinode.yaml index d11944ffa5..e6f2f1398f 100644 --- a/ci/common/net-config-multinode.yaml +++ b/ci/common/net-config-multinode.yaml @@ -162,6 +162,28 @@ parameters: description: The IP address of the EC2 metadata server. (The parameter is automatically resolved from the ctlplane subnet's host_routes attribute.) type: string + # NOTE(hjensas): We need these because the default network_data.yaml define + # vlan for all networks. + ExternalNetworkVlanID: + default: 10 + description: Vlan ID for the external network traffic. + type: number + InternalApiNetworkVlanID: + default: 20 + description: Vlan ID for the internal_api network traffic. + type: number + StorageNetworkVlanID: + default: 30 + description: Vlan ID for the storage network traffic. + type: number + StorageMgmtNetworkVlanID: + default: 40 + description: Vlan ID for the storage_mgmt network traffic. + type: number + TenantNetworkVlanID: + default: 50 + description: Vlan ID for the tenant network traffic. + type: number resources: OsNetConfigImpl: diff --git a/ci/common/net-config-simple-bridge.yaml b/ci/common/net-config-simple-bridge.yaml index 79ae74f628..0704ef6aa6 100644 --- a/ci/common/net-config-simple-bridge.yaml +++ b/ci/common/net-config-simple-bridge.yaml @@ -159,6 +159,28 @@ parameters: description: The IP address of the EC2 metadata server. (The parameter is automatically resolved from the ctlplane subnet's host_routes attribute.) type: string + # NOTE(hjensas): We need these because the default network_data.yaml define + # vlan for all networks. + ExternalNetworkVlanID: + default: 10 + description: Vlan ID for the external network traffic. + type: number + InternalApiNetworkVlanID: + default: 20 + description: Vlan ID for the internal_api network traffic. + type: number + StorageNetworkVlanID: + default: 30 + description: Vlan ID for the storage network traffic. + type: number + StorageMgmtNetworkVlanID: + default: 40 + description: Vlan ID for the storage_mgmt network traffic. + type: number + TenantNetworkVlanID: + default: 50 + description: Vlan ID for the tenant network traffic. + type: number resources: OsNetConfigImpl: diff --git a/network/config/2-linux-bonds-vlans/role.role.j2.yaml b/network/config/2-linux-bonds-vlans/role.role.j2.yaml index 4155e56023..08ee850857 100644 --- a/network/config/2-linux-bonds-vlans/role.role.j2.yaml +++ b/network/config/2-linux-bonds-vlans/role.role.j2.yaml @@ -50,7 +50,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/bond-with-vlans/controller-no-external.j2.yaml b/network/config/bond-with-vlans/controller-no-external.j2.yaml index 8dd8950fd2..0d8e51158d 100644 --- a/network/config/bond-with-vlans/controller-no-external.j2.yaml +++ b/network/config/bond-with-vlans/controller-no-external.j2.yaml @@ -41,7 +41,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/bond-with-vlans/controller-v6.j2.yaml b/network/config/bond-with-vlans/controller-v6.j2.yaml index 44a77ad29b..a5b029564b 100644 --- a/network/config/bond-with-vlans/controller-v6.j2.yaml +++ b/network/config/bond-with-vlans/controller-v6.j2.yaml @@ -39,7 +39,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/bond-with-vlans/role.role.j2.yaml b/network/config/bond-with-vlans/role.role.j2.yaml index 1510b18668..4075a15f97 100644 --- a/network/config/bond-with-vlans/role.role.j2.yaml +++ b/network/config/bond-with-vlans/role.role.j2.yaml @@ -48,7 +48,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/multiple-nics/compute-dvr.j2.yaml b/network/config/multiple-nics/compute-dvr.j2.yaml index 8819e19de9..07a59dba31 100644 --- a/network/config/multiple-nics/compute-dvr.j2.yaml +++ b/network/config/multiple-nics/compute-dvr.j2.yaml @@ -39,7 +39,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan|default("")}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/multiple-nics/controller-v6.j2.yaml b/network/config/multiple-nics/controller-v6.j2.yaml index 7bf39f2c16..7ffd022994 100644 --- a/network/config/multiple-nics/controller-v6.j2.yaml +++ b/network/config/multiple-nics/controller-v6.j2.yaml @@ -38,7 +38,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan|default("")}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/multiple-nics/role.role.j2.yaml b/network/config/multiple-nics/role.role.j2.yaml index 908f2a397b..98519a1937 100644 --- a/network/config/multiple-nics/role.role.j2.yaml +++ b/network/config/multiple-nics/role.role.j2.yaml @@ -49,7 +49,7 @@ parameters: type: string {%- if network.vlan %} {{network.name}}NetworkVlanID: - default: {{network.vlan|default("")}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {%- endif %} diff --git a/network/config/single-nic-linux-bridge-vlans/controller-v6.j2.yaml b/network/config/single-nic-linux-bridge-vlans/controller-v6.j2.yaml index ea97af006e..867443bc52 100644 --- a/network/config/single-nic-linux-bridge-vlans/controller-v6.j2.yaml +++ b/network/config/single-nic-linux-bridge-vlans/controller-v6.j2.yaml @@ -38,7 +38,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/single-nic-linux-bridge-vlans/role.role.j2.yaml b/network/config/single-nic-linux-bridge-vlans/role.role.j2.yaml index d19d423643..4638798434 100644 --- a/network/config/single-nic-linux-bridge-vlans/role.role.j2.yaml +++ b/network/config/single-nic-linux-bridge-vlans/role.role.j2.yaml @@ -48,7 +48,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/single-nic-vlans/controller-no-external.j2.yaml b/network/config/single-nic-vlans/controller-no-external.j2.yaml index e745040cde..03152346d5 100644 --- a/network/config/single-nic-vlans/controller-no-external.j2.yaml +++ b/network/config/single-nic-vlans/controller-no-external.j2.yaml @@ -41,7 +41,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/single-nic-vlans/controller-v6.j2.yaml b/network/config/single-nic-vlans/controller-v6.j2.yaml index cc8f1340ec..174ef39167 100644 --- a/network/config/single-nic-vlans/controller-v6.j2.yaml +++ b/network/config/single-nic-vlans/controller-v6.j2.yaml @@ -38,7 +38,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/config/single-nic-vlans/role.role.j2.yaml b/network/config/single-nic-vlans/role.role.j2.yaml index 76b1de9a17..5bd49233bd 100644 --- a/network/config/single-nic-vlans/role.role.j2.yaml +++ b/network/config/single-nic-vlans/role.role.j2.yaml @@ -48,7 +48,7 @@ parameters: description: IP address/subnet on the {{network.name_lower}} network type: string {{network.name}}NetworkVlanID: - default: {{network.vlan}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {{network.name}}Mtu: diff --git a/network/network.j2 b/network/network.j2 index 0c8136267d..78a77b7105 100644 --- a/network/network.j2 +++ b/network/network.j2 @@ -67,7 +67,7 @@ parameters: type: string {%- if network.vlan %} {{network.name}}NetworkVlanID: - default: {{network.vlan|default('')}} + default: {{network.vlan|default(1)}} description: Vlan ID for the {{network.name_lower}} network traffic. type: number {%- endif %} @@ -114,10 +114,10 @@ parameters: default route for the {{network.name_lower}} network's {{subnet}} subnet. type: string {{network.name}}NetworkVlanID_{{subnet}}: - default: {{network.subnets[subnet]['vlan']|default('')}} + default: {{network.subnets[subnet]['vlan']|default(1)}} description: | Vlan ID for the {{network.name_lower}} network's {{subnet}} subnet. - type: string + type: number {{network.name}}Routes_{{subnet}}: default: {{network.subnets[subnet]['routes']|default([])}} description: > diff --git a/puppet/role.role.j2.yaml b/puppet/role.role.j2.yaml index eec4d9e1dc..d42c955d3f 100644 --- a/puppet/role.role.j2.yaml +++ b/puppet/role.role.j2.yaml @@ -269,8 +269,7 @@ parameters: If not set the nameservers configured in the ctlplane subnet's dns_nameservers attribute will be used. type: comma_delimited_list -{%- 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}}InterfaceRoutes: default: [] description: > @@ -279,7 +278,28 @@ parameters: Unless the default is changed, the parameter is automatically resolved from the subnet host_routes attribute. type: json -{%- endif %} + {%- if role.networks is mapping %} + {%- set _subnets = network.get('subnets') %} + {%- set _role_net_subnet = role.networks[network.name].get('subnet') %} + {%- if _subnets and _role_net_subnet and _role_net_subnet in _subnets %} + {{network.name}}NetworkVlanID_{{_role_net_subnet}}: + default: {{_role_net_subnet.vlan|default(1)}} + description: > + Vlan ID for the {{network.name_lower}} network traffic for subnet + {{_role_net_subnet}}. + type: number + {%- elif network.vlan|default(false) %} + {{network.name}}NetworkVlanID: + default: {{network.vlan|default(1)}} + description: Vlan ID for the {{network.name_lower}} network traffic. + type: number + {%- endif %} + {%- elif network.vlan|default(false) %} + {{network.name}}NetworkVlanID: + default: {{network.vlan|default(1)}} + description: Vlan ID for the {{network.name_lower}} network traffic. + type: number + {%- endif %} {%- endfor %} ServerDeletionPolicy: @@ -545,6 +565,17 @@ resources: {%- if network.name in role.default_route_networks %} {{network.name}}InterfaceDefaultRoute: {get_attr: [{{network.name}}Port, gateway_ip]} {%- endif %} + {%- if role.networks is mapping %} + {%- set _subnets = network.get('subnets') %} + {%- set _role_net_subnet = role.networks[network.name].get('subnet') %} + {%- if _subnets and _role_net_subnet and _role_net_subnet in _subnets %} + {{network.name}}NetworkVlanID: {get_param: {{network.name}}NetworkVlanID_{{_role_net_subnet}}} + {%- elif network.vlan|default(false) %} + {{network.name}}NetworkVlanID: {get_param: {{network.name}}NetworkVlanID} + {%- endif %} + {%- elif network.vlan|default(false) %} + {{network.name}}NetworkVlanID: {get_param: {{network.name}}NetworkVlanID} + {%- endif %} {%- endif %} {%- endfor %}