diff options
author | Devaev Maxim <[email protected]> | 2020-10-02 07:03:46 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-10-02 07:03:46 +0300 |
commit | b2a377233d35d7fcc138bfd09a8a867644427620 (patch) | |
tree | bd0df504922ac1e9e92ad1c174912ac307877908 /kvmd/validators/net.py | |
parent | 729dc977c82dd858f16be1ef3712450db1bcc6b4 (diff) |
improved net validators
Diffstat (limited to 'kvmd/validators/net.py')
-rw-r--r-- | kvmd/validators/net.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/kvmd/validators/net.py b/kvmd/validators/net.py index 3c172e7b..4197ac8e 100644 --- a/kvmd/validators/net.py +++ b/kvmd/validators/net.py @@ -37,7 +37,7 @@ from .basic import valid_stripped_string_not_empty # ===== def valid_ip_or_host(arg: Any) -> str: - name = "IP address or RFC-1123 hostname" + name = "IPv4/6 address or RFC-1123 hostname" return check_any( arg=valid_stripped_string_not_empty(arg, name), name=name, @@ -51,11 +51,14 @@ def valid_ip_or_host(arg: Any) -> str: def valid_ip(arg: Any, v4: bool=True, v6: bool=True) -> str: assert v4 or v6 validators: List[Callable] = [] + versions: List[str] = [] if v4: validators.append(lambda arg: str(ipaddress.IPv4Address(arg))) + versions.append("4") if v6: validators.append(lambda arg: str(ipaddress.IPv6Address(arg))) - name = "IP address" + versions.append("6") + name = f"IPv{'/'.join(versions)} address" return check_any( arg=valid_stripped_string_not_empty(arg, name), name=name, @@ -71,7 +74,7 @@ def valid_rfc_host(arg: Any) -> str: def valid_port(arg: Any) -> int: - return int(valid_number(arg, min=0, max=65535, name="TCP/UDP port")) + return int(valid_number(arg, min=0, max=65535, name="network port")) def valid_mac(arg: Any) -> str: |