Browse Source

Move cmp() func into ffho module

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm 9 months ago
parent
commit
ca77ffe4f8
2 changed files with 17 additions and 12 deletions
  1. 11 0
      _modules/ffho.py
  2. 6 12
      _modules/ffho_net.py

+ 11 - 0
_modules/ffho.py

@@ -11,3 +11,14 @@ def is_bool (value):
 
 def any_item_in_list (items, list):
 	return len(set(items).intersection(set(list))) != 0
+
+def cmp (x, y):
+	"""
+	Most generic comparator
+	"""
+	if x < y:
+		return -1
+	elif x == y:
+		return 0
+	else:
+		return 1

+ 6 - 12
_modules/ffho_net.py

@@ -6,6 +6,8 @@ import ipaddress
 import re
 from copy import deepcopy
 
+import ffho
+
 mac_prefix = "f2"
 
 # VRF configuration map
@@ -1023,21 +1025,13 @@ def get_interface_config (node_config, sites_config, node_id = ""):
 
 vlan_vxlan_iface_re = re.compile (r'^vlan(\d+)|^vx_v(\d+)_(\w+)')
 
-def _cmp (x, y):
-	if x < y:
-		return -1
-	elif x == y:
-		return 0
-	else:
-		return 1
-
 def _iface_sort (iface_a, iface_b):
 	a = vlan_vxlan_iface_re.search (iface_a)
 	b = vlan_vxlan_iface_re.search (iface_b)
 
 	# At least one interface didn't match, do regular comparison
 	if not a or not b:
-		return _cmp (iface_a, iface_b)
+		return ffho.cmp (iface_a, iface_b)
 
 	# Extract VLAN ID from VLAN interface (if given) or VXLAN
 	vid_a = a.group (1) if a.group (1) else a.group (2)
@@ -1045,17 +1039,17 @@ def _iface_sort (iface_a, iface_b):
 
 	# If it's different type of interfaces (one VLAN, one VXLAN), do regular comparison
 	if (a.group (1) == None) != (b.group (1) == None):
-		return _cmp (iface_a, iface_b)
+		return ffho.cmp (iface_a, iface_b)
 
 	# Ok, t's two VLAN or two VXLAN interfaces
 
 	# If it's VXLAN interfaces and the VLAN ID is the same, sort by site name
 	if a.group (2) and vid_a == vid_b:
-		return _cmp (a.groups (2), b.groups (2))
+		return ffho.cmp (a.groups (2), b.groups (2))
 
 	# If it's two VLANs or two VXLANs with different VLAN IDs, sort by VLAN ID
 	else:
-		return _cmp (int (vid_a), int (vid_b))
+		return ffho.cmp (int (vid_a), int (vid_b))
 
 
 def get_interface_list (ifaces):