X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=roles%2Fbaremetal_interface_config%2Ftemplates%2Fos_net_config.j2;h=1d1bd044ee0aadb179813abdb7108d7c488ee3d4;hb=refs%2Fheads%2Fmaster;hp=11c0d744a670155e77bd93da2ee368b8c9be07bb;hpb=74a49ba6ef2ea715fa492db0bcd85c30398688e8;p=ta%2Finfra-ansible.git diff --git a/roles/baremetal_interface_config/templates/os_net_config.j2 b/roles/baremetal_interface_config/templates/os_net_config.j2 index 11c0d74..1d1bd04 100644 --- a/roles/baremetal_interface_config/templates/os_net_config.j2 +++ b/roles/baremetal_interface_config/templates/os_net_config.j2 @@ -1,3 +1,4 @@ +#jinja2: lstrip_blocks: True {# This file is written with conditional check and for loop based indentation. It improved code readability. The output json is not pretty. Run cat | python -m json.tool @@ -14,7 +15,6 @@ for pretty printing the same. {%- else %} {%- set default_mtu = 1500 %} {%- endif %} -{%- set sriov_mtu = 9000 %} {%- set max_mtu = 9000 %} {%- set host_network_profiles_list = hosts[ansible_hostname]['network_profiles'] %} {%- set host_network_profile_value = hostvars[ansible_hostname]['network_profiles'][host_network_profiles_list[0]] %} @@ -32,7 +32,7 @@ for pretty printing the same. {%- 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 %} - {%- if CLOUD_TENANT in host_networking.keys() %} + {%- if CLOUD_TENANT in host_networking.keys() and 'interface' in host_networking[CLOUD_TENANT] %} {%- set mtu = default_mtu %} {%- if 'mtu' in host_networking[CLOUD_TENANT] %} {%- set mtu = host_networking[CLOUD_TENANT]['mtu'] %} @@ -59,6 +59,17 @@ for pretty printing the same. {%- set host_provider_network_interfaces = {} %} {%- set dpdk_in_use = False %} {%- endif %} +{%- set sriov_mtus = {} %} +{%- if 'sriov_provider_networks' in host_network_profile_value %} + {%- for net,iface_info in host_network_profile_value['sriov_provider_networks'].iteritems() %} + {%- for tmp,mtu_info in host_networking['provider_networks'].iteritems() if tmp == net %} + {%- if 'mtu' in mtu_info %}{% set mtu = mtu_info['mtu'] %}{% else %}{% set mtu = default_mtu %}{% endif %} + {%- for iface in iface_info['interfaces'] %} + {%- if sriov_mtus.update({iface: mtu}) %}{%- endif %} + {%- endfor %} + {%- endfor %} + {%- endfor %} +{%- endif %} {%- set external_ceph_cidr = None %} {%- if config_phase != 'setup' and 'external_ceph' in storage['backends'] %} {%- set ext_ceph = storage['backends']['external_ceph'] %} @@ -109,6 +120,7 @@ for pretty printing the same. {%- for route in routes %} { "ip_netmask": "{{ route.to }}", "next_hop": "{{ route.via }}" + {%- if route.table is defined %}, "table": "{{ route.table }}"{% endif %} } {% if not loop.last %},{% endif %} {%- endfor %} ] @@ -124,7 +136,7 @@ for pretty printing the same. {%- if not single_nic_setup %} {#- -If all infra ifaces on some phys iface are vlan ifaces it is configured here. +If all infra ifaces on some phys iface are vlan ifaces then phys iface is configured here. Otherwise it gets configured normally on infra iface configuration in the next loop. -#} {%- for iface,infras in host_interface_net_mapping.iteritems() %} @@ -148,6 +160,19 @@ Otherwise it gets configured normally on infra iface configuration in the next l {%- endif %} {%- endif %} {%- endfor %} + {%- if 'bond' in iface %} + {%- for key,slaves in host_bonding_interfaces.iteritems() if key == iface %} + {%- for slave in slaves %} + {%- if slave in sriov_mtus and sriov_mtus[slave] > ifacevars.mtu %} + {%- if ifacevars.update({'mtu': sriov_mtus[slave]}) %}{%- endif %} + {%- endif %} + {%- endfor %} + {%- endfor %} + {%- else %} + {%- if iface in sriov_mtus and sriov_mtus[iface] > ifacevars.mtu %} + {%- if ifacevars.update({'mtu': sriov_mtus[iface]}) %}{%- endif %} + {%- endif %} + {%- endif %} {%- if ifacevars.create %} {%- if not loopvar.first_entry %},{%- endif %} {%- if loopvar.update({'first_entry': False}) %}{%- endif %} @@ -156,7 +181,7 @@ Otherwise it gets configured normally on infra iface configuration in the next l {%- if 'bond' in iface %} {%- for key,slaves in host_bonding_interfaces.iteritems() if key == iface %} "type": "linux_bond", - {% if ifacevars.mtu > 0 %}"mtu": {{ifacevars['mtu']}},{% endif %} + "mtu": {{ifacevars['mtu']}}, {%- if 'linux_bonding_options' in host_network_profile_value %} "bonding_options": "{{ generate_linux_bonding_options(host_network_profile_value['linux_bonding_options']) }}", {%- endif %} @@ -165,7 +190,7 @@ Otherwise it gets configured normally on infra iface configuration in the next l { "name": "{{slave}}", "type": "interface", - {% if ifacevars.mtu > 0 %}"mtu": {{ifacevars['mtu']}},{% endif %} + "mtu": {{ifacevars['mtu']}}, "use_dhcp": false } {% if not loop.last %},{% endif %} @@ -176,7 +201,7 @@ Otherwise it gets configured normally on infra iface configuration in the next l {%- if configured_phys_ifaces.append(iface) %}{%- endif %} "type": "interface", {%- endif %} - {% if ifacevars.mtu > 0 %}"mtu": {{ifacevars['mtu']}},{% endif %} + "mtu": {{ifacevars['mtu']}}, "use_dhcp": false } {%- endif %} @@ -196,6 +221,7 @@ Otherwise it gets configured normally on infra iface configuration in the next l "name": "{{bond_key}}", "type": "linux_bond", "members": [ {% for member in bond_value %} + {%- if configured_phys_ifaces.append(member) %}{%- endif %} { "name": "{{ member }}", "type": "interface", @@ -233,6 +259,32 @@ Otherwise it gets configured normally on infra iface configuration in the next l {%- if 'routes' in value %} {%- set routes = value['routes'] %} {%- endif %} + {%- if config_phase not in ('setup', 'bootstrapping') -%} + {% if 'gateway' in value %} + {%- set caas_oam_gw = value['gateway'] %} + {% else %} + {# Fall back to most popular self IP as gateway #} + {%- set caas_oam_gw = value['cidr'] | ipaddr(1) | ipaddr('address') %} + {% endif %} + {%- set caas_oam_route = { + "to": '0.0.0.0/0', "via": caas_oam_gw, + "table": caas_oam_routing_table_name} %} + {%- if key == 'caas_oam' %} + {%- set _ = routes.append(caas_oam_route) %} + {%- elif key == 'infra_internal' %} + {% set bound_host_networks = [] %} + {% for host_networks in (host_interface_net_mapping.keys() | map('extract', host_interface_net_mapping)| list) %} + {% set _ = bound_host_networks.extend(host_networks) %} + {% endfor %} + {%- if 'caas_oam' not in bound_host_networks %} + {%- set _ = routes.append(caas_oam_route) %} + {%- endif %} + {%- set caas_oam_internal_route = { + "to": value['cidr'], "via": value['ip'], + "table": caas_oam_routing_table_name} %} + {%- set _ = routes.append(caas_oam_internal_route) %} + {% endif %} + {%- endif -%} {%- if key == 'infra_external' and 'gateway' in value %} {%- if '.' in value['gateway'] %} {% set defaultroute = '0.0.0.0/0'%} @@ -263,47 +315,108 @@ Otherwise it gets configured normally on infra iface configuration in the next l {%- if routes %} "routes": {{ add_static_routes(routes) }}, {%- endif %} + {%- if config_phase not in ('setup', 'bootstrapping') -%} + "rules": [ + {"rule": "from {{ caas.oam_cidr }} lookup {{ caas_oam_routing_table_name }}"}, + {"rule": "to {{ caas.oam_cidr }} lookup main"} + ], + {%- endif -%} "use_dhcp": false } {%- endif %}{#- no dpdk or no cloud tenant -#} {%- endif %} {%- endfor %} +{%- if config_phase != 'setup' %} +{#- configure caas provider network interfaces -#} +{%- for iface,value in host_provider_network_interfaces.iteritems() if 'caas' in value['type'] %} + {%- if not loopvar.first_entry %},{%- endif %} + {%- if loopvar.update({'first_entry': False}) %}{%- endif %} + {%- set ifacevars = {'mtu': 0} %} + { + "name": "{{iface}}", + {%- for mapped_net in value['provider_networks'] %} + {%- for net,info in host_networking['provider_networks'].iteritems() if net == mapped_net %} + {%- if 'mtu' in info %} + {%- if info['mtu'] > ifacevars.mtu %} + {%- if ifacevars.update({'mtu': info['mtu']}) %}{%- endif %} + {%- endif %} + {%- elif default_mtu > ifacevars.mtu %} + {%- if ifacevars.update({'mtu': default_mtu}) %}{%- endif %} + {%- endif %} + {%- endfor %} + {%- endfor %} + {%- if 'bond' in iface %} + {%- for bond,slaves in host_bonding_interfaces.iteritems() if bond == iface %} + {%- for slave in slaves %} + {%- if slave in sriov_mtus and sriov_mtus[slave] > ifacevars.mtu %} + {%- if ifacevars.update({'mtu': sriov_mtus[slave]}) %}{%- endif %} + {%- endif %} + {%- endfor %} + "type": "linux_bond", + "mtu": {{ifacevars.mtu}}, + {%- if 'linux_bonding_options' in host_network_profile_value %} + "bonding_options": "{{ generate_linux_bonding_options(host_network_profile_value['linux_bonding_options']) }}", + {%- endif %} + "members": [ {% for slave in slaves %} + {%- if configured_phys_ifaces.append(slave) %}{%- endif %} + { + "name": "{{slave}}", + "type": "interface", + "mtu": {{ifacevars.mtu}}, + "use_dhcp": false + } + {% if not loop.last %},{% endif %} + {%- endfor %} + ], + {%- endfor %} + {%- else %} + {%- if configured_phys_ifaces.append(iface) %}{%- endif %} + {%- if iface in sriov_mtus and sriov_mtus[iface] > ifacevars.mtu %} + {%- if ifacevars.update({'mtu': sriov_mtus[iface]}) %}{%- endif %} + {%- endif %} + "type": "interface", + {%- endif %} + "mtu": {{ifacevars.mtu}}, + "use_dhcp": false + } +{%- endfor %} +{%- endif %}{#- if config_phase != 'setup' -#} + {%- endif %}{#- if not single_nic_setup -#} {%- if config_phase != 'setup' or single_nic_setup %} -{#- configure provider network interfaces -#} -{%- for key,value in host_provider_network_interfaces|dictsort(true) %} +{#- configure ovs-* provider network interfaces -#} +{%- for key,value in host_provider_network_interfaces|dictsort(true) if 'ovs' in value['type'] %} {%- set keyloop = loop %} - {%- if 'ovs' in value['type'] %} - {%- if not loopvar.first_entry %},{%- endif %} - {%- if loopvar.update({'first_entry': False}) %}{%- endif %} - {%- if value['type'] == 'ovs-dpdk' %} - {%- for bond_key,bond_value in host_bonding_interfaces.iteritems() if bond_key == key %} - {%- for member in bond_value %} - {%- if member not in ixgbedevs %} - {%- if configured_phys_ifaces.append(member) %}{%- endif %} - { - "name": "{{member}}", - "type": "interface", - "mtu": {{max_mtu}}, - "use_dhcp": false - }, - {%- endif %} - {%- endfor %} + {%- if not loopvar.first_entry %},{%- endif %} + {%- if loopvar.update({'first_entry': False}) %}{%- endif %} + {%- if value['type'] == 'ovs-dpdk' %} + {%- for bond_key,bond_value in host_bonding_interfaces.iteritems() if bond_key == key %} + {%- for member in bond_value %} + {%- if member not in ixgbedevs %} + {%- if configured_phys_ifaces.append(member) %}{%- endif %} + { + "name": "{{member}}", + "type": "interface", + "mtu": {{max_mtu}}, + "use_dhcp": false + }, + {%- endif %} {%- endfor %} - {%- if 'bond' not in key and key not in ixgbedevs %} - {%- if configured_phys_ifaces.append(key) %}{%- endif %} - { - "name": "{{key}}", - "type": "interface", - "mtu": {{max_mtu}}, - "use_dhcp": false - }, - {%- endif %} + {%- endfor %} + {%- if 'bond' not in key and key not in ixgbedevs %} + {%- if configured_phys_ifaces.append(key) %}{%- endif %} + { + "name": "{{key}}", + "type": "interface", + "mtu": {{max_mtu}}, + "use_dhcp": false + }, {%- endif %} - { + {%- endif %} + { "name": "br-pro{{keyloop.index0}}", {%- if value['type'] == 'ovs-dpdk' %} "type": "ovs_user_bridge", @@ -398,6 +511,32 @@ Otherwise it gets configured normally on infra iface configuration in the next l {%- if 'routes' in value %} {%- set routes = value['routes'] %} {%- endif %} + {%- if config_phase not in ('setup', 'bootstrapping') -%} + {% if 'gateway' in value %} + {%- set caas_oam_gw = value['gateway'] %} + {% else %} + {# Fall back to most popular self IP as gateway #} + {%- set caas_oam_gw = value['cidr'] | ipaddr(1) | ipaddr('address') %} + {% endif %} + {%- set caas_oam_route = { + "to": '0.0.0.0/0', "via": caas_oam_gw, + "table": caas_oam_routing_table_name} %} + {%- if key == 'caas_oam' %} + {%- set _ = routes.append(caas_oam_route) %} + {%- elif key == 'infra_internal' %} + {% set bound_host_networks = [] %} + {% for host_networks in (host_interface_net_mapping.keys() | map('extract', host_interface_net_mapping)| list) %} + {% set _ = bound_host_networks.extend(host_networks) %} + {% endfor %} + {%- if 'caas_oam' not in bound_host_networks %} + {%- set _ = routes.append(caas_oam_route) %} + {%- endif %} + {%- set caas_oam_internal_route = { + "to": value['cidr'], "via": value['ip'], + "table": caas_oam_routing_table_name} %} + {%- set _ = routes.append(caas_oam_internal_route) %} + {% endif %} + {%- endif -%} {%- if key == 'infra_external' and 'gateway' in value %} {%- if '.' in value['gateway'] %} {% set defaultroute = '0.0.0.0/0'%} @@ -428,16 +567,22 @@ Otherwise it gets configured normally on infra iface configuration in the next l {%- if routes %} "routes": {{ add_static_routes(routes) }}, {%- endif %} + {%- if config_phase not in ('setup', 'bootstrapping') -%} + "rules": [ + {"rule": "from {{ caas.oam_cidr }} lookup {{ caas_oam_routing_table_name }}"}, + {"rule": "to {{ caas.oam_cidr }} lookup main"} + ], + {%- endif -%} "use_dhcp": false } {%- endif %} {%- endfor %} {%- endif %}{#- if single_nic_setup -#} ] - } - {%- for net in value['provider_networks'] %} - , - { + } + {%- for net in value['provider_networks'] %} + , + { "name": "br-pro{{keyloop.index0}}.{{loop.index0}}", {%- if value['type'] == 'ovs-dpdk' %} "type": "ovs_user_bridge", @@ -453,13 +598,12 @@ Otherwise it gets configured normally on infra iface configuration in the next l "peer": "pro{{keyloop.index0}}-pro{{keyloop.index0}}.{{loop.index0}}" } ] - } - {%- endfor %} - {%- endif %} + } + {%- endfor %} {%- endfor %} {#- configure vxlan bridge for dpdk cloud tenant -#} -{%- if CLOUD_TENANT in host_networking.keys() and dpdk_in_use %} +{%- if CLOUD_TENANT in host_networking.keys() and 'interface' in host_networking[CLOUD_TENANT] and dpdk_in_use %} {%- set net = host_networking[CLOUD_TENANT] %} {%- if not loopvar.first_entry %},{%- endif %} {%- if loopvar.update({'first_entry': False}) %}{%- endif %} @@ -490,22 +634,26 @@ Otherwise it gets configured normally on infra iface configuration in the next l {#- configure sr-iov ifaces -#} {%- if config_phase != 'setup' %} -{%- if 'sriov_provider_networks' in host_network_profile_value %} - {%- for net,net_info in host_network_profile_value['sriov_provider_networks'].iteritems() %} - {%- for iface in net_info['interfaces'] %} - {%- if iface not in configured_phys_ifaces %} - {%- if not loopvar.first_entry %},{%- endif %} - {%- if loopvar.update({'first_entry': False}) %}{%- endif %} - { + {%- for iface,mtu in sriov_mtus.iteritems() %} + {%- if iface not in configured_phys_ifaces %} + {%- if not loopvar.first_entry %},{%- endif %} + {%- if loopvar.update({'first_entry': False}) %}{%- endif %} + { "name": "{{iface}}", "type": "interface", - "mtu": {{sriov_mtu}}, + "mtu": {{mtu}}, "use_dhcp": false - } - {%- endif %} - {%- endfor %} + } + {%- endif %} {%- endfor %} -{%- endif %} {%- endif %}{#- if config_phase != 'setup' -#} +{%- if config_phase not in ('setup', 'bootstrapping') %} + , + { + "name": "{{ caas_oam_routing_table_name }}", + "type": "route_table", + "table_id": {{ caas_oam_routing_table_id }} + } +{%- endif %} ] }