Saltstack Official Linux Formula
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

238 lines
8.6KB

  1. {%- from "linux/map.jinja" import network with context %}
  2. {%- from "linux/map.jinja" import system with context %}
  3. {%- if network.dpdk.enabled %}
  4. linux_dpdk_pkgs:
  5. pkg.installed:
  6. - pkgs: {{ network.dpdk_pkgs }}
  7. linux_dpdk_kernel_module:
  8. kmod.present:
  9. - name: {{ network.dpdk.driver }}
  10. - persist: true
  11. - require:
  12. - pkg: linux_dpdk_pkgs
  13. - require_in:
  14. - service: linux_network_dpdk_service
  15. /etc/dpdk/interfaces:
  16. file.managed:
  17. - source: salt://linux/files/dpdk_interfaces
  18. - template: jinja
  19. - user: root
  20. - group: root
  21. - mode: 644
  22. - require:
  23. - pkg: linux_dpdk_pkgs
  24. linux_network_dpdk_service:
  25. service.running:
  26. - enable: true
  27. - name: dpdk
  28. - watch:
  29. - file: /etc/dpdk/interfaces
  30. {%- if network.openvswitch is defined %}
  31. openvswitch_dpdk_pkgs:
  32. pkg.installed:
  33. - pkgs:
  34. - openvswitch-switch-dpdk
  35. - openvswitch-switch
  36. - bridge-utils
  37. linux_network_dpdk_ovs_service:
  38. cmd.run:
  39. - name: "ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-init=true"
  40. - require:
  41. - service: linux_network_dpdk_service
  42. - unless: 'ovs-vsctl get Open_vSwitch . other_config | grep "dpdk-init=\"true\""'
  43. {%- set ovs_options = [
  44. "pmd-cpu-mask=\""+network.openvswitch.pmd_cpu_mask+"\"",
  45. "dpdk-socket-mem=\""+network.openvswitch.dpdk_socket_mem+"\"",
  46. "dpdk-lcore-mask=\""+network.openvswitch.dpdk_lcore_mask+"\"",
  47. "dpdk-extra=\"-n "+network.openvswitch.memory_channels+" --vhost-owner libvirt-qemu:kvm --vhost-perm 0664\""
  48. ]
  49. %}
  50. {%- if network.openvswitch.get('vhost_socket_dir',{}).get('path') %}
  51. {%- do ovs_options.append("vhost-sock-dir=\""+network.openvswitch.vhost_socket_dir.path+"\"") %}
  52. {%- endif %}
  53. {%- for option in ovs_options %}
  54. linux_network_dpdk_ovs_option_{{ option }}:
  55. cmd.run:
  56. - name: 'ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Open_vSwitch . other_config:{{ option }}'
  57. - watch_in:
  58. - service: service_openvswitch
  59. - require:
  60. - cmd: linux_network_dpdk_ovs_service
  61. - unless: |
  62. ovs-vsctl get Open_vSwitch . other_config | grep '{{ option }}'
  63. {%- endfor %}
  64. openvswitch_dpdk_ovs_alternative:
  65. alternatives.remove:
  66. - name: ovs-vswitchd
  67. - path: /usr/lib/openvswitch-switch/ovs-vswitchd
  68. - require:
  69. - pkg: openvswitch_dpdk_pkgs
  70. - watch_in:
  71. - service: service_openvswitch
  72. service_openvswitch:
  73. service.running:
  74. - name: openvswitch-switch
  75. - enable: true
  76. - watch:
  77. - cmd: linux_network_dpdk_ovs_service
  78. {%- endif %}
  79. {%- for interface_name, interface in network.interface.items() if interface.get('enabled', True) %}
  80. {%- if interface.type == "dpdk_ovs_bond" %}
  81. {%- set bond_interfaces = {} %}
  82. {%- for iface_name, iface in network.interface.items() if iface.get('enabled', True) and iface.get('bond',"") == interface_name %}
  83. {#- Get list of child interfaces #}
  84. {%- do bond_interfaces.update({iface_name: iface}) %}
  85. {%- endfor %}
  86. linux_network_dpdk_bond_interface_{{ interface_name }}:
  87. cmd.run:
  88. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} add-bond {{ interface.bridge }} {{ interface_name }} {{ bond_interfaces.keys()|join(' ') }}"
  89. - unless: "ovs-vsctl list-ports {{ interface.bridge }} | grep -w {{ interface_name }}"
  90. - require:
  91. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  92. {% for iface_name, iface in bond_interfaces.items() %}
  93. linux_network_dpdk_bond_interface_{{ iface_name }}_activate:
  94. cmd.run:
  95. - name: "timeout 5 /bin/sh -c -- 'while true; do ovs-vsctl get Interface {{ iface_name }} name 1>/dev/null 2>&1 && break || sleep 1; done'"
  96. - unless: "ovs-vsctl get Interface {{ iface_name }} name 1>/dev/null 2>&1"
  97. linux_network_dpdk_bond_interface_{{ iface_name }}_type:
  98. cmd.run:
  99. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ iface_name }} type=dpdk"
  100. - unless: "ovs-vsctl get interface {{ iface_name }} type | grep -w dpdk"
  101. - require:
  102. - cmd: linux_network_dpdk_bond_interface_{{ iface_name }}_activate
  103. linux_network_dpdk_bond_interface_{{ iface_name }}_options:
  104. cmd.run:
  105. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ iface_name }} options:dpdk-devargs={{ iface.pci }}"
  106. - unless: "ovs-vsctl get interface {{ iface_name }} options:dpdk-devargs | grep -w {{ iface.pci }}"
  107. - require:
  108. - cmd: linux_network_dpdk_bond_interface_{{ iface_name }}_activate
  109. {% endfor %}
  110. linux_network_dpdk_bond_mode_{{ interface_name }}:
  111. cmd.run:
  112. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set port {{ interface_name }} bond_mode={{ interface.mode }}{%- if interface.mode == 'balance-slb' %} lacp=active{%- endif %}"
  113. - unless: "ovs-appctl bond/show {{ interface_name }} | grep {{ interface.mode }}"
  114. - require:
  115. - cmd: linux_network_dpdk_bond_interface_{{ interface_name }}
  116. {%- elif interface.type == 'dpdk_ovs_bridge' %}
  117. linux_network_dpdk_bridge_interface_{{ interface_name }}:
  118. cmd.run:
  119. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} add-br {{ interface_name }} -- set bridge {{ interface_name }} datapath_type=netdev{% if interface.tag is defined %} -- set port {{ interface_name }} tag={{ interface.tag }}{% endif %}"
  120. - unless: "ovs-vsctl show | grep {{ interface_name }}"
  121. {# OVS dpdk needs ip address for vxlan termination on bridge br-prv #}
  122. {%- if interface.address is defined %}
  123. {# create override for openvswitch dependency for dpdk br-prv #}
  124. /etc/systemd/system/ifup@{{ interface_name }}.service.d/override.conf:
  125. file.managed:
  126. - makedirs: true
  127. - require:
  128. - cmd: linux_network_dpdk_bridge_interface_{{ interface_name }}
  129. - contents: |
  130. [Unit]
  131. Requires=openvswitch-switch.service
  132. After=openvswitch-switch.service
  133. {# enforce ip address and mtu for ovs dpdk br-prv #}
  134. /etc/network/interfaces.u/ifcfg-{{ interface_name }}:
  135. file.managed:
  136. - contents: |
  137. auto {{ interface_name }}
  138. iface {{ interface_name }} inet static
  139. address {{ interface.address }}
  140. netmask {{ interface.netmask }}
  141. {%- if interface.mtu is defined %}
  142. mtu {{ interface.mtu }}
  143. {%- endif %}
  144. - makedirs: True
  145. - require:
  146. - file: /etc/systemd/system/ifup@{{ interface_name }}.service.d/override.conf
  147. {%- endif %}
  148. {%- elif interface.type == 'dpdk_ovs_port' and interface.bridge is defined %}
  149. linux_network_dpdk_bridge_port_interface_{{ interface_name }}:
  150. cmd.run:
  151. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} add-port {{ interface.bridge }} {{ interface_name }} -- set Interface {{ interface_name }} type=dpdk options:dpdk-devargs={{ interface.pci }}"
  152. - unless: "ovs-vsctl list-ports {{ interface.bridge }} | grep -w {{ interface_name }}"
  153. - require:
  154. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  155. {%- endif %}
  156. {# Multiqueue n_rxq, pmd_rxq_affinity and mtu setup on interfaces #}
  157. {%- if interface.type == 'dpdk_ovs_port' %}
  158. {%- if interface.n_rxq is defined %}
  159. linux_network_dpdk_bridge_port_interface_n_rxq_{{ interface_name }}:
  160. cmd.run:
  161. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} options:n_rxq={{ interface.n_rxq }} "
  162. - unless: |
  163. ovs-vsctl get Interface {{ interface_name }} options | grep 'n_rxq="{{ interface.n_rxq }}"'
  164. {%- if interface.get("bond", "") != "" %}
  165. - require:
  166. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  167. {%- endif %}
  168. {%- endif %}
  169. {%- if interface.pmd_rxq_affinity is defined %}
  170. linux_network_dpdk_bridge_port_interface_pmd_rxq_affinity_{{ interface_name }}:
  171. cmd.run:
  172. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} other_config:pmd-rxq-affinity={{ interface.pmd_rxq_affinity }} "
  173. - unless: |
  174. ovs-vsctl get Interface {{ interface_name }} other_config | grep 'pmd-rxq-affinity="{{ interface.pmd_rxq_affinity }}"'
  175. {%- if interface.get("bond", "") != "" %}
  176. - require:
  177. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  178. {%- endif %}
  179. {%- endif %}
  180. {%- if interface.mtu is defined %}
  181. {# MTU ovs dpdk setup on interfaces #}
  182. linux_network_dpdk_bridge_port_interface_mtu_{{ interface_name }}:
  183. cmd.run:
  184. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} mtu_request={{ interface.mtu }} "
  185. - unless: "ovs-vsctl get Interface {{ interface_name }} mtu_request | grep {{ interface.mtu }}"
  186. {%- if interface.get("bond", "") != "" %}
  187. - require:
  188. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  189. {%- endif %}
  190. {%- endif %}
  191. {%- endif %}
  192. {%- endfor %}
  193. {%- endif %}