summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2022-03-27 22:50:35 +0300
committerMaxim Devaev <[email protected]>2022-03-27 22:50:35 +0300
commit056f0693466104180beb201b9eb45ff0d04babca (patch)
tree95133f38bdcd7b46f43af7a23471cc886aed9e76 /kvmd
parent8775cd22860a21d5b93dc3c691e25d33571e02eb (diff)
removed unused network code and simplified configs
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py20
-rw-r--r--kvmd/apps/kvmd/http.py22
-rw-r--r--kvmd/apps/kvmd/streamer.py12
-rw-r--r--kvmd/clients/kvmd.py9
-rw-r--r--kvmd/clients/streamer.py10
5 files changed, 18 insertions, 55 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index 59490fc5..521c73db 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -343,9 +343,7 @@ def _get_config_scheme() -> Dict:
"kvmd": {
"server": {
- "host": Option("localhost", type=valid_ip_or_host),
- "port": Option(0, type=valid_port),
- "unix": Option("", type=valid_abs_path, only_if="!port", unpack_as="unix_path"),
+ "unix": Option("/run/kvmd/kvmd.sock", type=valid_abs_path, unpack_as="unix_path"),
"unix_rm": Option(True, type=valid_bool),
"unix_mode": Option(0o660, type=valid_unix_mode),
"heartbeat": Option(15.0, type=valid_float_f01),
@@ -447,9 +445,7 @@ def _get_config_scheme() -> Dict:
"max": Option(60, type=valid_stream_h264_gop, unpack_as="h264_gop_max"),
},
- "host": Option("localhost", type=valid_ip_or_host),
- "port": Option(0, type=valid_port),
- "unix": Option("", type=valid_abs_path, only_if="!port", unpack_as="unix_path"),
+ "unix": Option("/run/kvmd/ustreamer.sock", type=valid_abs_path, unpack_as="unix_path"),
"timeout": Option(2.0, type=valid_float_f01),
"process_name_prefix": Option("kvmd/streamer"),
@@ -600,9 +596,7 @@ def _get_config_scheme() -> Dict:
},
"kvmd": {
- "host": Option("localhost", type=valid_ip_or_host),
- "port": Option(0, type=valid_port),
- "unix": Option("", type=valid_abs_path, only_if="!port", unpack_as="unix_path"),
+ "unix": Option("/run/kvmd/kvmd.sock", type=valid_abs_path, unpack_as="unix_path"),
"timeout": Option(5.0, type=valid_float_f01),
},
@@ -646,16 +640,12 @@ def _get_config_scheme() -> Dict:
},
"kvmd": {
- "host": Option("localhost", type=valid_ip_or_host),
- "port": Option(0, type=valid_port),
- "unix": Option("", type=valid_abs_path, only_if="!port", unpack_as="unix_path"),
+ "unix": Option("/run/kvmd/kvmd.sock", type=valid_abs_path, unpack_as="unix_path"),
"timeout": Option(5.0, type=valid_float_f01),
},
"streamer": {
- "host": Option("localhost", type=valid_ip_or_host),
- "port": Option(0, type=valid_port),
- "unix": Option("", type=valid_abs_path, only_if="!port", unpack_as="unix_path"),
+ "unix": Option("/run/kvmd/ustreamer.sock", type=valid_abs_path, unpack_as="unix_path"),
"timeout": Option(5.0, type=valid_float_f01),
},
diff --git a/kvmd/apps/kvmd/http.py b/kvmd/apps/kvmd/http.py
index f2d73ad9..797d32dc 100644
--- a/kvmd/apps/kvmd/http.py
+++ b/kvmd/apps/kvmd/http.py
@@ -215,34 +215,26 @@ def set_request_auth_info(request: BaseRequest, info: str) -> None:
class HttpServer:
def run(
self,
- host: str,
- port: int,
unix_path: str,
unix_rm: bool,
unix_mode: int,
access_log_format: str,
) -> None:
- assert port or unix_path
- if unix_path:
- socket_kwargs: Dict = {}
- if unix_rm and os.path.exists(unix_path):
- os.remove(unix_path)
- server_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- server_socket.bind(unix_path)
- if unix_mode:
- os.chmod(unix_path, unix_mode)
- socket_kwargs = {"sock": server_socket}
- else:
- socket_kwargs = {"host": host, "port": port}
+ if unix_rm and os.path.exists(unix_path):
+ os.remove(unix_path)
+ server_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ server_socket.bind(unix_path)
+ if unix_mode:
+ os.chmod(unix_path, unix_mode)
run_app(
+ sock=server_socket,
app=self._make_app(),
shutdown_timeout=1,
access_log_format=access_log_format,
print=self.__run_app_print,
loop=asyncio.get_event_loop(),
- **socket_kwargs,
)
async def _make_app(self) -> Application:
diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py
index 68195fa4..357403ec 100644
--- a/kvmd/apps/kvmd/streamer.py
+++ b/kvmd/apps/kvmd/streamer.py
@@ -182,8 +182,6 @@ class Streamer: # pylint: disable=too-many-instance-attributes
shutdown_delay: float,
state_poll: float,
- host: str,
- port: int,
unix_path: str,
timeout: float,
@@ -200,9 +198,6 @@ class Streamer: # pylint: disable=too-many-instance-attributes
self.__shutdown_delay = shutdown_delay
self.__state_poll = state_poll
- assert port or unix_path
- self.__host = host
- self.__port = port
self.__unix_path = unix_path
self.__timeout = timeout
@@ -402,16 +397,15 @@ class Streamer: # pylint: disable=too-many-instance-attributes
if not self.__http_session:
kwargs: Dict = {
"headers": {"User-Agent": htclient.make_user_agent("KVMD")},
+ "connector": aiohttp.UnixConnector(path=self.__unix_path),
"timeout": aiohttp.ClientTimeout(total=self.__timeout),
}
- if self.__unix_path:
- kwargs["connector"] = aiohttp.UnixConnector(path=self.__unix_path)
self.__http_session = aiohttp.ClientSession(**kwargs)
return self.__http_session
def __make_url(self, handle: str) -> str:
assert not handle.startswith("/"), handle
- return f"http://{self.__host}:{self.__port}/{handle}"
+ return f"http://localhost:0/{handle}"
# =====
@@ -452,8 +446,6 @@ class Streamer: # pylint: disable=too-many-instance-attributes
assert self.__streamer_proc is None
cmd = [
part.format(
- host=self.__host,
- port=self.__port,
unix=self.__unix_path,
process_name_prefix=self.__process_name_prefix,
**self.__params.get_params(),
diff --git a/kvmd/clients/kvmd.py b/kvmd/clients/kvmd.py
index d3d91094..84576fb2 100644
--- a/kvmd/clients/kvmd.py
+++ b/kvmd/clients/kvmd.py
@@ -245,15 +245,11 @@ class KvmdClientSession:
class KvmdClient:
def __init__(
self,
- host: str,
- port: int,
unix_path: str,
timeout: float,
user_agent: str,
) -> None:
- self.__host = host
- self.__port = port
self.__unix_path = unix_path
self.__timeout = timeout
self.__user_agent = user_agent
@@ -271,12 +267,11 @@ class KvmdClient:
"X-KVMD-Passwd": passwd,
"User-Agent": self.__user_agent,
},
+ "connector": aiohttp.UnixConnector(path=self.__unix_path),
"timeout": aiohttp.ClientTimeout(total=self.__timeout),
}
- if self.__unix_path:
- kwargs["connector"] = aiohttp.UnixConnector(path=self.__unix_path)
return aiohttp.ClientSession(**kwargs)
def __make_url(self, handle: str) -> str:
assert not handle.startswith("/"), handle
- return f"http://{self.__host}:{self.__port}/{handle}"
+ return f"http://localhost:0/{handle}"
diff --git a/kvmd/clients/streamer.py b/kvmd/clients/streamer.py
index 35006ede..dd4167f9 100644
--- a/kvmd/clients/streamer.py
+++ b/kvmd/clients/streamer.py
@@ -71,17 +71,12 @@ class HttpStreamerClient(BaseStreamerClient):
def __init__(
self,
name: str,
- host: str,
- port: int,
unix_path: str,
timeout: float,
user_agent: str,
) -> None:
- assert port or unix_path
self.__name = name
- self.__host = host
- self.__port = port
self.__unix_path = unix_path
self.__timeout = timeout
self.__user_agent = user_agent
@@ -125,18 +120,17 @@ class HttpStreamerClient(BaseStreamerClient):
def __make_http_session(self) -> aiohttp.ClientSession:
kwargs: Dict = {
"headers": {"User-Agent": self.__user_agent},
+ "connector": aiohttp.UnixConnector(path=self.__unix_path),
"timeout": aiohttp.ClientTimeout(
connect=self.__timeout,
sock_read=self.__timeout,
),
}
- if self.__unix_path:
- kwargs["connector"] = aiohttp.UnixConnector(path=self.__unix_path)
return aiohttp.ClientSession(**kwargs)
def __make_url(self, handle: str) -> str:
assert not handle.startswith("/"), handle
- return f"http://{self.__host}:{self.__port}/{handle}"
+ return f"http://localhost:0/{handle}"
def __patch_stream_reader(self, reader: aiohttp.StreamReader) -> None:
# https://github.com/pikvm/pikvm/issues/92