[PDF] Daisy, Fuel: Add support for IDF net_config
[pharos.git] / config / installers / daisy / network.yaml.j2
1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 ##############################################################################
11 # Description
12 # MANAGEMENT: used for management
13 # STORAGE: used for storage access
14 # EXTERNAL: tenant public/floating IP associated network
15 # PUBLICAPI: used for horizon access, openstack API access
16 # TENANT: used for tenant access, vlan and VxLan supported, default VxLan
17 # HEARTBEAT: used for heartbeat, requires a dedicated interface
18 ##############################################################################
19
20 ---
21
22 network-config-metadata:
23   title: 'Deployment Adapter for baremetal POD'
24   version: '0.1'
25   created: 'Nov 22 2017'
26   comment: 'For Daisy initial'
27
28 {%- set mapping = {'HEARTBEAT': 'admin',
29                    'MANAGEMENT': 'mgmt',
30                    'PUBLICAPI': 'mgmt',
31                    'STORAGE': 'storage',
32                    'TENANT': 'private',
33                    'EXTERNAL': 'public'} -%}
34
35 {%- if "idf" in conf and ("daisy" in conf["idf"] or "fuel" in conf["idf"]) -%}
36   {%- if "daisy" in conf["idf"] -%}
37     {%- set installer = "daisy" -%}
38   {%- else -%}
39     {%- set installer = "fuel" -%}
40   {%- endif %}
41
42 {%- if conf.net_config is defined -%}
43     {%- set conf_net_config = conf.net_config -%}
44 {%- elif conf.idf.net_config is defined -%}
45     {%- set conf_net_config = conf.idf.net_config -%}
46 {%- endif %}
47
48 networks:
49
50   {%- set nodes_num = conf['nodes'] | length -%}
51   {%- set networks = {} -%}
52   {%- for key in mapping -%}
53     {%- set net_data = conf_net_config[mapping[key]] -%}
54     {%- set interface = net_data['interface'] -%}
55     {%- set interface_name = conf.idf[installer].network.node[0].interfaces[interface] -%}
56     {%- set bus_addr = conf.idf[installer].network.node[0].busaddr[interface] -%}
57     {%- set vlan = net_data['vlan'] -%}
58     {%- if vlan == "native" or vlan == None -%}
59       {%- set vlan = "null" -%}
60     {%- endif -%}
61     {%- set network = net_data['network'] -%}
62     {%- set ips = network.split(".") -%}
63     {%- set mask = net_data['mask'] -%}
64     {%- if 'ip-range' in net_data -%}
65       {%- set ip_range = net_data['ip-range'] -%}
66       {%- set (start, end) = ip_range.split("-") -%}
67     {%- else -%}
68       {%- set start = ".".join([ips[0], ips[1], ips[2], "10"]) -%}
69       {%- set end = ".".join([ips[0], ips[1], ips[2], "200"]) -%}
70     {%- endif -%}
71     {%- set vip = start.split(".")[3] | int -%}
72     {%- set vip = vip + nodes_num + 10 - (vip + nodes_num) % 10 -%}
73     {%- set vip = ".".join([ips[0], ips[1], ips[2], vip | string]) -%}
74
75     {%- if 'gateway' in net_data -%}
76       {%- set gateway = net_data.gateway -%}
77     {%- else -%}
78       {%- set gateway = ".".join([ips[0], ips[1], ips[2], "1"]) -%}
79     {%- endif -%}
80
81     {%- set networks = networks.update({key: {'interface_name': interface_name,
82                                               'bus_addr': bus_addr,
83                                               'vlan': vlan,
84                                               'network': network,
85                                               'mask': mask,
86                                               'start': start,
87                                               'end': end,
88                                               'vip': vip,
89                                               'gateway': gateway
90                                              }
91                                        }) %}
92
93   - cidr: '{{ network }}/{{ mask }}'
94     gateway: '{{ gateway }}'
95     ip_ranges:
96       - 'start': '{{ start }}'
97         'end': '{{ end }}'
98     vlan_id: {{ vlan }}
99     name: '{{ key }}'
100     {%- if key == 'EXTERNAL' %}
101     network_name: 'admin_external'
102     mapping: 'physnet1'
103     {%- endif -%}
104   {%- endfor %}
105
106 interfaces:
107   {%- for key in mapping %}
108   - name: '{{ key }}'
109     interface: '{{ networks[key].interface_name }}'
110   {%- endfor %}
111
112 internal_vip: '{{ networks['MANAGEMENT'].vip }}'
113 public_vip: '{{ networks['PUBLICAPI'].vip }}'
114
115 {%- endif %}