simplify main script

This commit is contained in:
Nico Schottelius 2019-12-08 12:28:25 +01:00
parent 9517e73233
commit cfb09c29de

View file

@ -1,49 +1,34 @@
#!/usr/bin/env python3
import argparse
import multiprocessing as mp
import logging
import importlib
from os.path import join as join_path
from ucloud.sanity_checks import check
# For the exception
import decouple
import sys
COMMANDS = ['api', 'scheduler', 'host', 'filescanner', 'imagescanner', 'metadata']
if __name__ == "__main__":
log = logging.getLogger("ucloud")
arg_parser = argparse.ArgumentParser(prog='ucloud',
description='Open Source Cloud Management Software')
arg_parser.add_argument('component',
choices=['api', 'scheduler', 'host',
'filescanner', 'imagescanner',
'metadata'])
arg_parser.add_argument('component', choices=COMMANDS)
arg_parser.add_argument('component_args', nargs='*')
args = arg_parser.parse_args()
try:
if args.component == 'api':
from ucloud.api.main import main
name = args.component
main()
elif args.component == 'host':
from ucloud.host.main import main
mod = importlib.import_module("ucloud.{}.main".format(name))
main = getattr(mod, "main")
main()
hostname = args.component_args
mp.set_start_method('spawn')
main(*hostname)
elif args.component == 'scheduler':
from ucloud.scheduler.main import main
main()
elif args.component == 'filescanner':
from ucloud.filescanner.main import main
main()
elif args.component == 'imagescanner':
from ucloud.imagescanner.main import main
main()
elif args.component == 'metadata':
from ucloud.metadata.main import main
main()
except decouple.UndefinedValueError as e:
print(e)
sys.exit(1)
except Exception as e:
logging.exception(e)