From 8c7826de450523eadb4905667747914a8483255c Mon Sep 17 00:00:00 2001 From: sagewe Date: Fri, 8 Dec 2023 17:58:12 +0800 Subject: [PATCH] add some config defaults and a tool to validate properties file Signed-off-by: sagewe --- python/eggroll/config/__main__.py | 29 +++++++++++++++++++++++ python/eggroll/config/defaults.py | 39 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 python/eggroll/config/__main__.py diff --git a/python/eggroll/config/__main__.py b/python/eggroll/config/__main__.py new file mode 100644 index 000000000..912e2318d --- /dev/null +++ b/python/eggroll/config/__main__.py @@ -0,0 +1,29 @@ +def main(): + import argparse + import configparser + import omegaconf + + from .config import Config + + arguments = argparse.ArgumentParser() + arguments.add_argument("-c", "--config", type=str, required=True) + args = arguments.parse_args() + + config = Config() + config.load_default() + c = configparser.ConfigParser() + c.read(args.config) + for k, v in c.items("eggroll"): + try: + if v == "": + omegaconf.OmegaConf.select(config.config, k) + else: + config.config = omegaconf.OmegaConf.merge( + config.config, omegaconf.OmegaConf.from_dotlist([f"{k}={v}"]) + ) + except omegaconf.errors.ConfigKeyError: + print(f"Error: {k} is not set, please add it to eggroll/config/defaults") + + +if __name__ == "__main__": + main() diff --git a/python/eggroll/config/defaults.py b/python/eggroll/config/defaults.py index 49e50b877..5f9587a59 100644 --- a/python/eggroll/config/defaults.py +++ b/python/eggroll/config/defaults.py @@ -7,6 +7,14 @@ class DefaultConfig: @dataclass class EggrollConfig: + @dataclass + class DashboardConfig: + @dataclass + class ServerConfig: + port: int = 8083 + + server: ServerConfig = ServerConfig() + @dataclass class TransferConfig: @dataclass @@ -36,6 +44,18 @@ class JdbcConfig: @dataclass class NodemanagerConfig: + @dataclass + class GpuConfig: + @dataclass + class NumConfig: + shell: str = MISSING + + num: NumConfig = NumConfig() + + @dataclass + class NetConfig: + device: str = MISSING + @dataclass class ContainersConfig: @dataclass @@ -47,6 +67,8 @@ class DataConfig: host: str = MISSING port: int = MISSING containers: ContainersConfig = ContainersConfig() + net: NetConfig = NetConfig() + gpu: GpuConfig = GpuConfig() @dataclass class ProcessConfig: @@ -350,12 +372,28 @@ class ServerConfig: @dataclass class SecurityConfig: + @dataclass + class EncryptConfig: + public_key: str = MISSING + private_key: str = MISSING + enable: bool = False + + @dataclass + class SessionConfig: + @dataclass + class ExpiredConfig: + time: int = 30 + + expired: ExpiredConfig = ExpiredConfig() + @dataclass class LoginConfig: username: str = MISSING password: str = MISSING login: LoginConfig = LoginConfig() + session: SessionConfig = SessionConfig() + encrypt: EncryptConfig = EncryptConfig() @dataclass class ContainerConfig: @@ -604,5 +642,6 @@ class RootConfig: home: str = MISSING gc: GCConfig = GCConfig() transfer: TransferConfig = TransferConfig() + dashboard: DashboardConfig = DashboardConfig() eggroll: EggrollConfig = EggrollConfig()