uncloud-mravi/scripts/ucloud

62 lines
1.7 KiB
Text
Raw Normal View History

#!/usr/bin/env python3
import argparse
import logging
2019-12-08 11:28:25 +00:00
import importlib
import os
import multiprocessing as mp
2019-12-21 09:36:55 +00:00
import sys
from ucloud.configure.main import update_config, configure_parser
2019-12-08 11:28:25 +00:00
2019-12-21 09:36:55 +00:00
def exception_hook(exc_type, exc_value, exc_traceback):
logger.error(
"Uncaught exception",
exc_info=(exc_type, exc_value, exc_traceback)
)
print(exc_type, exc_value)
2019-12-21 09:36:55 +00:00
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG,
format='%(pathname)s:%(lineno)d -- %(levelname)-8s %(message)s',
filename='/var/log/ucloud.log', filemode='a')
logger = logging.getLogger("ucloud")
2019-12-08 11:28:25 +00:00
2019-12-21 09:36:55 +00:00
sys.excepthook = exception_hook
mp.set_start_method('spawn')
2019-12-21 09:36:55 +00:00
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)
2019-12-08 13:15:36 +00:00
2019-12-21 09:36:55 +00:00
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()
2019-12-21 09:36:55 +00:00
if not args.command:
arg_parser.print_help()
else:
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(e)
print(e)