소스 검색

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 %}
 
 
 {#