Browse Source

network: Rework network configuration to allow multiple suites

 The <network> state now supports multiple ifupdown-ish suites which can be
 configured via the »network:suite« entry in global pillar as well as the same
 entry within the node configuration. This allows for a smooth transition.

 The available state now behave as follows:

 »network«
   The network state will install and configured everything required to make
   networking work including a reload of the interface configuration if this
   has changed.

 »network.bootstrap«
   This state will configure systemd link files, install and configure the
   selection networking suite and write the interface configuration but will
   NOT reload it.

 »network.interfaces«
   This state will just write the interfacec configuration file.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm 11 months ago
parent
commit
0fb50928d0

+ 9 - 3
network/bootstrap.sls

@@ -1,9 +1,15 @@
 #
+# Install and configure configured network suite, configure links and install
+# /etc/network/interfaces but do not reload the interafces.
+#
 # To be called from pressed
 #
 
+# Which networ suite to configure?
+{% set default_suite = salt['pillar.get']('network:suite', 'ifupdown2') %}
+{% set suite = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':network:suite', default_suite) %}
+
 include:
  - network.link
- - network.interfaces.base
-
-
+ - network.{{ suite }}
+ - network.interfaces

+ 0 - 0
network/interfaces/ff_fix_default_route → network/ifupdown2/ff_fix_default_route


+ 0 - 0
network/interfaces/ff_fix_default_route.cron → network/ifupdown2/ff_fix_default_route.cron


+ 0 - 0
network/ifupdown2.conf → network/ifupdown2/ifupdown2.conf


+ 0 - 0
network/ifupdown2.conf.buster → network/ifupdown2/ifupdown2.conf.buster


+ 0 - 0
network/ifupdown2.conf.stretch → network/ifupdown2/ifupdown2.conf.stretch


+ 15 - 0
network/ifupdown2/init.sls

@@ -0,0 +1,15 @@
+#
+# Use ifupdown2 to manage the interfaces of this box
+#
+
+ifupdown2:
+  pkg.installed
+
+# ifupdown2 configuration
+/etc/network/ifupdown2/ifupdown2.conf:
+  file.managed:
+    - source:
+      - salt://network/ifupdown2/ifupdown2.conf.{{ grains['oscodename'] }}
+      - salt://network/ifupdown2/ifupdown2.conf
+    - require:
+      - pkg: ifupdown2

+ 49 - 0
network/ifupdown2/reload.sls

@@ -0,0 +1,49 @@
+#
+# network.ifupdown2.reload
+#
+
+# Reload interface configuration if neccessary
+ifreload:
+  cmd.wait:
+    - name: /sbin/ifreload -a
+    - watch:
+      - file: /etc/network/interfaces
+
+# If there is an interface in vrf_external, install a workaround script
+# for a bug in ifupdown2 which will sometimes drop an IPv4 default route
+# present in the kernel and not reinstall it.
+#
+# The fix script will be called every minute by cron and after ifreload
+# was called to try to minimize any downtime.
+{% set vrf = [False] %}
+{% for iface, iface_config in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces', {}).items() %}
+  {% if iface_config.get ('vrf', '') == 'vrf_external' %}
+    {% do vrf.append (True) %}
+    {% break %}
+  {% endif %}
+{% endfor %}
+
+/usr/local/sbin/ff_fix_default_route:
+{% if True in vrf %}
+  file.managed:
+    - source: salt://network/ifupdown2/ff_fix_default_route
+    - mode: 755
+  cmd.wait:
+    - require:
+      - cmd: ifreload
+      - file: /usr/local/sbin/ff_fix_default_route
+    - watch:
+      - file: /etc/network/interfaces
+{% else %}
+  file.absent
+{% endif %}
+
+/etc/cron.d/ff_fix_default_route:
+{% if True in vrf %}
+  file.managed:
+    - source: salt://network/ifupdown2/ff_fix_default_route.cron
+    - template: jinja
+{% else %}
+  file.absent
+{% endif %}
+

+ 6 - 1
network/init.sls

@@ -2,10 +2,15 @@
 # Networking
 #
 
+# Which networ suite to configure?
+{% set default_suite = salt['pillar.get']('network:suite', 'ifupdown2') %}
+{% set suite = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':network:suite', default_suite) %}
+
 include:
-  - apt
   - network.link
+  - network.{{ suite }}
   - network.interfaces
+  - network.{{ suite }}.reload
 
 network-pkg:
   pkg.installed:

+ 0 - 26
network/interfaces/base.sls

@@ -1,26 +0,0 @@
-#
-# network.interface.base
-#
-
-# Install required packets and write /etc/network/interfaces but don't apply it!
-
-ifupdown2:
-  pkg.installed
-
-# ifupdown2 configuration
-/etc/network/ifupdown2/ifupdown2.conf:
-  file.managed:
-    - source:
-      - salt://network/ifupdown2.conf.{{ grains['oscodename'] }}
-      - salt://network/ifupdown2.conf
-    - require:
-      - pkg: ifupdown2
-
-
-# Write network configuration
-/etc/network/interfaces:
- file.managed:
-    - template: jinja
-    - source: salt://network/interfaces/interfaces.tmpl
-    - require:
-      - pkg: ifupdown2

+ 5 - 49
network/interfaces/init.sls

@@ -1,54 +1,10 @@
 #
-# /etc/network/interfaces
+# network.interfaces
 #
-
-include:
- - network.interfaces.base
-
-# Reload interface configuration if neccessary
-ifreload:
-  cmd.wait:
-    - name: /sbin/ifreload -a
-    - watch:
-      - file: /etc/network/interfaces
-    - require:
-      - file: /etc/network/ifupdown2/ifupdown2.conf
-
-
-# If there is an interface in vrf_external, install a workaround script
-# for a bug in ifupdown2 which will sometimes drop an IPv4 default route
-# present in the kernel and not reinstall it.
+# Generate and install /etc/network/interfaces file
 #
-# The fix script will be called every minute by cron and after ifreload
-# was called to try to minimize any downtime.
-{% set vrf = [False] %}
-{% for iface, iface_config in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces', {}).items() %}
-  {% if iface_config.get ('vrf', '') == 'vrf_external' %}
-    {% do vrf.append(True) %}
-    {% break %}
-  {% endif %}
-{% endfor %}
-
-/usr/local/sbin/ff_fix_default_route:
-{% if True in vrf %}
-  file.managed:
-    - source: salt://network/interfaces/ff_fix_default_route
-    - mode: 755
-  cmd.wait:
-    - require:
-      - cmd: ifreload
-      - file: /usr/local/sbin/ff_fix_default_route
-    - watch:
-      - file: /etc/network/interfaces
-{% else %}
-  file.absent
-{% endif %}
 
-/etc/cron.d/ff_fix_default_route:
-{% if True in vrf %}
-  file.managed:
-    - source: salt://network/interfaces/ff_fix_default_route.cron
+/etc/network/interfaces:
+ file.managed:
     - template: jinja
-{% else %}
-  file.absent
-{% endif %}
+    - source: salt://network/interfaces/interfaces.tmpl