Saltstack Official Linux Formula
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

214 lines
5.8KB

  1. {%- from "linux/map.jinja" import network with context %}
  2. {%- from "linux/map.jinja" import system with context %}
  3. {%- if network.enabled %}
  4. {%- macro set_param(param_name, param_dict) -%}
  5. {%- if param_dict.get(param_name, False) -%}
  6. - {{ param_name }}: {{ param_dict[param_name] }}
  7. {%- endif -%}
  8. {%- endmacro -%}
  9. {%- if network.bridge != 'none' %}
  10. linux_network_bridge_pkgs:
  11. pkg.installed:
  12. {%- if network.bridge == 'openvswitch' %}
  13. - names: {{ network.ovs_pkgs }}
  14. {%- else %}
  15. - names: {{ network.bridge_pkgs }}
  16. {%- endif %}
  17. {%- endif %}
  18. {%- if not network.network_manager %}
  19. {# TODO stop/disable/uninstall network manager #}
  20. {%- for interface_name, interface in network.interface.iteritems() %}
  21. {%- if interface.get('managed', True) %}
  22. {%- if grains.os_family in ['RedHat', 'Debian'] %}
  23. {%- if interface.type == 'bridge' and network.bridge == 'openvswitch' %}
  24. linux_interface_{{ interface_name }}:
  25. network.managed:
  26. - enabled: {{ interface.enabled }}
  27. - name: {{ interface_name }}
  28. - type: eth
  29. {%- if interface.address is defined %}
  30. - proto: {{ interface.get('proto', 'static') }}
  31. - ipaddr: {{ interface.address }}
  32. - netmask: {{ interface.netmask }}
  33. {%- else %}
  34. - proto: {{ interface.get('proto', 'dhcp') }}
  35. {%- endif %}
  36. {%- if interface.name_servers is defined %}
  37. - dns: {{ interface.name_servers }}
  38. {%- endif %}
  39. {%- for param in network.interface_params %}
  40. {{ set_param(param, interface) }}
  41. {%- endfor %}
  42. {%- if interface.wireless is defined and grains.os_family == 'Debian' %}
  43. {%- if interface.wireless.security == "wpa" %}
  44. - wpa-ssid: {{ interface.wireless.essid }}
  45. - wpa-psk: {{ interface.wireless.key }}
  46. {%- else %}
  47. - wireless-ssid: {{ interface.wireless.essid }}
  48. - wireless-psk: {{ interface.wireless.key }}
  49. {%- endif %}
  50. {%- endif %}
  51. - require:
  52. - pkg: linux_network_bridge_pkgs
  53. {%- for network in interface.use_interfaces %}
  54. - network: linux_interface_{{ network }}
  55. {%- endfor %}
  56. linux_ovs_bridge_{{ interface_name }}:
  57. cmd.run:
  58. - name: ovs-vsctl add-br {{ interface_name }}
  59. - unless: ovs-vsctl show | grep 'Bridge {{ interface_name }}'
  60. - require:
  61. - network: linux_interface_{{ interface_name }}
  62. {%- for port in interface.use_interfaces %}
  63. linux_ovs_bridge_{{ interface_name }}_port_{{ port }}:
  64. cmd.run:
  65. - name: ovs-vsctl add-port {{ interface_name }} {{ port }}
  66. - unless: ovs-vsctl show | grep 'Interface "{{ interface_name }}"'
  67. - require:
  68. - cmd: linux_ovs_bridge_{{ interface_name }}
  69. {%- endfor %}
  70. {%- else %}
  71. linux_interface_{{ interface_name }}:
  72. network.managed:
  73. - enabled: {{ interface.enabled }}
  74. - name: {{ interface_name }}
  75. - type: {{ interface.type }}
  76. {%- if interface.address is defined %}
  77. - proto: {{ interface.get('proto', 'static') }}
  78. - ipaddr: {{ interface.address }}
  79. - netmask: {{ interface.netmask }}
  80. {%- else %}
  81. - proto: {{ interface.get('proto', 'dhcp') }}
  82. {%- endif %}
  83. {%- if interface.name_servers is defined %}
  84. - dns: {{ interface.name_servers }}
  85. {%- endif %}
  86. {%- if interface.wireless is defined and grains.os_family == 'Debian' %}
  87. {%- if interface.wireless.security == "wpa" %}
  88. - wpa-ssid: {{ interface.wireless.essid }}
  89. - wpa-psk: {{ interface.wireless.key }}
  90. {%- else %}
  91. - wireless-ssid: {{ interface.wireless.essid }}
  92. - wireless-psk: {{ interface.wireless.key }}
  93. {%- endif %}
  94. {%- endif %}
  95. {%- for param in network.interface_params %}
  96. {{ set_param(param, interface) }}
  97. {%- endfor %}
  98. {%- if interface.type == 'bridge' %}
  99. - bridge: {{ interface_name }}
  100. - delay: 0
  101. - bypassfirewall: True
  102. - use:
  103. {%- for network in interface.use_interfaces %}
  104. - network: linux_interface_{{ network }}
  105. {%- endfor %}
  106. - ports: {% for network in interface.use_interfaces %}{{ network }} {% endfor %}
  107. - require:
  108. {%- for network in interface.use_interfaces %}
  109. - network: linux_interface_{{ network }}
  110. {%- endfor %}
  111. {%- endif %}
  112. {%- if interface.type == 'bond' %}
  113. - slaves: {{ interface.slaves }}
  114. - mode: {{ interface.mode }}
  115. {%- endif %}
  116. {%- if interface.gateway is defined %}
  117. linux_system_network:
  118. network.system:
  119. - enabled: {{ interface.enabled }}
  120. - hostname: {{ network.fqdn }}
  121. {%- if interface.gateway is defined %}
  122. - gateway: {{ interface.gateway }}
  123. - gatewaydev: {{ interface_name }}
  124. {%- endif %}
  125. - nozeroconf: True
  126. - nisdomain: {{ system.domain }}
  127. - require_reboot: False
  128. {%- endif %}
  129. {%- endif %}
  130. {%- endif %}
  131. {%- if interface.wireless is defined %}
  132. {%- if grains.os_family == 'Arch' %}
  133. linux_network_packages:
  134. pkg.installed:
  135. - names: {{ network.pkgs }}
  136. /etc/netctl/network_{{ interface.wireless.essid }}:
  137. file.managed:
  138. - source: salt://linux/files/wireless
  139. - mode: 755
  140. - template: jinja
  141. - require:
  142. - pkg: linux_network_packages
  143. - defaults:
  144. interface_name: {{ interface_name }}
  145. switch_profile_{{ interface.wireless.essid }}:
  146. cmd.run:
  147. - name: netctl switch-to network_{{ interface.wireless.essid }}
  148. - cwd: /root
  149. - unless: "iwconfig {{ interface_name }} | grep -e 'ESSID:\"{{ interface.wireless.essid }}\"'"
  150. - require:
  151. - file: /etc/netctl/network_{{ interface.wireless.essid }}
  152. enable_profile_{{ interface.wireless.essid }}:
  153. cmd.run:
  154. - name: netctl enable network_{{ interface.wireless.essid }}
  155. - cwd: /root
  156. - unless: test -e /etc/systemd/system/multi-user.target.wants/netctl@network_{{ interface.wireless.essid }}.service
  157. - require:
  158. - file: /etc/netctl/network_{{ interface.wireless.essid }}
  159. {%- endif %}
  160. {%- endif %}
  161. {%- endif %}
  162. {%- if interface.route is defined %}
  163. linux_network_{{ interface_name }}_routes:
  164. network.routes:
  165. - name: {{ interface_name }}
  166. - routes:
  167. {%- for route_name, route in interface.route.iteritems() %}
  168. - name: {{ route_name }}
  169. ipaddr: {{ route.address }}
  170. netmask: {{ route.netmask }}
  171. gateway: {{ route.gateway }}
  172. {%- endfor %}
  173. {%- endif %}
  174. {%- endfor %}
  175. {%- endif %}
  176. {%- endif %}