Browse Source

interfaces: Configure tagged VM interfaces on the host automatically

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm 1 year ago
parent
commit
c2a5cb7532
2 changed files with 19 additions and 0 deletions
  1. 9 0
      network/interfaces/interfaces.tmpl
  2. 10 0
      network/interfaces/vm_interfaces.tmpl

+ 9 - 0
network/interfaces/interfaces.tmpl

@@ -7,6 +7,7 @@
 {%- set sites_config = salt['pillar.get']('sites', {}) %}
 {%- set ifaces = salt['ffho_net.get_interface_config'](node_config, sites_config) %}
 {%- set iface_list = salt['ffho_net.get_interface_list'](ifaces) %}
+{%- set vms = node_config.get ('vms') %}
 
 #source /etc/network/interfaces.d/*
 
@@ -93,3 +94,11 @@ iface {{ interface }}
  # OpenVPN VPNs (if any)
  #}
 {%- include "network/interfaces/openvpn.tmpl" %}
+
+
+{#-
+ # VM interfaces (if any)
+ #}
+{%- if vms %}
+  {%- include "network/interfaces/vm_interfaces.tmpl" with context %}
+{%- endif %}

+ 10 - 0
network/interfaces/vm_interfaces.tmpl

@@ -0,0 +1,10 @@
+{%- for vm_fqdn, vm_cfg in vms.items ()|sort %}
+  {%- set vm_name = vm_fqdn.split ('.')[0].split ('-')[0] %}
+  {%- for vm_iface, iface_cfg in vm_cfg['ifaces'].items ()|sort %}
+    {%- if iface_cfg.get ('vlan-mode') == 'tagged' and iface_cfg.get ('tagged_vlans') %}
+      {%- set host_iface = "%s_%s" % (vm_name, vm_iface.replace ('vlan', 'v')) %}
+iface {{ host_iface }}
+	bridge-vids {{ iface_cfg.get ('tagged_vlans')|join (' ') }}
+    {%- endif %}
+  {%- endfor %}
+{%- endfor %}