passing arguments dict to componenets instead of **kwargs
This commit is contained in:
		
					parent
					
						
							
								d9dd6b48dc
							
						
					
				
			
			
				commit
				
					
						31ec024be6
					
				
			
		
					 7 changed files with 18 additions and 44 deletions
				
			
		| 
						 | 
					@ -3,23 +3,16 @@ import logging
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import importlib
 | 
					import importlib
 | 
				
			||||||
import argparse
 | 
					import argparse
 | 
				
			||||||
import multiprocessing as mp
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
from uncloud import UncloudException
 | 
					from uncloud import UncloudException
 | 
				
			||||||
from contextlib import suppress
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# the components that use etcd
 | 
					# the components that use etcd
 | 
				
			||||||
ETCD_COMPONENTS= ['api',
 | 
					ETCD_COMPONENTS = ['api', 'scheduler', 'host', 'filescanner', 'imagescanner', 'metadata', 'configure']
 | 
				
			||||||
                  'scheduler',
 | 
					 | 
				
			||||||
                  'host',
 | 
					 | 
				
			||||||
                  'filescanner',
 | 
					 | 
				
			||||||
                  'imagescanner',
 | 
					 | 
				
			||||||
                  'metadata',
 | 
					 | 
				
			||||||
                  'configure' ]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
ALL_COMPONENTS = ETCD_COMPONENTS.copy()
 | 
					ALL_COMPONENTS = ETCD_COMPONENTS.copy()
 | 
				
			||||||
ALL_COMPONENTS.append('cli')
 | 
					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(
 | 
				
			||||||
        'Uncaught exception',
 | 
					        'Uncaught exception',
 | 
				
			||||||
| 
						 | 
					@ -44,12 +37,9 @@ if __name__ == '__main__':
 | 
				
			||||||
    etcd_parser = argparse.ArgumentParser(add_help=False)
 | 
					    etcd_parser = argparse.ArgumentParser(add_help=False)
 | 
				
			||||||
    etcd_parser.add_argument('--etcd-host')
 | 
					    etcd_parser.add_argument('--etcd-host')
 | 
				
			||||||
    etcd_parser.add_argument('--etcd-port')
 | 
					    etcd_parser.add_argument('--etcd-port')
 | 
				
			||||||
    etcd_parser.add_argument('--etcd-ca-cert',
 | 
					    etcd_parser.add_argument('--etcd-ca-cert', help='CA that signed the etcd certificate')
 | 
				
			||||||
                             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-cert',
 | 
					    etcd_parser.add_argument('--etcd-cert-key', help='Path to client certificate key')
 | 
				
			||||||
                             help="Path to client certificate")
 | 
					 | 
				
			||||||
    etcd_parser.add_argument('--etcd-cert-key',
 | 
					 | 
				
			||||||
                             help="Path to client certificate key")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for component in ALL_COMPONENTS:
 | 
					    for component in ALL_COMPONENTS:
 | 
				
			||||||
        mod = importlib.import_module('uncloud.{}.main'.format(component))
 | 
					        mod = importlib.import_module('uncloud.{}.main'.format(component))
 | 
				
			||||||
| 
						 | 
					@ -60,19 +50,13 @@ if __name__ == '__main__':
 | 
				
			||||||
        else:
 | 
					        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()
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        # 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.
 | 
					 | 
				
			||||||
        # mp.set_start_method('spawn')
 | 
					 | 
				
			||||||
        arguments = vars(args)
 | 
					        arguments = vars(args)
 | 
				
			||||||
        print(arguments)
 | 
					        # print(arguments)
 | 
				
			||||||
        print(etcd_parser)
 | 
					        # print(etcd_parser)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        name = arguments.pop('command')
 | 
					        name = arguments.pop('command')
 | 
				
			||||||
        mod = importlib.import_module('uncloud.{}.main'.format(name))
 | 
					        mod = importlib.import_module('uncloud.{}.main'.format(name))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -565,7 +565,7 @@ api.add_resource(CreateNetwork, '/network/create')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main(arguments):
 | 
					def main(arguments):
 | 
				
			||||||
    debug = arguments['debug']
 | 
					    debug = arguments['debug']
 | 
				
			||||||
    port  = arguments['port']
 | 
					    port = arguments['port']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        image_stores = list(
 | 
					        image_stores = list(
 | 
				
			||||||
| 
						 | 
					@ -596,12 +596,6 @@ def main(arguments):
 | 
				
			||||||
    #     )
 | 
					    #     )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        app.run(host='::',
 | 
					        app.run(host='::', port=port, debug=debug)
 | 
				
			||||||
                port=port,
 | 
					 | 
				
			||||||
                debug=debug)
 | 
					 | 
				
			||||||
    except OSError as e:
 | 
					    except OSError as e:
 | 
				
			||||||
        raise UncloudException('Failed to start Flask: {}'.format(e))
 | 
					        raise UncloudException('Failed to start Flask: {}'.format(e))
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == '__main__':
 | 
					 | 
				
			||||||
    main()
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,8 @@ def track_file(file, base_dir, host):
 | 
				
			||||||
        shared.etcd_client.put(entry_key, entry_value, value_in_json=True)
 | 
					        shared.etcd_client.put(entry_key, entry_value, value_in_json=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main(hostname, debug=False):
 | 
					def main(arguments):
 | 
				
			||||||
 | 
					    hostname = arguments['hostname']
 | 
				
			||||||
    base_dir = settings['storage']['file_dir']
 | 
					    base_dir = settings['storage']['file_dir']
 | 
				
			||||||
    # Recursively Get All Files and Folder below BASE_DIR
 | 
					    # Recursively Get All Files and Folder below BASE_DIR
 | 
				
			||||||
    files = glob.glob('{}/**'.format(base_dir), recursive=True)
 | 
					    files = glob.glob('{}/**'.format(base_dir), recursive=True)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,8 @@ def maintenance(host):
 | 
				
			||||||
            shared.vm_pool.put(vm)
 | 
					            shared.vm_pool.put(vm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main(hostname, debug=False):
 | 
					def main(arguments):
 | 
				
			||||||
 | 
					    hostname = arguments['hostname']
 | 
				
			||||||
    host_pool = shared.host_pool
 | 
					    host_pool = shared.host_pool
 | 
				
			||||||
    host = next(filter(lambda h: h.hostname == hostname, host_pool.hosts), None)
 | 
					    host = next(filter(lambda h: h.hostname == hostname, host_pool.hosts), None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ def qemu_img_type(path):
 | 
				
			||||||
        return qemu_img_info["format"]
 | 
					        return qemu_img_info["format"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main(debug=False):
 | 
					def main(arguments):
 | 
				
			||||||
    # We want to get images entries that requests images to be created
 | 
					    # We want to get images entries that requests images to be created
 | 
				
			||||||
    images = shared.etcd_client.get_prefix(
 | 
					    images = shared.etcd_client.get_prefix(
 | 
				
			||||||
        settings["etcd"]["image_prefix"], value_in_json=True
 | 
					        settings["etcd"]["image_prefix"], value_in_json=True
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,9 +88,7 @@ class Root(Resource):
 | 
				
			||||||
api.add_resource(Root, "/")
 | 
					api.add_resource(Root, "/")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main(port=None, debug=False):
 | 
					def main(arguments):
 | 
				
			||||||
 | 
					    port = arguments['port']
 | 
				
			||||||
 | 
					    debug = arguments['debug']
 | 
				
			||||||
    app.run(debug=debug, host="::", port=port)
 | 
					    app.run(debug=debug, host="::", port=port)
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == "__main__":
 | 
					 | 
				
			||||||
    main()
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,7 +16,7 @@ from uncloud.scheduler.helper import (dead_host_mitigation, dead_host_detection,
 | 
				
			||||||
arg_parser = argparse.ArgumentParser('scheduler', add_help=False)
 | 
					arg_parser = argparse.ArgumentParser('scheduler', add_help=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main(debug=False):
 | 
					def main(arguments):
 | 
				
			||||||
    # The below while True is neccessary for gracefully handling leadership transfer and temporary
 | 
					    # The below while True is neccessary for gracefully handling leadership transfer and temporary
 | 
				
			||||||
    # unavailability in etcd. Why does it work? It works because the get_prefix,watch_prefix return
 | 
					    # unavailability in etcd. Why does it work? It works because the get_prefix,watch_prefix return
 | 
				
			||||||
    # iter([]) that is iterator of empty list on exception (that occur due to above mentioned reasons)
 | 
					    # iter([]) that is iterator of empty list on exception (that occur due to above mentioned reasons)
 | 
				
			||||||
| 
						 | 
					@ -50,7 +50,3 @@ def main(debug=False):
 | 
				
			||||||
                        shared.vm_pool.put(vm_entry)
 | 
					                        shared.vm_pool.put(vm_entry)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        logger.info('No Resource Left. Emailing admin....')
 | 
					                        logger.info('No Resource Left. Emailing admin....')
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == '__main__':
 | 
					 | 
				
			||||||
    main()
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue