uncloud-mravi/scripts/ucloud

63 lines
No EOL
1.8 KiB
Python
Executable file

#!/usr/bin/env python3
import argparse
import logging
import importlib
import multiprocessing as mp
import sys
from ucloud.configure.main import configure_parser
def exception_hook(exc_type, exc_value, exc_traceback):
logger.error(
'Uncaught exception',
exc_info=(exc_type, exc_value, exc_traceback)
)
print('Error: ', end='')
print(exc_type, exc_value, exc_traceback)
if __name__ == '__main__':
sys.excepthook = exception_hook
arg_parser = argparse.ArgumentParser()
subparsers = arg_parser.add_subparsers(dest="command")
api_parser = subparsers.add_parser("api")
host_parser = subparsers.add_parser("host")
host_parser.add_argument("--hostname", required=True)
scheduler_parser = subparsers.add_parser("scheduler")
filescanner_parser = subparsers.add_parser("filescanner")
imagescanner_parser = subparsers.add_parser("imagescanner")
metadata_parser = subparsers.add_parser("metadata")
config_parser = subparsers.add_parser("configure")
configure_parser(config_parser)
args = arg_parser.parse_args()
if not args.command:
arg_parser.print_help()
else:
logging.basicConfig(
level=logging.DEBUG,
format='%(pathname)s:%(lineno)d -- %(levelname)-8s %(message)s',
handlers=[logging.handlers.SysLogHandler(address = '/dev/log')]
)
logger = logging.getLogger("ucloud")
mp.set_start_method('spawn')
arguments = vars(args)
try:
name = arguments.pop('command')
mod = importlib.import_module("ucloud.{}.main".format(name))
main = getattr(mod, "main")
main(**arguments)
except Exception as e:
logger.exception('Error')
print(e)