additional cmd options

This commit is contained in:
Devaev Maxim 2021-02-16 09:07:51 +03:00
parent 70fb46d428
commit 3e289262f8
4 changed files with 37 additions and 12 deletions

View File

@ -516,7 +516,10 @@ def _get_config_scheme() -> Dict:
}, },
"commands": { "commands": {
"pre_start_cmd": Option(["/bin/true", "pre-start"], type=valid_command), "pre_start_cmd": Option(["/bin/true", "pre-start"], type=valid_command),
"pre_start_cmd_remove": Option([], type=valid_options),
"pre_start_cmd_append": Option([], type=valid_options),
"post_start_cmd": Option([ "post_start_cmd": Option([
"/usr/bin/systemd-run", "/usr/bin/systemd-run",
"--unit=kvmd-otgnet-dnsmasq", "--unit=kvmd-otgnet-dnsmasq",
@ -532,12 +535,20 @@ def _get_config_scheme() -> Dict:
"--dhcp-option=6", "--dhcp-option=6",
"--keep-in-foreground", "--keep-in-foreground",
], type=valid_command), ], type=valid_command),
"pre_stop_cmd": Option([ "post_start_cmd_remove": Option([], type=valid_options),
"post_start_cmd_append": Option([], type=valid_options),
"pre_stop_cmd": Option([
"/usr/bin/systemctl", "/usr/bin/systemctl",
"stop", "stop",
"kvmd-otgnet-dnsmasq", "kvmd-otgnet-dnsmasq",
], type=valid_command), ], type=valid_command),
"post_stop_cmd": Option(["/bin/true", "post-stop"], type=valid_command), "pre_stop_cmd_remove": Option([], type=valid_options),
"pre_stop_cmd_append": Option([], type=valid_options),
"post_stop_cmd": Option(["/bin/true", "post-stop"], type=valid_command),
"post_stop_cmd_remove": Option([], type=valid_options),
"post_stop_cmd_append": Option([], type=valid_options),
}, },
}, },

View File

@ -179,11 +179,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
self.__process_name_prefix = process_name_prefix self.__process_name_prefix = process_name_prefix
self.__cmd = [ self.__cmd = tools.build_cmd(cmd, cmd_remove, cmd_append)
cmd[0], # Executable
*filter((lambda item: item not in cmd_remove), cmd[1:]),
*cmd_append,
]
self.__params = _StreamerParams(**params_kwargs) self.__params = _StreamerParams(**params_kwargs)

View File

@ -35,6 +35,7 @@ from ...logging import get_logger
from ...yamlconf import Section from ...yamlconf import Section
from ... import env from ... import env
from ... import tools
from ... import aioproc from ... import aioproc
from .. import init from .. import init
@ -74,10 +75,17 @@ class _Service: # pylint: disable=too-many-instance-attributes
self.__forward_iface: str = config.otgnet.firewall.forward_iface self.__forward_iface: str = config.otgnet.firewall.forward_iface
self.__iptables_cmd: List[str] = config.otgnet.firewall.iptables_cmd self.__iptables_cmd: List[str] = config.otgnet.firewall.iptables_cmd
self.__pre_start_cmd: List[str] = config.otgnet.commands.pre_start_cmd def build_cmd(key: str) -> List[str]:
self.__post_start_cmd: List[str] = config.otgnet.commands.post_start_cmd return tools.build_cmd(
self.__pre_stop_cmd: List[str] = config.otgnet.commands.pre_stop_cmd getattr(config.otgnet.commands, key),
self.__post_stop_cmd: List[str] = config.otgnet.commands.post_stop_cmd getattr(config.otgnet.commands, f"{key}_remove"),
getattr(config.otgnet.commands, f"{key}_append"),
)
self.__pre_start_cmd: List[str] = build_cmd("pre_start_cmd")
self.__post_start_cmd: List[str] = build_cmd("post_start_cmd")
self.__pre_stop_cmd: List[str] = build_cmd("pre_stop_cmd")
self.__post_stop_cmd: List[str] = build_cmd("post_stop_cmd")
self.__gadget: str = config.otg.gadget self.__gadget: str = config.otg.gadget
self.__driver: str = config.otg.devices.ethernet.driver self.__driver: str = config.otg.devices.ethernet.driver

View File

@ -73,3 +73,13 @@ def clear_queue(q: multiprocessing.queues.Queue) -> None: # pylint: disable=inv
q.get_nowait() q.get_nowait()
except queue.Empty: except queue.Empty:
break break
# =====
def build_cmd(cmd: List[str], cmd_remove: List[str], cmd_append: List[str]) -> List[str]:
assert len(cmd) >= 1, cmd
return [
cmd[0], # Executable
*filter((lambda item: item not in cmd_remove), cmd[1:]),
*cmd_append,
]