removed unused network code and simplified configs

This commit is contained in:
Maxim Devaev
2022-03-27 22:50:35 +03:00
parent 8775cd2286
commit 056f069346
22 changed files with 18 additions and 277 deletions

View File

@@ -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),
},

View File

@@ -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:

View File

@@ -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(),

View File

@@ -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}"

View File

@@ -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