Skip to content
Snippets Groups Projects

Feature/nat 329 interface names should validated 3

Merged Hakan Calim requested to merge feature/NAT-329-interface-names-should-validated-3 into develop
All threads resolved!
Files
9
+ 31
0
@@ -263,3 +263,34 @@ class BaseSiteValidatorModel(BaseModel):
@@ -263,3 +263,34 @@ class BaseSiteValidatorModel(BaseModel):
"""
"""
validate_site_name(site_name)
validate_site_name(site_name)
return site_name
return site_name
 
 
 
def validate_interface_name_list(interface_name_list: list, vendor: str) -> 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.
 
vendor: Router vendor to check interface names
 
 
Returns:
 
-------
 
list: The list of interface names if all match was successful, otherwise it will throw a ValueError exception.
 
"""
 
# For Nokia nothing to do
 
if vendor == RouterVendor.NOKIA:
 
return interface_name_list
 
pattern = re.compile(r"^(ge|et|xe)-[0-9]/[0-9]/[0-9]$")
 
for interface in interface_name_list:
 
if not bool(pattern.match(interface.interface_name)):
 
error_msg = (
 
f"Invalid interface name. The interface name should be of format: xe-1/0/0. "
 
f"Got: [{interface.interface_name}]"
 
)
 
raise ValueError(error_msg)
 
return interface_name_list
Loading