Saltstack Official Linux Formula
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. 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. {%- elif interface.type == 'dpdk_ovs_port' and interface.bridge is defined %}
  122. linux_network_dpdk_bridge_port_interface_{{ interface_name }}:
  123. cmd.run:
  124. - 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 }}"
  125. - unless: "ovs-vsctl list-ports {{ interface.bridge }} | grep -w {{ interface_name }}"
  126. - require:
  127. - cmd: linux_network_dpdk_bridge_interface_{{ interface.bridge }}
  128. {%- endif %}
  129. {# Multiqueue n_rxq, pmd_rxq_affinity and mtu setup on interfaces #}
  130. {%- if interface.type == 'dpdk_ovs_port' %}
  131. {%- if interface.n_rxq is defined %}
  132. linux_network_dpdk_bridge_port_interface_n_rxq_{{ interface_name }}:
  133. cmd.run:
  134. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} options:n_rxq={{ interface.n_rxq }} "
  135. - unless: |
  136. ovs-vsctl get Interface {{ interface_name }} options | grep 'n_rxq="{{ interface.n_rxq }}"'
  137. {%- if interface.get("bond", "") != "" %}
  138. - require:
  139. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  140. {%- endif %}
  141. {%- endif %}
  142. {%- if interface.pmd_rxq_affinity is defined %}
  143. linux_network_dpdk_bridge_port_interface_pmd_rxq_affinity_{{ interface_name }}:
  144. cmd.run:
  145. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} other_config:pmd-rxq-affinity={{ interface.pmd_rxq_affinity }} "
  146. - unless: |
  147. ovs-vsctl get Interface {{ interface_name }} other_config | grep 'pmd-rxq-affinity="{{ interface.pmd_rxq_affinity }}"'
  148. {%- if interface.get("bond", "") != "" %}
  149. - require:
  150. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  151. {%- endif %}
  152. {%- endif %}
  153. {%- if interface.mtu is defined %}
  154. {# MTU ovs dpdk setup on interfaces #}
  155. linux_network_dpdk_bridge_port_interface_mtu_{{ interface_name }}:
  156. cmd.run:
  157. - name: "ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} set Interface {{ interface_name }} mtu_request={{ interface.mtu }} "
  158. - unless: "ovs-vsctl get Interface {{ interface_name }} mtu_request | grep {{ interface.mtu }}"
  159. {%- if interface.get("bond", "") != "" %}
  160. - require:
  161. - cmd: linux_network_dpdk_bond_interface_{{ interface.get("bond", "") }}
  162. {%- endif %}
  163. {%- endif %}
  164. {%- endif %}
  165. {%- endfor %}
  166. {%- endif %}