summaryrefslogtreecommitdiff
path: root/kvmd/validators/net.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-11-29 01:35:38 +0300
committerDevaev Maxim <[email protected]>2019-11-29 01:35:38 +0300
commit3d8f16b9c60cc2ef8547e62f968b5faedf1d8094 (patch)
tree4addbab851f2ad68932d88249ea812ac74b1d957 /kvmd/validators/net.py
parent51e15d01c28556f47be849604ee5e52f18ffdd5d (diff)
wake-on-lan back
Diffstat (limited to 'kvmd/validators/net.py')
-rw-r--r--kvmd/validators/net.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/kvmd/validators/net.py b/kvmd/validators/net.py
index ce875242..79d46a15 100644
--- a/kvmd/validators/net.py
+++ b/kvmd/validators/net.py
@@ -22,6 +22,8 @@
import socket
+from typing import List
+from typing import Callable
from typing import Any
from . import check_re_match
@@ -44,15 +46,18 @@ def valid_ip_or_host(arg: Any) -> str:
)
-def valid_ip(arg: Any) -> str:
+def valid_ip(arg: Any, v4: bool=True, v6: bool=True) -> str:
+ assert v4 or v6
+ validators: List[Callable] = []
+ if v4:
+ validators.append(lambda arg: (arg, socket.inet_pton(socket.AF_INET, arg))[0])
+ if v6:
+ validators.append(lambda arg: (arg, socket.inet_pton(socket.AF_INET6, arg))[0])
name = "IP address"
return check_any(
arg=valid_stripped_string_not_empty(arg, name),
name=name,
- validators=[
- lambda arg: (arg, socket.inet_pton(socket.AF_INET, arg))[0],
- lambda arg: (arg, socket.inet_pton(socket.AF_INET6, arg))[0],
- ],
+ validators=validators,
)
@@ -65,3 +70,8 @@ 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"))
+
+
+def valid_mac(arg: Any) -> str:
+ pattern = ":".join([r"[0-9a-fA-F]{2}"] * 6)
+ return check_re_match(arg, "MAC address", pattern).lower()