summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-08 12:58:09 +0300
committerDevaev Maxim <[email protected]>2020-09-08 12:58:09 +0300
commit081797b2536149b41ca513e64c20de8ee40f5b6e (patch)
treedeabbc59534b93b04f32ac57501bbb3d84e11b43
parentd528a3002e53bb7a5b5e6d9b5385252372738fbf (diff)
refactoring
-rw-r--r--kvmd/apps/kvmd/api/info.py10
-rw-r--r--kvmd/apps/kvmd/info/__init__.py6
-rw-r--r--kvmd/apps/kvmd/server.py2
-rw-r--r--kvmd/validators/kvm.py9
4 files changed, 17 insertions, 10 deletions
diff --git a/kvmd/apps/kvmd/api/info.py b/kvmd/apps/kvmd/api/info.py
index b33a4b6c..5adf3974 100644
--- a/kvmd/apps/kvmd/api/info.py
+++ b/kvmd/apps/kvmd/api/info.py
@@ -27,8 +27,7 @@ from typing import List
from aiohttp.web import Request
from aiohttp.web import Response
-from ....validators import check_string_in_list
-from ....validators.basic import valid_string_list
+from ....validators.kvm import valid_info_fields
from ..info import InfoManager
@@ -54,8 +53,7 @@ class InfoApi:
def __valid_info_fields(self, request: Request) -> List[str]:
subs = self.__info_manager.get_subs()
- return (sorted(set(valid_string_list(
+ return sorted(valid_info_fields(
arg=request.query.get("fields", ",".join(subs)),
- subval=(lambda field: check_string_in_list(field, "info field", subs)),
- name="info fields list",
- ))) or subs)
+ variants=subs,
+ ) or subs)
diff --git a/kvmd/apps/kvmd/info/__init__.py b/kvmd/apps/kvmd/info/__init__.py
index 3e833aed..dcb192d9 100644
--- a/kvmd/apps/kvmd/info/__init__.py
+++ b/kvmd/apps/kvmd/info/__init__.py
@@ -20,7 +20,7 @@
# ========================================================================== #
-from typing import List
+from typing import Set
from ....yamlconf import Section
@@ -41,8 +41,8 @@ class InfoManager:
"hw": HwInfoSubmanager(**config.kvmd.info.hw._unpack()),
}
- def get_subs(self) -> List[str]:
- return list(self.__subs)
+ def get_subs(self) -> Set[str]:
+ return set(self.__subs)
def get_submanager(self, name: str) -> BaseInfoSubmanager:
return self.__subs[name]
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index cb999fb9..f50c3688 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -170,7 +170,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
],
*[
_Component(f"Info manager ({sub})", f"info_{sub}_state", info_manager.get_submanager(sub))
- for sub in info_manager.get_subs()
+ for sub in sorted(info_manager.get_subs())
],
*[
_Component("Wake-on-LAN", "wol_state", wol),
diff --git a/kvmd/validators/kvm.py b/kvmd/validators/kvm.py
index 5a4dd6c8..0374ebd8 100644
--- a/kvmd/validators/kvm.py
+++ b/kvmd/validators/kvm.py
@@ -34,6 +34,7 @@ from . import check_len
from .basic import valid_stripped_string_not_empty
from .basic import valid_number
+from .basic import valid_string_list
from .os import valid_printable_filename
@@ -51,6 +52,14 @@ def valid_msd_image_name(arg: Any) -> str:
return valid_printable_filename(arg, name="MSD image name") # pragma: nocover
+def valid_info_fields(arg: Any, variants: Set[str]) -> Set[str]:
+ return set(valid_string_list(
+ arg=str(arg).strip(),
+ subval=(lambda field: check_string_in_list(field, "info field", variants)),
+ name="info fields list",
+ ))
+
+
def valid_log_seek(arg: Any) -> int:
return int(valid_number(arg, min=0, name="log seek"))