Parcourir la source

Move systemd link file / udev network rule generation into own state.

  network.link state will be triggered from preseed late command in the future
  so the freshly installed and bootet VM will have nicely named interfaces.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm il y a 5 ans
Parent
commit
c88192f45f
4 fichiers modifiés avec 31 ajouts et 24 suppressions
  1. 1 22
      network/init.sls
  2. 26 0
      network/link.sls
  3. 1 0
      network/systemd-link.tmpl
  4. 3 2
      network/udev-rules.tmpl

+ 1 - 22
network/init.sls

@@ -4,6 +4,7 @@
 
 include:
   - apt
+  - network.link
   - network.interfaces
 
 network-pkg:
@@ -38,28 +39,6 @@ vnstat:
     - watch_in:
       - service: vnstat
 
-# Udev rules
-/etc/udev/rules.d/42-ffho-net.rules:
-  file.managed:
-    - template: jinja
-    - source: salt://network/udev-rules.tmpl
-
-# Systemd link files?
-{% if grains['oscodename'] == 'stretch' %}
-  {% for iface, iface_config in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces', {}).items ()|sort %}
-    {% if '_udev_mac' in iface_config %}
-/etc/systemd/network/42-{{ iface }}.link:
-  file.managed:
-    - source: salt://network/systemd-link.tmpl
-    - template: jinja
-      interface: {{ iface }}
-      mac: {{ iface_config.get ('_udev_mac') }}
-      desc: {{ iface_config.get ('desc', '') }}
-    {% endif %}
-  {% endfor %}
-{% endif %}
-
-
 # /etc/resolv.conf
 /etc/resolv.conf:
   file.managed:

+ 26 - 0
network/link.sls

@@ -0,0 +1,26 @@
+#
+# Networking / link
+#
+
+{% if grains['oscodename'] == 'jessie' %}
+# Udev rules
+/etc/udev/rules.d/42-ffho-net.rules:
+  file.managed:
+    - template: jinja
+    - source: salt://network/udev-rules.tmpl
+{% endif %}
+
+# Systemd link files?
+{% if grains['oscodename'] == 'stretch' %}
+  {% for iface, iface_config in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces', {}).items ()|sort %}
+    {% if '_udev_mac' in iface_config or 'mac' in iface_config %}
+/etc/systemd/network/42-{{ iface }}.link:
+  file.managed:
+    - source: salt://network/systemd-link.tmpl
+    - template: jinja
+      interface: {{ iface }}
+      iface_config: {{ iface_config }}
+      desc: {{ iface_config.get ('desc', '') }}
+    {% endif %}
+  {% endfor %}
+{% endif %}

+ 1 - 0
network/systemd-link.tmpl

@@ -1,3 +1,4 @@
+{%- set mac = iface_config.get ('mac', iface_config.get ('_udev_mac')) -%}
 #
 # {{ interface }} / {{ desc }}
 #

+ 3 - 2
network/udev-rules.tmpl

@@ -2,9 +2,10 @@
 # FFHO net rules (Salt managed)
 #
 {%- for iface, iface_config in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':ifaces', {}).items ()|sort %}
-  {%- if '_udev_mac' in iface_config %}
+  {%- if '_udev_mac' in iface_config or 'mac' in iface_config %}
+    {%- set mac = iface_config.get ('mac', iface_config.get ('_udev_mac')) -%}
 # {{ iface_config.get ('desc', '') }}
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="{{ iface_config.get ('_udev_mac') }}", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="{{ iface }}"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="{{ mac }}", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="{{ iface }}"
 
   {%- endif %}
 {%- endfor %}