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.

228 lines
8.3KB

  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 | json }}
  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. {# create drop-in dpdk dependency for openvswitch-switch (ovsdb-server) #}
  38. /etc/systemd/system/openvswitch-switch.service.d/dpdk.conf:
  39. file.managed:
  40. - makedirs: true
  41. - require:
  42. - pkg: openvswitch_dpdk_pkgs
  43. - contents: |
  44. [Unit]
  45. Requires=dpdk.service
  46. After=dpdk.service
  47. {# create drop-in dpdk post-start reload of openvswitch-nonetwork #}
  48. /etc/systemd/system/dpdk.service.d/openvswitch-nonetwork.conf:
  49. file.managed:
  50. - makedirs: true
  51. - require:
  52. - pkg: openvswitch_dpdk_pkgs
  53. - contents: |
  54. [Service]
  55. ExecStartPost=/bin/systemctl restart openvswitch-nonetwork
  56. linux_network_dpdk_ovs_service:
  57. cmd.run:
  58. - name: "ovs-vsctl --no-wait set Open_vSwitch . other_config:dpdk-init=true"
  59. - require:
  60. - service: linux_network_dpdk_service
  61. - unless: 'ovs-vsctl get Open_vSwitch . other_config | grep "dpdk-init=\"true\""'
  62. {%- set ovs_options = [
  63. "pmd-cpu-mask=\""+network.openvswitch.pmd_cpu_mask+"\"",
  64. "dpdk-socket-mem=\""+network.openvswitch.dpdk_socket_mem+"\"",
  65. "dpdk-lcore-mask=\""+network.openvswitch.dpdk_lcore_mask+"\"",
  66. "dpdk-extra=\"-n "+network.openvswitch.memory_channels+" --vhost-owner libvirt-qemu:kvm --vhost-perm 0664\""
  67. ]
  68. %}
  69. {%- if network.openvswitch.get('vhost_socket_dir',{}).get('path') %}
  70. {%- do ovs_options.append("vhost-sock-dir=\""+network.openvswitch.vhost_socket_dir.path+"\"") %}
  71. {%- endif %}
  72. {%- for option in ovs_options %}
  73. linux_network_dpdk_ovs_option_{{ option }}:
  74. cmd.run:
  75. - name: 'ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Open_vSwitch . other_config:{{ option }}'
  76. - watch_in:
  77. - service: service_openvswitch
  78. - require:
  79. - cmd: linux_network_dpdk_ovs_service
  80. - unless: |
  81. ovs-vsctl get Open_vSwitch . other_config | grep '{{ option }}'
  82. {%- endfor %}
  83. openvswitch_dpdk_ovs_alternative:
  84. alternatives.remove:
  85. - name: ovs-vswitchd
  86. - path: /usr/lib/openvswitch-switch/ovs-vswitchd
  87. - require:
  88. - pkg: openvswitch_dpdk_pkgs
  89. - watch_in:
  90. - service: service_openvswitch
  91. service_openvswitch:
  92. service.running:
  93. - name: openvswitch-switch
  94. - enable: true
  95. - watch:
  96. - cmd: linux_network_dpdk_ovs_service
  97. {%- endif %}
  98. {%- for interface_name, interface in network.interface.items() if interface.get('enabled', True) %}
  99. {%- if interface.type == "dpdk_ovs_bond" %}
  100. {%- set bond_interfaces = {} %}
  101. {%- for iface_name, iface in network.interface.items() if iface.get('enabled', True) and iface.get('bond',"") == interface_name %}
  102. {#- Get list of child interfaces #}
  103. {%- do bond_interfaces.update({iface_name: iface}) %}
  104. {%- endfor %}
  105. linux_network_dpdk_bond_interface_{{ interface_name }}:
  106. cmd.run:
  107. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} add-bond {{ interface.bridge }} {{ interface_name }} {{ bond_interfaces.keys()|join(' ') }}"
  108. - unless: "ovs-vsctl list-ports {{ interface.bridge }} | grep -w {{ interface_name }}"
  109. - require:
  110. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  111. {% for iface_name, iface in bond_interfaces.items() %}
  112. linux_network_dpdk_bond_interface_{{ iface_name }}_activate:
  113. cmd.run:
  114. - 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'"
  115. - unless: "ovs-vsctl get Interface {{ iface_name }} name 1>/dev/null 2>&1"
  116. linux_network_dpdk_bond_interface_{{ iface_name }}_type:
  117. cmd.run:
  118. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ iface_name }} type=dpdk"
  119. - unless: "ovs-vsctl get interface {{ iface_name }} type | grep -w dpdk"
  120. - require:
  121. - cmd: linux_network_dpdk_bond_interface_{{ iface_name }}_activate
  122. linux_network_dpdk_bond_interface_{{ iface_name }}_options:
  123. cmd.run:
  124. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ iface_name }} options:dpdk-devargs={{ iface.pci }}"
  125. - unless: "ovs-vsctl get interface {{ iface_name }} options:dpdk-devargs | grep -w {{ iface.pci }}"
  126. - require:
  127. - cmd: linux_network_dpdk_bond_interface_{{ iface_name }}_activate
  128. {% endfor %}
  129. linux_network_dpdk_bond_mode_{{ interface_name }}:
  130. cmd.run:
  131. - 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 %}"
  132. - unless: "ovs-appctl bond/show {{ interface_name }} | grep {{ interface.mode }}"
  133. - require:
  134. - cmd: linux_network_dpdk_bond_interface_{{ interface_name }}
  135. {%- elif interface.type == 'dpdk_ovs_bridge' %}
  136. linux_network_dpdk_bridge_interface_{{ interface_name }}:
  137. cmd.run:
  138. - 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 %}"
  139. - unless: "ovs-vsctl show | grep {{ interface_name }}"
  140. {%- elif interface.type == 'dpdk_ovs_port' and interface.bridge is defined %}
  141. linux_network_dpdk_bridge_port_interface_{{ interface_name }}:
  142. cmd.run:
  143. - 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 }}"
  144. - unless: "ovs-vsctl list-ports {{ interface.bridge }} | grep -w {{ interface_name }}"
  145. - require:
  146. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  147. {%- endif %}
  148. {# Multiqueue n_rxq, pmd_rxq_affinity and mtu setup on interfaces #}
  149. {%- if interface.type == 'dpdk_ovs_port' %}
  150. {%- if interface.n_rxq is defined %}
  151. linux_network_dpdk_bridge_port_interface_n_rxq_{{ interface_name }}:
  152. cmd.run:
  153. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} options:n_rxq={{ interface.n_rxq }} "
  154. - unless: |
  155. ovs-vsctl get Interface {{ interface_name }} options | grep 'n_rxq="{{ interface.n_rxq }}"'
  156. {%- if interface.get("bond", "") != "" %}
  157. - require:
  158. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  159. {%- endif %}
  160. {%- endif %}
  161. {%- if interface.pmd_rxq_affinity is defined %}
  162. linux_network_dpdk_bridge_port_interface_pmd_rxq_affinity_{{ interface_name }}:
  163. cmd.run:
  164. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} other_config:pmd-rxq-affinity={{ interface.pmd_rxq_affinity }} "
  165. - unless: |
  166. ovs-vsctl get Interface {{ interface_name }} other_config | grep 'pmd-rxq-affinity="{{ interface.pmd_rxq_affinity }}"'
  167. {%- if interface.get("bond", "") != "" %}
  168. - require:
  169. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  170. {%- endif %}
  171. {%- endif %}
  172. {%- if interface.mtu is defined %}
  173. {# MTU ovs dpdk setup on interfaces #}
  174. linux_network_dpdk_bridge_port_interface_mtu_{{ interface_name }}:
  175. cmd.run:
  176. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} mtu_request={{ interface.mtu }} "
  177. - unless: "ovs-vsctl get Interface {{ interface_name }} mtu_request | grep {{ interface.mtu }}"
  178. {%- if interface.get("bond", "") != "" %}
  179. - require:
  180. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  181. {%- endif %}
  182. {%- endif %}
  183. {%- endif %}
  184. {%- endfor %}
  185. {%- endif %}