-{#
-This file is written with conditional check and for loop based indentation.
-It improved code readability. The output json is not pretty. Run cat <output.json> | python -m json.tool
-for pretty printing the same.
-#}
-
-{% macro generate_linux_bonding_options(options) -%}
- {%- set mode_mapping = {'active-backup' : 'active-backup', 'lacp' : '802.3ad'} -%}
- {%- set default_options = {
- 'active-backup' : 'miimon=100',
- 'lacp' : 'lacp_rate=fast miimon=100'
- } -%}
- {%- for i in options.split() -%}
- {%- set key, value = i.split('=') -%}
- {%- if key == 'mode' -%}
- {%- if default_options[value] -%}
- {{ 'mode=' ~ mode_mapping[value] ~ ' ' ~ default_options[value] }}
- {%- else -%}
- {{ 'mode=' ~ mode_mapping[value] }}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
-{%- endmacro %}
-
-{% macro generate_ovs_bonding_options(options) -%}
- {%- set mode_mapping = {'active-backup' : 'active-backup', 'lacp' : 'balance-slb', 'lacp-layer34' : 'balance-tcp'} -%}
- {%- set default_options = {
- 'active-backup' : '',
- 'lacp' : 'lacp=active other_config:lacp-time=fast other_config:bond-detect-mode=carrier',
- 'lacp-layer34' : 'lacp=active other_config:lacp-time=fast other_config:bond-detect-mode=carrier'
- } -%}
- {%- for i in options.split() -%}
- {%- set key, value = i.split('=') -%}
- {%- if key == 'mode' -%}
- {%- if default_options[value] -%}
- {{ 'bond_mode=' ~ mode_mapping[value] ~ ' ' ~ default_options[value] }}
- {%- else -%}
- {{ 'bond_mode=' ~ mode_mapping[value] }}
- {%- endif -%}
- {%- endif -%}
- {%- endfor -%}
-{%- endmacro %}
-
-{% macro add_static_routes(routes) -%}
- [
- {%- for route in routes %}
- {
- "ip_netmask": "{{ route.to }}", "next_hop": "{{ route.via }}"
- } {% if not loop.last %},{% endif %}
- {%- endfor %}
- ]
-{%- endmacro %}
-
-{%- set nfs_server_ip = hostvars[installation_controller]['networking']['infra_external']['ip'] %}
-{
-"ironic_nodes": [
-{% for host_key,host_value in hosts.iteritems() %}
-
-{%- set host_networking = hostvars[host_key]['networking'] %}
-{%- set host_network_profiles_list = hosts[host_key]['network_profiles'] %}
-{%- set host_network_profile_value = hostvars[host_key]['network_profiles'][host_network_profiles_list[0]] %}
-{%- set host_interface_net_mapping = host_network_profile_value['interface_net_mapping'] %}
-{%- set host_hdd_mapping = hostvars[host_key]['by_path_disks'] %}
-
-{%- set infra_bond = {'in_use': false} %}
-{%- if 'bonding_interfaces' in host_network_profile_value %}
- {%- set host_bonding_interfaces = host_network_profile_value['bonding_interfaces'] %}
-{%- endif %}
-
-{%- set single_nic_setup = False %}
-{%- if 'provider_network_interfaces' in host_network_profile_value %}
- {%- set host_provider_network_interfaces = host_network_profile_value['provider_network_interfaces'] %}
- {%- if host_interface_net_mapping|length == 1 and host_provider_network_interfaces|length == 1 %}
- {%- if host_interface_net_mapping.keys()[0] == host_provider_network_interfaces.keys()[0] %}
- {%- set single_nic_setup = True %}
- {%-endif %}
- {%-endif %}
-{%-endif %}
-
-{%- set mtu = 1500 %}
-{%- if 'mtu' in host_networking['infra_internal'] %}
- {%- set mtu = host_networking['infra_internal']['mtu'] %}
-{%- elif 'mtu' in host_networking %}
- {%- set mtu = host_networking['mtu'] %}
-{%- endif %}
-
-{%- set phys_iface = {'mtu': 1500} %}
-{%- if 'vlan' in host_networking['infra_internal'] %}
- {%- for iface,infras in host_interface_net_mapping.iteritems() %}
- {%- if "infra_internal" in infras %}
- {%- for infra in infras %}
- {%- set tmp_mtu = 0 %}
- {%- if 'mtu' in host_networking[infra] %}
- {%- set tmp_mtu = host_networking[infra]['mtu'] %}
- {%- elif 'mtu' in host_networking %}
- {%- set tmp_mtu = host_networking['mtu'] %}
- {%- endif %}
- {%- if infra == 'cloud_tenant' %}
- {%- set tmp_mtu = tmp_mtu + 50 %}
- {%- endif %}
- {%- if tmp_mtu > phys_iface.mtu %}
- {%- if phys_iface.update({'mtu': tmp_mtu}) %}{%- endif %}
- {%- endif %}
- {%- endfor %}
- {%- endif %}
- {%- endfor %}
-{%- endif %}
-
- {
- "name": "{{ host_key }}",
- "network_interface": "noop",
- "nics": [ {%- if 'mgmt_mac' in host_value %}
- {%- for mac_members in host_value['mgmt_mac'] %}
- {
- "mac": "{{ mac_members }}"
- }
- {%- if not loop.last %},{%- endif %}
- {%- endfor %}
- {%- else: %}
- {
- "mac": "{{ hw_inventory_details[host_key]['mgmt_mac'] }}"
- }
- {%- endif %}
- ],
- "driver_info": { "power": {
- "os_net_config": {
- "network_config": [
- {%- if 'interface' in host_networking['infra_internal'] %}
- {%- if not single_nic_setup %}
- {%- if 'bonding_interfaces' in host_network_profile_value %}
- {%- for net_key,net_value in host_interface_net_mapping.iteritems() %}
- {%- if "bond" in net_key and "infra_internal" in net_value %}
- {
- "name": "{{net_key}}",
- "type": "linux_bond",
- "members": [
- {%- for member in host_bonding_interfaces[net_key] %}
- {
- {%- if 'bond' in host_networking['infra_internal']['interface'] %}
- "mtu": {{mtu}},
- {%- else %}
- "mtu": {{phys_iface['mtu']}},
- {%- endif %}
- "name": "{{ member }}",
- "type": "interface",
- "use_dhcp": false
- } {%- if not loop.last %},{%- endif %}
- {% endfor %} ],
- {%- if 'linux_bonding_options' in host_network_profile_value %}
- "bonding_options": "{{ generate_linux_bonding_options(host_network_profile_value['linux_bonding_options']) }}",
- {%- endif %}
- {%- if 'bond' in host_networking['infra_internal']['interface'] %}
- "addresses": [ { "ip_netmask": "{{ host_networking['infra_internal']['ip'] }}/{{host_networking['infra_internal']['mask']}}" } ],
- "mtu": {{mtu}},
- {%- if 'routes' in host_networking['infra_internal'] %}
- {%- set routes = host_networking['infra_internal']['routes'] %}
- "routes": {{ add_static_routes(routes) }},
- {%- endif %}
- {%- else %}
- "mtu": {{phys_iface['mtu']}},
- {%- endif %}
- "use_dhcp": false
- {%- if infra_bond.update({'in_use': true}) %}{%- endif %}
- },
- {%- endif %}
- {%- endfor %}
- {%- endif %}
- {%- if 'vlan' in host_networking['infra_internal'] %}
- {
- "type": "vlan",
- "addresses": [ { "ip_netmask": "{{ host_networking['infra_internal']['ip'] }}/{{host_networking['infra_internal']['mask']}}" } ],
- "vlan_id": {{ host_networking['infra_internal']['vlan'] }},
- {%- for net_key,net_value in host_interface_net_mapping.iteritems() %}
- {%- if "infra_internal" in net_value %}
- "device": "{{net_key}}",
- {%- endif %}
- {%- endfor %}
- "mtu": {{mtu}},
- {%- if 'routes' in host_networking['infra_internal'] %}
- {%- set routes = host_networking['infra_internal']['routes'] %}
- "routes": {{ add_static_routes(routes) }},
- {%- endif %}
- "use_dhcp": false
- }
- {%- if not infra_bond.in_use %}
- ,
- {
- {%- for net_key,net_value in host_interface_net_mapping.iteritems() %}
- {%- if "infra_internal" in net_value %}
- "name": "{{net_key}}",
- {%- endif %}
- {%- endfor %}
- "type": "interface",
- "mtu": {{phys_iface['mtu']}},
- "use_dhcp": false
- }
- {%- endif %}
- {%- elif not infra_bond.in_use %}
- {
- "name": "{{host_networking['infra_internal']['interface']}}",
- "type": "interface",
- "addresses": [ { "ip_netmask": "{{ host_networking['infra_internal']['ip'] }}/{{host_networking['infra_internal']['mask']}}" } ],
- "mtu": {{mtu}},
- {%- if 'routes' in host_networking['infra_internal'] %}
- {%- set routes = host_networking['infra_internal']['routes'] %}
- "routes": {{ add_static_routes(routes) }},
- {%- endif %}
- "use_dhcp": false
- }
- {%- endif %}
- {%- else %}{#- if not single_nic_setup -#}
- {
- "name": "br-pro0",
- "type": "ovs_bridge",
- "members": [
- {
- "mtu": {{phys_iface['mtu']}},
- {%- set iface = host_interface_net_mapping.keys()[0] %}
- {%- if 'bond' in iface %}
- {%- for bond_iface,bond_value in host_bonding_interfaces.iteritems() if bond_iface == iface %}
- {%- if 'ovs_bonding_options' in host_network_profile_value %}
- "ovs_options": "{{ generate_ovs_bonding_options(host_network_profile_value['ovs_bonding_options']) }}",
- {%- endif %}
- "name": "{{iface}}",
- "type": "ovs_bond",
- "members": [ {% for member in bond_value %}
- {
- "name": "{{ member }}",
- "type": "interface",
- "mtu": {{phys_iface['mtu']}},
- "use_dhcp": false
- }
- {% if not loop.last %},{% endif %}
- {%- endfor %}
- ],
- {%- endfor %}
- {%- else %}
- "name": "{{iface}}",
- "type": "interface",
- {%- endif %}
- "use_dhcp": false
- }
- ,
- {
- {%- set infra = host_networking['infra_internal'] %}
- "type": "vlan",
- "vlan_id": {{ infra['vlan'] }},
- "addresses": [ { "ip_netmask": "{{ infra['ip'] }}/{{infra['mask']}}" } ],
- "mtu": {{mtu}},
- {%- if 'routes' in infra %}
- {%- set routes = infra['routes'] %}
- "routes": {{ add_static_routes(routes) }},
- {%- endif %}
- "use_dhcp": false
- }
- ]
- }
- {%- endif %}{#- if not single_nic_setup -#}
- {%- endif %}
- ]
- },
- "provisioning_server": "{{nfs_server_ip}}",
- "provisioning_server_http_port": "{{golden_image_http_port}}",
- "virtmedia_deploy_iso": "file:///opt/images/ironic-deploy.iso",
- {% if virtual_env == true %}
- "ssh_address": "{{ host_value['hwmgmt']['address'] }}",
- "ssh_key_contents": "{{ '{{' }} lookup('file', '/etc/userconfig/id_rsa') {{ '}}' }}",
- "ssh_username": "{{ host_value['hwmgmt']['user'] }}",
- "ipmi_address": "{{hostvars[installation_controller]['networking']['infra_internal']['ip']}}",
- "ipmi_username": "admin",
- "ipmi_password": "password",
- "ipmi_port": "{{ hosts[host_key]['vbmc_port'] }}"
- } },
- "driver": "ssh_virtmedia",
- "properties": { "capabilities": "boot_option:local", "cpu_arch": "x86_64", "cpus": 8, "disk_size": 40, "ram": 16384, "root_device":{ "by_path": "{{ host_hdd_mapping['os']}}" } }
- {%- else %}
- "ipmi_address": "{{ host_value['hwmgmt']['address'] }}",
- "ipmi_password": "{{ host_value['hwmgmt']['password'] }}",
- "ipmi_username": "{{ host_value['hwmgmt']['user'] }}",
- "product_family": "{{ hw_inventory_details[host_key]['product_family'] }}",
- "vendor": "{{ hw_inventory_details[host_key]['vendor'] }}"
- }
-},
- "driver": "ipmi_virtmedia",
- "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 %} } }
- {% endif %}
- }
- {% if not loop.last %},{% endif %}
-{%- endfor %}
-]
-}