simplify main script
This commit is contained in:
parent
9517e73233
commit
cfb09c29de
1 changed files with 16 additions and 31 deletions
|
@ -1,49 +1,34 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import multiprocessing as mp
|
|
||||||
import logging
|
import logging
|
||||||
|
import importlib
|
||||||
|
|
||||||
from os.path import join as join_path
|
# For the exception
|
||||||
from ucloud.sanity_checks import check
|
import decouple
|
||||||
|
import sys
|
||||||
|
|
||||||
|
COMMANDS = ['api', 'scheduler', 'host', 'filescanner', 'imagescanner', 'metadata']
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
log = logging.getLogger("ucloud")
|
||||||
|
|
||||||
arg_parser = argparse.ArgumentParser(prog='ucloud',
|
arg_parser = argparse.ArgumentParser(prog='ucloud',
|
||||||
description='Open Source Cloud Management Software')
|
description='Open Source Cloud Management Software')
|
||||||
arg_parser.add_argument('component',
|
arg_parser.add_argument('component', choices=COMMANDS)
|
||||||
choices=['api', 'scheduler', 'host',
|
|
||||||
'filescanner', 'imagescanner',
|
|
||||||
'metadata'])
|
|
||||||
arg_parser.add_argument('component_args', nargs='*')
|
arg_parser.add_argument('component_args', nargs='*')
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if args.component == 'api':
|
name = args.component
|
||||||
from ucloud.api.main import main
|
|
||||||
|
|
||||||
main()
|
mod = importlib.import_module("ucloud.{}.main".format(name))
|
||||||
elif args.component == 'host':
|
main = getattr(mod, "main")
|
||||||
from ucloud.host.main import main
|
main()
|
||||||
|
|
||||||
hostname = args.component_args
|
except decouple.UndefinedValueError as e:
|
||||||
mp.set_start_method('spawn')
|
print(e)
|
||||||
main(*hostname)
|
sys.exit(1)
|
||||||
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 Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
|
|
Loading…
Reference in a new issue