init.sls 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #
  2. # Fastd for gateways
  3. #
  4. {% set sites_all = pillar.get ('sites') %}
  5. {% set node_config = salt['pillar.get']('nodes:' ~ grains.id, {}) %}
  6. {% set sites_node = node_config.get('sites', {}) %}
  7. {% set device_no = node_config.get('id', -1) %}
  8. include:
  9. - apt
  10. - network.interfaces
  11. {% if 'fastd_peers' in node_config.get('roles', []) %}
  12. - fastd.peers
  13. {% endif %}
  14. # Install fastd
  15. fastd:
  16. pkg.installed:
  17. - name: fastd
  18. {% if grains.oscodename in ['jessie'] %}
  19. - fromrepo: {{ grains.oscodename }}-backports
  20. {% endif %}
  21. service.dead:
  22. - enable: False
  23. /etc/systemd/system/fastd@.service:
  24. file.managed:
  25. - source: salt://fastd/fastd@.service
  26. /etc/fastd:
  27. file.directory:
  28. - user: root
  29. - group: root
  30. - mode: 711
  31. require:
  32. - pkg: fastd
  33. #
  34. # Set up fastd configuration for every network (nodes4, nodes6, intergw-vpn)
  35. # for every site associated for the current minion ID.
  36. #
  37. {% for site in sites_all %}
  38. {% set networks_absent = [] %}
  39. {% set networks_present = [] %}
  40. {% set site_no = sites_all.get(site, {}).get('site_no') %}
  41. {% if site in sites_node %}
  42. {% do networks_present.extend(['intergw']) %}
  43. {% if 'fastd_peers' in node_config.get('roles', []) %}
  44. {% do networks_present.extend(['nodes4', 'nodes6']) %}
  45. {% else %}
  46. {% do networks_absent.extend(['nodes4', 'nodes6']) %}
  47. {% endif %}
  48. {% else %}
  49. {% do networks_absent.extend(['intergw', 'nodes4', 'nodes6']) %}
  50. {% endif %}
  51. {% for network in networks_present %}
  52. {% set network_type = 'nodes' if network.startswith ('nodes') else network %}
  53. {% set instance_name = site ~ '_' ~ network %}
  54. {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, network) %}
  55. /etc/fastd/{{ instance_name }}:
  56. file.directory:
  57. - makedirs: true
  58. - mode: 755
  59. - require:
  60. - file: /etc/fastd
  61. /etc/fastd/{{ instance_name }}/fastd.conf:
  62. file.managed:
  63. - source: salt://fastd/fastd.conf
  64. - template: jinja
  65. network: {{ network }}
  66. network_type: {{ network_type }}
  67. secret: {{ node_config.get('fastd', {}).get(network_type ~ '_privkey') }}
  68. site: {{ site }}
  69. site_no: {{ site_no }}
  70. mac_address: {{ mac_address }}
  71. {% if 'batman_ext' in node_config.get('roles', []) %}
  72. bat_iface: bat-{{ site }}-ext
  73. {% else %}
  74. bat_iface: bat-{{ site }}
  75. {% endif %}
  76. peer_limit: {{ node_config.get('fastd', {}).get('peer_limit', False) }}
  77. - require:
  78. - file: /etc/fastd/{{ instance_name }}
  79. /etc/fastd/{{ instance_name }}/secret.conf:
  80. file.absent
  81. # Create systemd start link
  82. fastd@{{ instance_name }}:
  83. service.running:
  84. - enable: True
  85. - require:
  86. - file: /etc/systemd/system/fastd@.service
  87. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  88. - service: fastd
  89. - watch:
  90. - file: /etc/fastd/{{ instance_name }}/fastd.conf
  91. {% endfor %}{# for network in networks #}
  92. #
  93. # Remove old Inter-GW peers folder
  94. /etc/fastd/{{ site }}_intergw/gateways:
  95. file.absent
  96. #
  97. # Cleanup configurations for previosly configured instances.
  98. # Stop fastd instance before purging the configuration.
  99. {% for network in networks_absent %}
  100. {% set instance_name = site ~ '_' ~ network %}
  101. Cleanup /etc/fastd/{{ instance_name }}:
  102. file.absent:
  103. - name: /etc/fastd/{{ instance_name }}
  104. # stop fastd service
  105. Stop fastd@{{ instance_name }}:
  106. service.dead:
  107. - name: fastd@{{ instance_name }}
  108. - enable: False
  109. - prereq:
  110. - file: Cleanup /etc/fastd/{{ instance_name }}
  111. {% endfor %}
  112. {% endfor %}{# for site in sites_all #}
  113. ff_fastd_con_pkgs:
  114. pkg.installed:
  115. - pkgs:
  116. - socat
  117. - jq
  118. /usr/local/bin/ff_fastd_conn:
  119. file.managed:
  120. - source: salt://fastd/ff_fastd_con
  121. - mode: 755
  122. - user: root
  123. - group: root