浏览代码

network: Don't try to generate loopback IPs if primary IPS are set or no node_id is present.

  This is compatibility glue for nodes not migrated to netbox yet. All nodes
  configured via netbox have IPs configured on the »lo« interface explicitly
  and none have to be generated. Some nodes don't have any unicast IPs on lo
  at all.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm 4 年之前
父节点
当前提交
037baa25a4
共有 2 个文件被更改,包括 16 次插入5 次删除
  1. 10 0
      _modules/ffho_net.py
  2. 6 5
      network/interfaces/interfaces.tmpl

+ 10 - 0
_modules/ffho_net.py

@@ -711,6 +711,16 @@ def _generate_ffrl_gre_tunnels (ifaces):
 				pass
 
 def _generate_loopback_ips (ifaces, node_config, node_id):
+	# If this node has primary_ips set and filled there are either IPs
+	# configured on lo or IPs on another interface - possibly ones on
+	# the only interface present - are considered as primary IPs.
+	if node_config.get ('primary_ips', False):
+		return
+
+	# If no node_id was set, there's nothing to do here.
+	if not node_id:
+		return
+
 	v4_ip = "%s/32"  % get_loopback_ip (node_config, node_id, 'v4')
 	v6_ip = "%s/128" % get_loopback_ip (node_config, node_id, 'v6')
 

+ 6 - 5
network/interfaces/interfaces.tmpl

@@ -12,15 +12,16 @@
 {#
  # Configure any secondary IPs / router_id on loopback, if present
  #}
-{%- set lo_prefixes = ifaces['lo']['prefixes'] %}
 # The loopback network interface
 auto lo
 iface lo
-{%- for prefix in lo_prefixes %}
-  {%- set mask = '128' if ':' in prefix else '32' %}
-  {%- set prefix = prefix if '/' in prefix else prefix ~ '/' ~ mask %}
+{%- if 'lo' in ifaces %}
+  {%- for prefix in ifaces['lo']['prefixes'] %}
+    {%- set mask = '128' if ':' in prefix else '32' %}
+    {%- set prefix = prefix if '/' in prefix else prefix ~ '/' ~ mask %}
 	address {{ prefix }}
-{%- endfor %}
+  {%- endfor %}
+{%- endif %}
 
 
 {#