Browse Source

add respondd

Karsten Böddeker 7 years ago
parent
commit
c91ec0e4e1
4 changed files with 113 additions and 0 deletions
  1. 74 0
      respondd/init.sls
  2. 26 0
      respondd/respondd-config.tmpl
  3. 12 0
      respondd/respondd@.service
  4. 1 0
      top.sls

+ 74 - 0
respondd/init.sls

@@ -0,0 +1,74 @@
+/srv/ffho-respondd:
+  file.directory
+
+ffho-respondd:
+  pkg.installed:
+    - pkgs:
+      - git
+      - lsb-release
+      - ethtool
+      - python3
+      - python3-netifaces
+  git.latest:
+   - name: https://github.com/FreifunkHochstift/ffho-respondd.git
+   - target: /srv/ffho-respondd
+   - require:
+     - file: /srv/ffho-respondd
+
+/etc/systemd/system/respondd@.service:
+  file.managed:
+    - source: salt://respondd/respondd@.service
+    - require:
+      - git: ffho-respondd
+
+{%- set node_config = salt['pillar.get']('nodes:' ~ grains['id'], {}) %}
+{%- set sites_config = salt['pillar.get']('sites', {}) %}
+
+{%- set ifaces = salt['ffho_net.get_interface_config'](node_config, sites_config) %}
+{% set device_no = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':id', -1) %}
+{% for site in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', []) %}
+  {% 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') %}
+
+/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}}"
+    {% else %}
+      mcast_iface: "bat-{{site}}"
+    {% endif %}
+      site: {{site}}
+      site_code: "{{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':site_code', '')}}"
+      location: {{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':location', {})}}
+    - require:
+      - git: ffho-respondd
+
+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
+{% endfor %}

+ 26 - 0
respondd/respondd-config.tmpl

@@ -0,0 +1,26 @@
+{
+  "batman": "{{ bat_iface }}",
+  "bridge": "{{ mcast_iface }}",
+  "mesh-vpn": ["{{ site }}_intergw", "{{ site }}_nodes4", "{{ site }}_nodes6"],
+  "nodeinfo": {
+    "hostname": "{{ hostname }}",
+{%- if location %}
+    "location": {
+      "latitude": {{ location.latitude }},
+      "longitude": {{ location.longitude }}
+    },
+{%- endif %}
+    "network": {
+      "mac": "{{ mac_address }}"
+    },
+    "software": {
+      "firmware": {
+        "release": "FFHO-1.0"
+      }
+    },
+    "system": {
+      "site_code": "{{ site_code }}"
+    },
+    "vpn": {{ fastd_peers }}
+  }
+}

+ 12 - 0
respondd/respondd@.service

@@ -0,0 +1,12 @@
+[Unit]
+Description=respondd (Site %I)
+After=syslog.target network.target
+
+[Service]
+Type=simple
+User=root
+Group=root
+ExecStart=/srv/ffho-respondd/ext-respondd.py -c /srv/ffho-respondd/%i.conf
+
+[Install]
+WantedBy=multi-user.target

+ 1 - 0
top.sls

@@ -38,6 +38,7 @@ base:
   nodes:{{ grains['id'] }}:roles:batman:
     - match: pillar
     - batman
+    - respondd
 
   # Batman gateway
   nodes:{{ grains['id'] }}:roles:batman_gw: