passing arguments dict to componenets instead of **kwargs

This commit is contained in:
ahmadbilalkhalid 2020-01-10 15:45:48 +05:00
commit 31ec024be6
7 changed files with 18 additions and 44 deletions

View file

@ -3,23 +3,16 @@ import logging
import sys
import importlib
import argparse
import multiprocessing as mp
from uncloud import UncloudException
from contextlib import suppress
# the components that use etcd
ETCD_COMPONENTS= ['api',
'scheduler',
'host',
'filescanner',
'imagescanner',
'metadata',
'configure' ]
ETCD_COMPONENTS = ['api', 'scheduler', 'host', 'filescanner', 'imagescanner', 'metadata', 'configure']
ALL_COMPONENTS = ETCD_COMPONENTS.copy()
ALL_COMPONENTS.append('cli')
def exception_hook(exc_type, exc_value, exc_traceback):
logging.getLogger(__name__).error(
'Uncaught exception',
@ -44,12 +37,9 @@ if __name__ == '__main__':
etcd_parser = argparse.ArgumentParser(add_help=False)
etcd_parser.add_argument('--etcd-host')
etcd_parser.add_argument('--etcd-port')
etcd_parser.add_argument('--etcd-ca-cert',
help="CA that signed the etcd certificate")
etcd_parser.add_argument('--etcd-cert-cert',
help="Path to client certificate")
etcd_parser.add_argument('--etcd-cert-key',
help="Path to client certificate key")
etcd_parser.add_argument('--etcd-ca-cert', help='CA that signed the etcd certificate')
etcd_parser.add_argument('--etcd-cert-cert', help='Path to client certificate')
etcd_parser.add_argument('--etcd-cert-key', help='Path to client certificate key')
for component in ALL_COMPONENTS:
mod = importlib.import_module('uncloud.{}.main'.format(component))
@ -60,19 +50,13 @@ if __name__ == '__main__':
else:
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser])
args = arg_parser.parse_args()
if not args.command:
arg_parser.print_help()
else:
# if we start etcd in seperate process with default settings
# i.e inheriting few things from parent process etcd3 module
# errors out, so the following command configure multiprocessing
# module to not inherit anything from parent.
# mp.set_start_method('spawn')
arguments = vars(args)
print(arguments)
print(etcd_parser)
# print(arguments)
# print(etcd_parser)
name = arguments.pop('command')
mod = importlib.import_module('uncloud.{}.main'.format(name))