begin phasing in arguments instead of **arguments

This commit is contained in:
Nico Schottelius 2020-01-10 11:30:23 +01:00
parent 71fd0ca7d9
commit b7596e071a
2 changed files with 35 additions and 5 deletions

View file

@ -8,6 +8,17 @@ 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' ]
ALL_COMPONENTS = ETCD_COMPONENTS.copy()
ALL_COMPONENTS.append('cli')
def exception_hook(exc_type, exc_value, exc_traceback):
logging.getLogger(__name__).error(
@ -30,11 +41,25 @@ if __name__ == '__main__':
parent_parser.add_argument('--debug', '-d', action='store_true', default=False,
help='More verbose logging')
for component in ['api', 'scheduler', 'host', 'filescanner', 'imagescanner',
'metadata', 'configure', 'cli']:
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")
for component in ALL_COMPONENTS:
mod = importlib.import_module('uncloud.{}.main'.format(component))
parser = getattr(mod, 'arg_parser')
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser])
if component in ETCD_COMPONENTS:
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser, etcd_parser])
else:
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser])
args = arg_parser.parse_args()
if not args.command:
@ -46,11 +71,13 @@ if __name__ == '__main__':
# module to not inherit anything from parent.
# mp.set_start_method('spawn')
arguments = vars(args)
print(arguments)
print(etcd_parser)
try:
name = arguments.pop('command')
mod = importlib.import_module('uncloud.{}.main'.format(name))
main = getattr(mod, 'main')
main(**arguments)
main(arguments)
except UncloudException as err:
logger.error(err)
sys.exit(1)

View file

@ -563,7 +563,10 @@ api.add_resource(ListHost, '/host/list')
api.add_resource(CreateNetwork, '/network/create')
def main(debug=False, port=None):
def main(arguments):
debug = arguments['debug']
port = arguments['port']
try:
image_stores = list(
shared.etcd_client.get_prefix(