Browse Source

Updated to use location info provided by netbox and lot's of old changes.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm 5 years ago
parent
commit
3b62b81b40
2 changed files with 58 additions and 24 deletions
  1. 58 21
      respondd/init.sls
  2. 0 3
      respondd/respondd-config.tmpl

+ 58 - 21
respondd/init.sls

@@ -18,6 +18,9 @@ ffho-respondd:
       - python3-netifaces
   git.latest:
    - name: https://git.ffho.net/FreifunkHochstift/ffho-respondd.git
+   - rev: dev
+   - branch: dev
+   - force_fetch: True
    - target: /srv/ffho-respondd
    - require:
      - file: /srv/ffho-respondd
@@ -35,34 +38,56 @@ ffho-respondd:
 {% set device_no = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':id', -1) %}
 {% for site in sites_node %}
   {% set site_no = salt['pillar.get']('sites:' ~ site ~ ':site_no') %}
-  {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, 'dummy') %}
+  {% set mac_address = salt['ffho_net.gen_batman_iface_mac'](site_no, device_no, 'bat') %}
+  {% set region_code = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':location:region:code', salt['pillar.get']('nodes:' ~ grains['id'] ~ ':site_code', '')) %}
 
 /srv/ffho-respondd/{{site}}.conf:
   file.managed:
     - source: salt://respondd/respondd-config.tmpl
     - template: jinja
     - defaults:
-      mac_address: {{ mac_address }}
-    {% if 'batman_ext' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
-      bat_iface: "bat-{{site}}-ext"
-    {% else %}
       bat_iface: "bat-{{site}}"
-    {% endif %}
-    {% if 'fastd_peers' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
-      fastd_peers: "true"
-    {% else %}
       fastd_peers: "false"
-    {% endif %}
-    {% if salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', [])|length > 1 %}
-      hostname: "{{grains['id'].split('.')[0]}}-{{site}}"
-    {% else %}
-      hostname: "{{grains['id'].split('.')[0]}}"
-    {% endif %}
-    {% if 'br-' ~ site in ifaces %}
-      mcast_iface: "br-{{site}}"
+      hostname: "{{grains['id'].split('.')[0]}}{% if salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', [])|length > 1 or grains.id.startswith('gw') %}-{{site}}{% endif %}"
+      mcast_iface: {% if 'br-' ~ site in ifaces %}"br-{{site}}"{% else %}"bat-{{site}}"{% endif %}
+    {% if 'fastd' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) and not 'batman_ext' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
+      mesh_vpn: [{{ site }}_intergw, {{ site }}_nodes4, {{ site }}_nodes6]
     {% else %}
-      mcast_iface: "bat-{{site}}"
+      mesh_vpn: False
     {% endif %}
+      site: {{site}}
+      site_code: "{{ region_code }}"
+      location: {{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':location', {})}}
+    - require:
+      - git: ffho-respondd
+
+{% if grains.id in ['gw05.in.ffho.net', 'bbr-upb.in.ffho.net'] and site == 'pad-cty' %}
+Stop respondd@{{site}}:
+  service.dead:
+    - name: respondd@{{site}}
+    - enable: False
+{% else %}
+respondd@{{site}}:
+  service.running:
+    - enable: True
+    - require:
+      - file: /srv/ffho-respondd/{{site}}.conf
+      - file: /etc/systemd/system/respondd@.service
+    - watch:
+      - file: /srv/ffho-respondd/{{site}}.conf
+      - git: ffho-respondd
+{% endif %}
+
+{% if 'batman_ext' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
+/srv/ffho-respondd/{{site}}-ext.conf:
+  file.managed:
+    - source: salt://respondd/respondd-config.tmpl
+    - template: jinja
+    - defaults:
+      bat_iface: "bat-{{site}}-ext"
+      fastd_peers: "{% if 'fastd_peers' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}true{% else %}false{% endif %}"
+      hostname: "{{grains['id'].split('.')[0]}}{% if salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', [])|length > 1 or grains.id.startswith('gw') %}-{{site}}{% endif %}-ext"
+      mcast_iface: "bat-{{ site }}-ext"
     {% if 'fastd' in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':roles', []) %}
       mesh_vpn: [{{ site }}_intergw, {{ site }}_nodes4, {{ site }}_nodes6]
     {% else %}
@@ -74,15 +99,16 @@ ffho-respondd:
     - require:
       - git: ffho-respondd
 
-respondd@{{site}}:
+respondd@{{site}}-ext:
   service.running:
     - enable: True
     - require:
-      - file: /srv/ffho-respondd/{{site}}.conf
+      - file: /srv/ffho-respondd/{{site}}-ext.conf
       - file: /etc/systemd/system/respondd@.service
     - watch:
-      - file: /srv/ffho-respondd/{{site}}.conf
+      - file: /srv/ffho-respondd/{{site}}-ext.conf
       - git: ffho-respondd
+{% endif %}
 {% endfor %}
 
 #
@@ -92,6 +118,10 @@ Cleanup /srv/ffho-respondd/{{site}}.conf:
   file.absent:
     - name: /srv/ffho-respondd/{{site}}.conf
 
+Cleanup /srv/ffho-respondd/{{site}}-ext.conf:
+  file.absent:
+    - name: /srv/ffho-respondd/{{site}}-ext.conf
+
 # stop respondd service
 Stop respondd@{{site}}:
   service.dead:
@@ -99,4 +129,11 @@ Stop respondd@{{site}}:
     - enable: False
     - prereq:
       - file: Cleanup /srv/ffho-respondd/{{site}}.conf
+
+Stop respondd@{{site}}-ext:
+  service.dead:
+    - name: respondd@{{site}}-ext
+    - enable: False
+    - prereq:
+      - file: Cleanup /srv/ffho-respondd/{{site}}-ext.conf
 {% endfor %}

+ 0 - 3
respondd/respondd-config.tmpl

@@ -12,9 +12,6 @@
       "longitude": {{ location.longitude }}
     },
 {%- endif %}
-    "network": {
-      "mac": "{{ mac_address }}"
-    },
     "software": {
       "firmware": {
         "release": "FFHO-1.0"