2019-12-07 11:58:51 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import logging
|
2019-12-08 11:28:25 +00:00
|
|
|
import importlib
|
2019-12-14 15:23:31 +00:00
|
|
|
import multiprocessing as mp
|
2019-12-21 09:36:55 +00:00
|
|
|
import sys
|
|
|
|
|
2019-12-22 08:14:42 +00:00
|
|
|
from logging.handlers import SysLogHandler
|
2019-12-31 10:35:51 +00:00
|
|
|
from uncloud.configure.main import configure_parser
|
2019-12-14 15:23:31 +00:00
|
|
|
|
2019-12-31 11:15:05 +00:00
|
|
|
from uncloud import UncloudException
|
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):
|
2019-12-29 18:14:39 +00:00
|
|
|
logging.getLogger(__name__).error(
|
2019-12-22 07:26:48 +00:00
|
|
|
'Uncaught exception',
|
|
|
|
exc_info=(exc_type, exc_value, exc_traceback)
|
|
|
|
)
|
2019-12-07 11:58:51 +00:00
|
|
|
|
2019-12-22 08:47:16 +00:00
|
|
|
|
2019-12-23 07:58:04 +00:00
|
|
|
sys.excepthook = exception_hook
|
2019-12-21 09:36:55 +00:00
|
|
|
|
2019-12-29 18:14:39 +00:00
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
if __name__ == '__main__':
|
2019-12-29 18:14:39 +00:00
|
|
|
# Setting up root logger
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
2019-12-31 10:56:28 +00:00
|
|
|
logger.setLevel(logging.DEBUG)
|
2019-12-29 18:14:39 +00:00
|
|
|
|
2019-12-31 10:56:28 +00:00
|
|
|
parent_parser = argparse.ArgumentParser(add_help=False)
|
|
|
|
parent_parser.add_argument("--debug", "-d", action='store_true')
|
2019-12-29 18:14:39 +00:00
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
arg_parser = argparse.ArgumentParser()
|
2019-12-31 10:35:51 +00:00
|
|
|
|
2019-12-31 10:56:28 +00:00
|
|
|
subparsers = arg_parser.add_subparsers(dest="command")
|
2019-12-31 10:35:51 +00:00
|
|
|
|
2019-12-31 10:56:28 +00:00
|
|
|
api_parser = subparsers.add_parser("api", parents=[parent_parser])
|
2019-12-31 12:13:19 +00:00
|
|
|
api_parser.add_argument("--port", "-p")
|
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
host_parser = subparsers.add_parser("host")
|
|
|
|
host_parser.add_argument("--hostname", required=True)
|
2019-12-08 13:15:36 +00:00
|
|
|
|
2019-12-31 13:22:44 +00:00
|
|
|
scheduler_parser = subparsers.add_parser("scheduler", parents=[parent_parser])
|
|
|
|
|
2019-12-31 14:35:49 +00:00
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
filescanner_parser = subparsers.add_parser("filescanner")
|
|
|
|
imagescanner_parser = subparsers.add_parser("imagescanner")
|
2019-12-31 14:35:49 +00:00
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
metadata_parser = subparsers.add_parser("metadata")
|
2019-12-31 14:35:49 +00:00
|
|
|
metadata_parser.add_argument("--port", "-p")
|
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
config_parser = subparsers.add_parser("configure")
|
2019-12-31 10:56:28 +00:00
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
configure_parser(config_parser)
|
|
|
|
args = arg_parser.parse_args()
|
2019-12-07 11:58:51 +00:00
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
if not args.command:
|
|
|
|
arg_parser.print_help()
|
|
|
|
else:
|
2019-12-22 08:14:42 +00:00
|
|
|
|
|
|
|
# if we start etcd in seperate process with default settings
|
|
|
|
# i.e inheriting few things from parent process etcd3 module
|
|
|
|
# errors out, so the following command configure multiprocessing
|
|
|
|
# module to not inherit anything from parent.
|
2019-12-22 07:26:48 +00:00
|
|
|
mp.set_start_method('spawn')
|
|
|
|
|
2019-12-21 09:36:55 +00:00
|
|
|
arguments = vars(args)
|
|
|
|
try:
|
|
|
|
name = arguments.pop('command')
|
2019-12-31 10:35:51 +00:00
|
|
|
mod = importlib.import_module("uncloud.{}.main".format(name))
|
2019-12-21 09:36:55 +00:00
|
|
|
main = getattr(mod, "main")
|
|
|
|
main(**arguments)
|
2019-12-31 11:15:05 +00:00
|
|
|
except UncloudException as err:
|
|
|
|
logger.error(err)
|
2019-12-22 08:14:42 +00:00
|
|
|
except Exception as err:
|
|
|
|
logger.exception(err)
|