From 3d769304d735ed23090fb593e03f149416df7aca Mon Sep 17 00:00:00 2001
From: Hakan Calim <hakan.calim@fau.de>
Date: Tue, 21 Nov 2023 12:04:47 +0100
Subject: [PATCH] NAT-329 added interface names validation after merge back

---
 gso/utils/helpers.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py
index 7cd8540a5..d81c4d309 100644
--- a/gso/utils/helpers.py
+++ b/gso/utils/helpers.py
@@ -219,3 +219,28 @@ def validate_site_name(site_name: str) -> str:
         )
         raise ValueError(msg)
     return site_name
+
+
+def validate_interface_name_list(interface_name_list: list) -> list:
+    """Validates that the provided interface name matches the expected pattern.
+
+    The expected pattern for the interface name is one of 'ge', 'et', 'xe' followed by a dash '-',
+    then a digit between 0 and 9, a forward slash '/', another digit between 0 and 9,
+    another forward slash '/', and ends with a digit between 0 and 9.
+For example: 'xe-1/0/0'.
+
+    Parameters:
+    interface_name_list (list): List of interface names to validate.
+
+    Returns:
+    list: The list of interface names if all match was successfull.
+                 Otherwise it will throw a ValueError exception.
+    """
+    pattern = re.compile(r'^(ge|et|xe)-[0-9]/[0-9]/[0-9]$')
+    for interface_name in interface_name_list:
+        if not bool(pattern.match(interface_name)):
+            raise ValueError(
+                "Invalid interface name. The interface name should be of format: xe-1/0/0. Get: [{}]".
+                format(interface_name))
+
+    return interface_name_list
-- 
GitLab