2 This file is written with conditional check and for loop based indentation.
3 It improved code readability. The output json is not pretty. Run cat <output.json> | python -m json.tool
4 for pretty printing the same.
7 {% macro generate_linux_bonding_options(options) -%}
8 {%- set mode_mapping = {'active-backup' : 'active-backup', 'lacp' : '802.3ad'} -%}
9 {%- set default_options = {
10 'active-backup' : 'miimon=100',
11 'lacp' : 'lacp_rate=fast miimon=100'
13 {%- for i in options.split() -%}
14 {%- set key, value = i.split('=') -%}
15 {%- if key == 'mode' -%}
16 {%- if default_options[value] -%}
17 {{ 'mode=' ~ mode_mapping[value] ~ ' ' ~ default_options[value] }}
19 {{ 'mode=' ~ mode_mapping[value] }}
25 {% macro generate_ovs_bonding_options(options) -%}
26 {%- set mode_mapping = {'active-backup' : 'active-backup', 'lacp' : 'balance-slb', 'lacp-layer34' : 'balance-tcp'} -%}
27 {%- set default_options = {
29 'lacp' : 'lacp=active other_config:lacp-time=fast other_config:bond-detect-mode=carrier',
30 'lacp-layer34' : 'lacp=active other_config:lacp-time=fast other_config:bond-detect-mode=carrier'
32 {%- for i in options.split() -%}
33 {%- set key, value = i.split('=') -%}
34 {%- if key == 'mode' -%}
35 {%- if default_options[value] -%}
36 {{ 'bond_mode=' ~ mode_mapping[value] ~ ' ' ~ default_options[value] }}
38 {{ 'bond_mode=' ~ mode_mapping[value] }}
44 {% macro add_static_routes(routes) -%}
46 {%- for route in routes %}
48 "ip_netmask": "{{ route.to }}", "next_hop": "{{ route.via }}"
49 } {% if not loop.last %},{% endif %}
54 {%- set nfs_server_ip = hostvars[installation_controller]['networking']['infra_external']['ip'] %}
57 {% for host_key,host_value in hosts.iteritems() %}
59 {%- set host_networking = hostvars[host_key]['networking'] %}
60 {%- set host_network_profiles_list = hosts[host_key]['network_profiles'] %}
61 {%- set host_network_profile_value = hostvars[host_key]['network_profiles'][host_network_profiles_list[0]] %}
62 {%- set host_interface_net_mapping = host_network_profile_value['interface_net_mapping'] %}
63 {%- set host_hdd_mapping = hostvars[host_key]['by_path_disks'] %}
65 {%- set infra_bond = {'in_use': false} %}
66 {%- if 'bonding_interfaces' in host_network_profile_value %}
67 {%- set host_bonding_interfaces = host_network_profile_value['bonding_interfaces'] %}
70 {%- set single_nic_setup = False %}
71 {%- if 'provider_network_interfaces' in host_network_profile_value %}
72 {%- set host_provider_network_interfaces = host_network_profile_value['provider_network_interfaces'] %}
73 {%- if host_interface_net_mapping|length == 1 and host_provider_network_interfaces|length == 1 %}
74 {%- if host_interface_net_mapping.keys()[0] == host_provider_network_interfaces.keys()[0] %}
75 {%- set single_nic_setup = True %}
81 {%- if 'mtu' in host_networking['infra_internal'] %}
82 {%- set mtu = host_networking['infra_internal']['mtu'] %}
83 {%- elif 'mtu' in host_networking %}
84 {%- set mtu = host_networking['mtu'] %}
87 {%- set phys_iface = {'mtu': 1500} %}
88 {%- if 'vlan' in host_networking['infra_internal'] %}
89 {%- for iface,infras in host_interface_net_mapping.iteritems() %}
90 {%- if "infra_internal" in infras %}
91 {%- for infra in infras %}
92 {%- set tmp_mtu = 0 %}
93 {%- if 'mtu' in host_networking[infra] %}
94 {%- set tmp_mtu = host_networking[infra]['mtu'] %}
95 {%- elif 'mtu' in host_networking %}
96 {%- set tmp_mtu = host_networking['mtu'] %}
98 {%- if infra == 'cloud_tenant' %}
99 {%- set tmp_mtu = tmp_mtu + 50 %}
101 {%- if tmp_mtu > phys_iface.mtu %}
102 {%- if phys_iface.update({'mtu': tmp_mtu}) %}{%- endif %}
110 "name": "{{ host_key }}",
111 "network_interface": "noop",
112 "nics": [ {%- if 'mgmt_mac' in host_value %}
113 {%- for mac_members in host_value['mgmt_mac'] %}
115 "mac": "{{ mac_members }}"
117 {%- if not loop.last %},{%- endif %}
121 "mac": "{{ hw_inventory_details[host_key]['mgmt_mac'] }}"
125 "driver_info": { "power": {
128 {%- if 'interface' in host_networking['infra_internal'] %}
129 {%- if not single_nic_setup %}
130 {%- if 'bonding_interfaces' in host_network_profile_value %}
131 {%- for net_key,net_value in host_interface_net_mapping.iteritems() %}
132 {%- if "bond" in net_key and "infra_internal" in net_value %}
134 "name": "{{net_key}}",
135 "type": "linux_bond",
137 {%- for member in host_bonding_interfaces[net_key] %}
139 {%- if 'bond' in host_networking['infra_internal']['interface'] %}
142 "mtu": {{phys_iface['mtu']}},
144 "name": "{{ member }}",
147 } {%- if not loop.last %},{%- endif %}
149 {%- if 'linux_bonding_options' in host_network_profile_value %}
150 "bonding_options": "{{ generate_linux_bonding_options(host_network_profile_value['linux_bonding_options']) }}",
152 {%- if 'bond' in host_networking['infra_internal']['interface'] %}
153 "addresses": [ { "ip_netmask": "{{ host_networking['infra_internal']['ip'] }}/{{host_networking['infra_internal']['mask']}}" } ],
155 {%- if 'routes' in host_networking['infra_internal'] %}
156 {%- set routes = host_networking['infra_internal']['routes'] %}
157 "routes": {{ add_static_routes(routes) }},
160 "mtu": {{phys_iface['mtu']}},
163 {%- if infra_bond.update({'in_use': true}) %}{%- endif %}
168 {%- if 'vlan' in host_networking['infra_internal'] %}
171 "addresses": [ { "ip_netmask": "{{ host_networking['infra_internal']['ip'] }}/{{host_networking['infra_internal']['mask']}}" } ],
172 "vlan_id": {{ host_networking['infra_internal']['vlan'] }},
173 {%- for net_key,net_value in host_interface_net_mapping.iteritems() %}
174 {%- if "infra_internal" in net_value %}
175 "device": "{{net_key}}",
179 {%- if 'routes' in host_networking['infra_internal'] %}
180 {%- set routes = host_networking['infra_internal']['routes'] %}
181 "routes": {{ add_static_routes(routes) }},
185 {%- if not infra_bond.in_use %}
188 {%- for net_key,net_value in host_interface_net_mapping.iteritems() %}
189 {%- if "infra_internal" in net_value %}
190 "name": "{{net_key}}",
194 "mtu": {{phys_iface['mtu']}},
198 {%- elif not infra_bond.in_use %}
200 "name": "{{host_networking['infra_internal']['interface']}}",
202 "addresses": [ { "ip_netmask": "{{ host_networking['infra_internal']['ip'] }}/{{host_networking['infra_internal']['mask']}}" } ],
204 {%- if 'routes' in host_networking['infra_internal'] %}
205 {%- set routes = host_networking['infra_internal']['routes'] %}
206 "routes": {{ add_static_routes(routes) }},
211 {%- else %}{#- if not single_nic_setup -#}
214 "type": "ovs_bridge",
217 "mtu": {{phys_iface['mtu']}},
218 {%- set iface = host_interface_net_mapping.keys()[0] %}
219 {%- if 'bond' in iface %}
220 {%- for bond_iface,bond_value in host_bonding_interfaces.iteritems() if bond_iface == iface %}
221 {%- if 'ovs_bonding_options' in host_network_profile_value %}
222 "ovs_options": "{{ generate_ovs_bonding_options(host_network_profile_value['ovs_bonding_options']) }}",
226 "members": [ {% for member in bond_value %}
228 "name": "{{ member }}",
230 "mtu": {{phys_iface['mtu']}},
233 {% if not loop.last %},{% endif %}
245 {%- set infra = host_networking['infra_internal'] %}
247 "vlan_id": {{ infra['vlan'] }},
248 "addresses": [ { "ip_netmask": "{{ infra['ip'] }}/{{infra['mask']}}" } ],
250 {%- if 'routes' in infra %}
251 {%- set routes = infra['routes'] %}
252 "routes": {{ add_static_routes(routes) }},
258 {%- endif %}{#- if not single_nic_setup -#}
262 "provisioning_server": "{{nfs_server_ip}}",
263 "provisioning_server_http_port": "{{golden_image_http_port}}",
264 "virtmedia_deploy_iso": "file:///opt/images/ironic-deploy.iso",
265 {% if virtual_env == true %}
266 "ssh_address": "{{ host_value['hwmgmt']['address'] }}",
267 "ssh_key_contents": "{{ '{{' }} lookup('file', '/etc/userconfig/id_rsa') {{ '}}' }}",
268 "ssh_username": "{{ host_value['hwmgmt']['user'] }}",
269 "ipmi_address": "{{hostvars[installation_controller]['networking']['infra_internal']['ip']}}",
270 "ipmi_username": "admin",
271 "ipmi_password": "password",
272 "ipmi_port": "{{ hosts[host_key]['vbmc_port'] }}"
274 "driver": "ssh_virtmedia",
275 "properties": { "capabilities": "boot_option:local", "cpu_arch": "x86_64", "cpus": 8, "disk_size": 40, "ram": 16384, "root_device":{ "by_path": "{{ host_hdd_mapping['os']}}" } }
277 "ipmi_address": "{{ host_value['hwmgmt']['address'] }}",
278 "ipmi_password": "{{ host_value['hwmgmt']['password'] }}",
279 "ipmi_username": "{{ host_value['hwmgmt']['user'] }}",
280 "product_family": "{{ hw_inventory_details[host_key]['product_family'] }}",
281 "vendor": "{{ hw_inventory_details[host_key]['vendor'] }}"
284 "driver": "ipmi_virtmedia",
285 "properties": { "capabilities": "boot_option:local", "cpu_arch": "x86_64", "cpus": 8, "disk_size": 40, "ram": 16384, "root_device":{ {% if host_hdd_mapping['os'] != "/dev/sda" %} "by_path": "{{ host_hdd_mapping['os']}}" {% else %} "name": "{{ host_hdd_mapping['os']}}" {% endif %} } }
288 {% if not loop.last %},{% endif %}