summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-10-02 10:22:43 +0300
committerDevaev Maxim <[email protected]>2020-10-09 03:51:19 +0300
commit5bfde6ceae5af9c47c7a86a6ee1d9fb180b39b54 (patch)
tree7d02fbc1b2170c009c4be099d1e5a75f35bc32e9 /kvmd
parent3c4d38f7551c9bd69ac4646d7704fc271e32bdc3 (diff)
otgnet stubs
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py22
-rw-r--r--kvmd/validators/net.py26
2 files changed, 48 insertions, 0 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 10a331da..a882e0d7 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -77,7 +77,9 @@ from ..validators.os import valid_command
from ..validators.net import valid_ip_or_host
from ..validators.net import valid_ip
+from ..validators.net import valid_net
from ..validators.net import valid_port
+from ..validators.net import valid_ports_list
from ..validators.net import valid_mac
from ..validators.net import valid_ssl_ciphers
@@ -426,6 +428,26 @@ def _get_config_scheme() -> Dict:
},
},
+ "otgnet": {
+ "iface": {
+ "net": Option("169.254.0.100/31", type=functools.partial(valid_net, v6=False)),
+ },
+
+ "firewall": {
+ "allow_tcp": Option([], type=valid_ports_list),
+ "allow_udp": Option([], type=valid_ports_list),
+ },
+
+ "dhcp": {
+ "enabled": Option(True, type=valid_bool),
+ },
+
+ "commands": {
+ "ip_cmd": Option(["/usr/bin/ip"], type=valid_command),
+ "iptables_cmd": Option(["/usr/bin/iptables"], type=valid_command),
+ },
+ },
+
"ipmi": {
"server": {
"host": Option("::", type=valid_ip_or_host),
diff --git a/kvmd/validators/net.py b/kvmd/validators/net.py
index 4197ac8e..f4019272 100644
--- a/kvmd/validators/net.py
+++ b/kvmd/validators/net.py
@@ -28,11 +28,13 @@ from typing import Callable
from typing import Any
from . import ValidatorError
+from . import raise_error
from . import check_re_match
from . import check_any
from .basic import valid_number
from .basic import valid_stripped_string_not_empty
+from .basic import valid_string_list
# =====
@@ -66,6 +68,26 @@ def valid_ip(arg: Any, v4: bool=True, v6: bool=True) -> str:
)
+def valid_net(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.IPv4Network(arg)))
+ versions.append("4")
+ if v6:
+ validators.append(lambda arg: str(ipaddress.IPv6Network(arg)))
+ versions.append("6")
+ name = f"IPv{'/'.join(versions)} network"
+ if "/" not in str(arg):
+ raise_error(arg, name)
+ return check_any(
+ arg=valid_stripped_string_not_empty(arg, name),
+ name=name,
+ validators=validators,
+ )
+
+
def valid_rfc_host(arg: Any) -> str:
# http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address
pattern = r"^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*" \
@@ -77,6 +99,10 @@ def valid_port(arg: Any) -> int:
return int(valid_number(arg, min=0, max=65535, name="network port"))
+def valid_ports_list(arg: Any) -> List[int]:
+ return list(map(int, valid_string_list(arg, subval=valid_port, name="ports list")))
+
+
def valid_mac(arg: Any) -> str:
pattern = ":".join([r"[0-9a-fA-F]{2}"] * 6)
return check_re_match(arg, "MAC address", pattern).lower()