forked from uncloud/uncloud
begin phasing in arguments instead of **arguments
This commit is contained in:
parent
71fd0ca7d9
commit
b7596e071a
2 changed files with 35 additions and 5 deletions
|
@ -8,6 +8,17 @@ import multiprocessing as mp
|
||||||
from uncloud import UncloudException
|
from uncloud import UncloudException
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
|
|
||||||
|
# the components that use etcd
|
||||||
|
ETCD_COMPONENTS= ['api',
|
||||||
|
'scheduler',
|
||||||
|
'host',
|
||||||
|
'filescanner',
|
||||||
|
'imagescanner',
|
||||||
|
'metadata',
|
||||||
|
'configure' ]
|
||||||
|
|
||||||
|
ALL_COMPONENTS = ETCD_COMPONENTS.copy()
|
||||||
|
ALL_COMPONENTS.append('cli')
|
||||||
|
|
||||||
def exception_hook(exc_type, exc_value, exc_traceback):
|
def exception_hook(exc_type, exc_value, exc_traceback):
|
||||||
logging.getLogger(__name__).error(
|
logging.getLogger(__name__).error(
|
||||||
|
@ -30,12 +41,26 @@ if __name__ == '__main__':
|
||||||
parent_parser.add_argument('--debug', '-d', action='store_true', default=False,
|
parent_parser.add_argument('--debug', '-d', action='store_true', default=False,
|
||||||
help='More verbose logging')
|
help='More verbose logging')
|
||||||
|
|
||||||
for component in ['api', 'scheduler', 'host', 'filescanner', 'imagescanner',
|
etcd_parser = argparse.ArgumentParser(add_help=False)
|
||||||
'metadata', 'configure', 'cli']:
|
etcd_parser.add_argument('--etcd-host')
|
||||||
|
etcd_parser.add_argument('--etcd-port')
|
||||||
|
etcd_parser.add_argument('--etcd-ca-cert',
|
||||||
|
help="CA that signed the etcd certificate")
|
||||||
|
etcd_parser.add_argument('--etcd-cert-cert',
|
||||||
|
help="Path to client certificate")
|
||||||
|
etcd_parser.add_argument('--etcd-cert-key',
|
||||||
|
help="Path to client certificate key")
|
||||||
|
|
||||||
|
for component in ALL_COMPONENTS:
|
||||||
mod = importlib.import_module('uncloud.{}.main'.format(component))
|
mod = importlib.import_module('uncloud.{}.main'.format(component))
|
||||||
parser = getattr(mod, 'arg_parser')
|
parser = getattr(mod, 'arg_parser')
|
||||||
|
|
||||||
|
if component in ETCD_COMPONENTS:
|
||||||
|
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser, etcd_parser])
|
||||||
|
else:
|
||||||
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser])
|
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser])
|
||||||
|
|
||||||
|
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
if not args.command:
|
if not args.command:
|
||||||
arg_parser.print_help()
|
arg_parser.print_help()
|
||||||
|
@ -46,11 +71,13 @@ if __name__ == '__main__':
|
||||||
# module to not inherit anything from parent.
|
# module to not inherit anything from parent.
|
||||||
# mp.set_start_method('spawn')
|
# mp.set_start_method('spawn')
|
||||||
arguments = vars(args)
|
arguments = vars(args)
|
||||||
|
print(arguments)
|
||||||
|
print(etcd_parser)
|
||||||
try:
|
try:
|
||||||
name = arguments.pop('command')
|
name = arguments.pop('command')
|
||||||
mod = importlib.import_module('uncloud.{}.main'.format(name))
|
mod = importlib.import_module('uncloud.{}.main'.format(name))
|
||||||
main = getattr(mod, 'main')
|
main = getattr(mod, 'main')
|
||||||
main(**arguments)
|
main(arguments)
|
||||||
except UncloudException as err:
|
except UncloudException as err:
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -563,7 +563,10 @@ api.add_resource(ListHost, '/host/list')
|
||||||
api.add_resource(CreateNetwork, '/network/create')
|
api.add_resource(CreateNetwork, '/network/create')
|
||||||
|
|
||||||
|
|
||||||
def main(debug=False, port=None):
|
def main(arguments):
|
||||||
|
debug = arguments['debug']
|
||||||
|
port = arguments['port']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image_stores = list(
|
image_stores = list(
|
||||||
shared.etcd_client.get_prefix(
|
shared.etcd_client.get_prefix(
|
||||||
|
|
Loading…
Reference in a new issue