diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py index 385096c8aa21c0a26dd17b5811478580a43c5132..1a54386af4fd21beb8284c9b2ef06da632a378a9 100644 --- a/gso/utils/helpers.py +++ b/gso/utils/helpers.py @@ -151,3 +151,17 @@ def validate_iptrunk_unique_interface(interfaces: list[LAGMember]) -> list[LAGMe if len(interface_names) != len(set(interface_names)): raise ValueError("Interfaces must be unique.") return interfaces + + +def validate_site_name(site_name: str) -> str: + """Accepts only three capital letters and optional a digit after the capital letters for the sitename. + + The site names can have the format like this: AMS, LON, LON0...LON9 + """ + + # Accept 3 chapital letters and only one ditigt after capital letters. + pattern = re.compile(r"^[A-Z]{3}[0-9]?$") + if not bool(pattern.match(site_name)): + raise ValueError(f"Enter a valid site name similar looks like AMS, AMS1or LON9. Get: {site_name}") + + return site_name