diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py index cbd56d1961ddeb65cca193e761422f34171d306f..2d1c5e8cb35de378989031f33329e8db53503889 100644 --- a/gso/utils/helpers.py +++ b/gso/utils/helpers.py @@ -75,9 +75,9 @@ def available_interfaces_choices(router_id: UUID, speed: str) -> Choice | None: def available_interfaces_choices_including_current_members( - router_id: UUID, - speed: str, - interfaces: list[IptrunkInterfaceBlock], + router_id: UUID, + speed: str, + interfaces: list[IptrunkInterfaceBlock], ) -> Choice | None: """Return a list of available interfaces for a given router and speed including the current members. @@ -263,3 +263,31 @@ class BaseSiteValidatorModel(BaseModel): """ validate_site_name(site_name) return site_name + + +def validate_interface_name_list(interface_name_list: list) -> list: + """Validate 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'. + + Args: + ---- + interface_name_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)): + error_msg = ( + f"Invalid interface name. The interface name should be of format: " + f"xe-1/0/0. Got: [{interface_name}]") + raise ValueError(error_msg) + + return interface_name_list