a12159eab371d6adfad61d188d5dd7020d574b1a
[pharos.git] / config / installers / fuel / net_map.j2
1 ##############################################################################
2 # Copyright (c) 2018 Mirantis Inc., Enea AB and others.
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
7 ##############################################################################
8 {%- set net = conf.idf.net_config %}
9 {#- NOTE: All nodes sharing a role (e.g. compute) will use the same mapping #}
10
11 {#- Until we support per-node configuration, we only collect data for the
12     first node in each role. Currently, there's no role mapping in PDF/IDF,
13     so we default to controller = first node in PDF, compute = 4th #}
14
15 {#- ctl maps to MCP kvm on baremetal, ctl + gtw etc. on virtual #}
16 {%- set ctl01 = {'idx': 0} %}
17 {%- set cmp001 = {'idx': 3} %}
18
19 {#- net_config v1.0 only supports global network-to-interface-index mapping,
20     which is incovenient for PODs with different computes (e.g. less NICs).
21     This can be worked around by tweaking the NIC definition order in PDF.
22     The same observation applies to vlan tags, at least for now. #}
23
24 {#- Determine interface index for each network #}
25 {%- set idx_mcp = 0 %} {#- mcpcontrol network is hard set on first interface #}
26 {%- set idx_admin = net.admin.interface %}
27 {%- set idx_mgmt = net.mgmt.interface %}
28 {%- set idx_private = net.private.interface %}
29 {%- set idx_public = net.public.interface %}
30
31 {#- VLAN for each network (only untagged 'admin' is supported by MaaS config!) #}
32 {%- set vlan_admin = net.admin.vlan %}
33 {%- set vlan_mgmt = net.mgmt.vlan %}
34 {%- set vlan_private = net.private.vlan %}
35 {%- set vlan_public = net.public.vlan %}
36
37 {#- Physical interface OS name for each network (e.g. em1, enp1s0f1) #}
38 {%- for role in [ctl01, cmp001] %}
39     {%- set node = conf.idf.fuel.network.node[role.idx] %}
40     {%- do role.update({
41         'nic_mcp': node.interfaces[idx_mcp],
42         'nic_admin': node.interfaces[idx_admin],
43         'nic_mgmt': node.interfaces[idx_mgmt],
44         'nic_private': node.interfaces[idx_private],
45         'nic_public': node.interfaces[idx_public],
46         'bus_private': node.busaddr[idx_private]}) %}
47     {#- PCI addresses are only used on computes for DPDK on private net #}
48 {%- endfor %}
49
50 {%- set net_admin = [net.admin.network, net.admin.mask] | join("/") %}
51 {%- set net_mgmt = [net.mgmt.network, net.mgmt.mask] | join("/") %}
52 {%- set net_private = [net.private.network, net.private.mask] | join("/") %}
53 {%- set net_public =  [net.public.network, net.public.mask] | join("/") %}
54 {%- set networks = [net_admin, net_mgmt, net_private, net_public] %}
55
56 {%- if net.public.dns is defined %}
57     {%- set dns_public = net.public.dns %}
58 {%- else %}
59     {%- set dns_public = [ '8.8.8.8', '8.8.4.4' ] %}
60 {%- endif %}
61
62 {%- if net.public.gateway is defined %}
63     {%- set net_public_gw = net.public.gateway %}
64 {%- endif %}
65 {%- if conf.idf.fuel.network.public_pool is defined %}
66     {%- set net_public_pool_start = conf.idf.fuel.network.public_pool.start_ip %}
67     {%- set net_public_pool_end = conf.idf.fuel.network.public_pool.end_ip %}
68 {%- endif %}
69
70 {%- if conf.idf.fuel.maas is defined %}
71     {%- set maas_timeout_comissioning = conf.idf.fuel.maas.timeout_comissioning %}
72     {%- set maas_timeout_deploying = conf.idf.fuel.maas.timeout_deploying %}
73 {%- else %}
74     {%- set maas_timeout_comissioning = 10 %}
75     {%- set maas_timeout_deploying = 15 %}
76 {%- endif %}
77
78 {%- set cmp_nodes = conf.nodes | length - cmp001.idx %}
79
80 {%- set net_admin_hosts = [
81     'opnfv_infra_config_pxe_admin_address',
82     'opnfv_infra_maas_node01_deploy_address',
83     'opnfv_openstack_proxy_node01_pxe_admin_address',
84     'opnfv_openstack_proxy_node02_pxe_admin_address',
85     'opnfv_openstack_gateway_node01_pxe_admin_address',
86     'opnfv_openstack_gateway_node02_pxe_admin_address',
87     'opnfv_openstack_gateway_node03_pxe_admin_address',
88     'opnfv_infra_kvm_node01_pxe_admin_address',
89     'opnfv_infra_kvm_node02_pxe_admin_address',
90     'opnfv_infra_kvm_node03_pxe_admin_address',
91     'opnfv_openstack_database_node01_pxe_admin_address',
92     'opnfv_openstack_database_node02_pxe_admin_address',
93     'opnfv_openstack_database_node03_pxe_admin_address',
94     'opnfv_openstack_message_queue_node01_pxe_admin_address',
95     'opnfv_openstack_message_queue_node02_pxe_admin_address',
96     'opnfv_openstack_message_queue_node03_pxe_admin_address',
97     'opnfv_openstack_telemetry_node01_pxe_admin_address',
98     'opnfv_openstack_telemetry_node02_pxe_admin_address',
99     'opnfv_openstack_telemetry_node03_pxe_admin_address',
100     'opnfv_openstack_control_node01_pxe_admin_address',
101     'opnfv_openstack_control_node02_pxe_admin_address',
102     'opnfv_openstack_control_node03_pxe_admin_address',
103     'opnfv_opendaylight_server_node01_pxe_admin_address',
104     'opnfv_stacklight_monitor_node01_pxe_admin_address',
105     'opnfv_stacklight_monitor_node02_pxe_admin_address',
106     'opnfv_stacklight_monitor_node03_pxe_admin_address',
107     'opnfv_stacklight_log_node01_pxe_admin_address',
108     'opnfv_stacklight_log_node02_pxe_admin_address',
109     'opnfv_stacklight_log_node03_pxe_admin_address',
110     'opnfv_stacklight_telemetry_node01_pxe_admin_address',
111     'opnfv_stacklight_telemetry_node02_pxe_admin_address',
112     'opnfv_stacklight_telemetry_node03_pxe_admin_address'] %}
113
114 {%- set net_mgmt_hosts = [
115     'opnfv_infra_config_address',
116     'opnfv_infra_maas_node01_address',
117     'opnfv_openstack_proxy_control_address',
118     'opnfv_openstack_proxy_node01_control_address',
119     'opnfv_openstack_proxy_node02_control_address',
120     'opnfv_openstack_gateway_node01_address',
121     'opnfv_openstack_gateway_node02_address',
122     'opnfv_openstack_gateway_node03_address',
123     'opnfv_infra_kvm_address',
124     'opnfv_infra_kvm_node01_address',
125     'opnfv_infra_kvm_node02_address',
126     'opnfv_infra_kvm_node03_address',
127     'opnfv_openstack_database_address',
128     'opnfv_openstack_database_node01_address',
129     'opnfv_openstack_database_node02_address',
130     'opnfv_openstack_database_node03_address',
131     'opnfv_openstack_message_queue_address',
132     'opnfv_openstack_message_queue_node01_address',
133     'opnfv_openstack_message_queue_node02_address',
134     'opnfv_openstack_message_queue_node03_address',
135     'opnfv_openstack_telemetry_address',
136     'opnfv_openstack_telemetry_node01_address',
137     'opnfv_openstack_telemetry_node02_address',
138     'opnfv_openstack_telemetry_node03_address',
139     'opnfv_openstack_control_address',
140     'opnfv_openstack_control_node01_address',
141     'opnfv_openstack_control_node02_address',
142     'opnfv_openstack_control_node03_address',
143     'opnfv_opendaylight_server_node01_single_address',
144     'opnfv_stacklight_monitor_address',
145     'opnfv_stacklight_monitor_node01_address',
146     'opnfv_stacklight_monitor_node02_address',
147     'opnfv_stacklight_monitor_node03_address',
148     'opnfv_stacklight_log_address',
149     'opnfv_stacklight_log_node01_address',
150     'opnfv_stacklight_log_node02_address',
151     'opnfv_stacklight_log_node03_address',
152     'opnfv_stacklight_telemetry_address',
153     'opnfv_stacklight_telemetry_node01_address',
154     'opnfv_stacklight_telemetry_node02_address',
155     'opnfv_stacklight_telemetry_node03_address'] %}
156
157 {%- set net_public_hosts = [
158     'opnfv_openstack_proxy_address',
159     'opnfv_openstack_proxy_node01_address',
160     'opnfv_openstack_proxy_node02_address',
161     'opnfv_openstack_gateway_node01_external_address',
162     'opnfv_openstack_gateway_node02_external_address',
163     'opnfv_openstack_gateway_node03_external_address',
164     'opnfv_openstack_control_node01_external_address',
165     'opnfv_openstack_control_node02_external_address',
166     'opnfv_openstack_control_node03_external_address'] %}
167
168 {%- set net_private_hosts = [
169     'opnfv_openstack_gateway_node01_tenant_address',
170     'opnfv_openstack_gateway_node02_tenant_address',
171     'opnfv_openstack_gateway_node03_tenant_address'] %}
172
173 {%- set hosts = {
174     net_admin: net_admin_hosts,
175     net_mgmt: net_mgmt_hosts,
176     net_private: net_private_hosts,
177     net_public: net_public_hosts } %}
178
179 {%- set start_ip = {
180     net_admin: 1,
181     net_mgmt: 1,
182     net_private: 1,
183     net_public: 1 } %}
184
185 {%- for nn, nd in net.items() %}
186   {%- if 'ip-range' in nd and 'network' in nd and 'mask' in nd %}
187     {%- set net_nd = [nd.network, nd.mask] | join('/') %}
188     {%- if net_nd in start_ip %}
189       {%- set nd_start_ip = nd['ip-range'].split('-')[0] %}
190       {%- set nd_start = net_nd | ipnet_range_size(net_nd | ipnet_hostmin, nd_start_ip) %}
191       {%- do start_ip.update({net_nd: nd_start}) %}
192     {%- endif %}
193   {%- endif %}
194 {%- endfor %}
195
196 {%- set total_admin_hosts = net_admin_hosts | length + cmp_nodes %}
197 {%- set net_admin_pool_start = net_admin | ipnet_hostaddr(total_admin_hosts + start_ip[net_admin] +1) %}
198 {%- set net_admin_pool_end = net_admin | ipnet_hostmax %}
199 {#- PXE/admin gateway is mas01 when present / jumpserver via virsh otherwise #}
200 {%- set net_admin_gw = net_admin | ipnet_hostaddr(start_ip[net_admin] + net_admin_hosts.index('opnfv_infra_maas_node01_deploy_address') +1) %}
201
202 {%- set total_public_hosts = net_public_hosts | length + cmp_nodes %}
203 {%- if net_public_pool_start is not defined or net_public_pool_end is not defined %}
204     {%- set net_public_pool_start = net_public | ipnet_hostaddr(total_public_hosts + start_ip[net_public] +1) %}
205     {%- set net_public_pool_end = net_public | ipnet_hostmax -1 %}
206 {%- endif %}
207
208 {%- set cluster = {
209     'has_virtual_nodes': False,
210     'has_baremetal_nodes': False,
211     'arch': [] } %}
212 {%- for node in conf.nodes %}
213   {%- if node.node.type == 'virtual' %}
214     {%- do cluster.update({'has_virtual_nodes': True}) %}
215   {%- else %}
216     {%- do cluster.update({'has_baremetal_nodes': True}) %}
217   {%- endif %}
218   {%- if node.node.arch not in cluster.arch %}
219     {%- do cluster.arch.append(node.node.arch) %}
220   {%- endif %}
221 {%- endfor %}