Merge branch 'master' of code.ungleich.ch:uncloud/uncloud

This commit is contained in:
Nico Schottelius 2020-01-10 11:56:56 +01:00
commit 469d03467d
7 changed files with 16 additions and 42 deletions

View file

@ -3,23 +3,16 @@ import logging
import sys
import importlib
import argparse
import multiprocessing as mp
from uncloud import UncloudException
from contextlib import suppress
# the components that use etcd
ETCD_COMPONENTS= ['api',
'scheduler',
'host',
'filescanner',
'imagescanner',
'metadata',
'configure' ]
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):
logging.getLogger(__name__).error(
'Uncaught exception',
@ -48,12 +41,9 @@ if __name__ == '__main__':
etcd_parser = argparse.ArgumentParser(add_help=False)
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")
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))
@ -64,16 +54,10 @@ if __name__ == '__main__':
else:
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser])
args = arg_parser.parse_args()
if not args.command:
arg_parser.print_help()
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)
name = arguments.pop('command')
mod = importlib.import_module('uncloud.{}.main'.format(name))

View file

@ -565,7 +565,7 @@ api.add_resource(CreateNetwork, '/network/create')
def main(arguments):
debug = arguments['debug']
port = arguments['port']
port = arguments['port']
try:
image_stores = list(
@ -596,12 +596,6 @@ def main(arguments):
# )
try:
app.run(host='::',
port=port,
debug=debug)
app.run(host='::', port=port, debug=debug)
except OSError as e:
raise UncloudException('Failed to start Flask: {}'.format(e))
if __name__ == '__main__':
main()

View file

@ -68,7 +68,8 @@ def track_file(file, base_dir, host):
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']
# Recursively Get All Files and Folder below BASE_DIR
files = glob.glob('{}/**'.format(base_dir), recursive=True)

View file

@ -44,7 +44,8 @@ def maintenance(host):
shared.vm_pool.put(vm)
def main(hostname, debug=False):
def main(arguments):
hostname = arguments['hostname']
host_pool = shared.host_pool
host = next(filter(lambda h: h.hostname == hostname, host_pool.hosts), None)

View file

@ -30,7 +30,7 @@ def qemu_img_type(path):
return qemu_img_info["format"]
def main(debug=False):
def main(arguments):
# We want to get images entries that requests images to be created
images = shared.etcd_client.get_prefix(
settings["etcd"]["image_prefix"], value_in_json=True

View file

@ -88,9 +88,7 @@ class Root(Resource):
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)
if __name__ == "__main__":
main()

View file

@ -16,7 +16,7 @@ from uncloud.scheduler.helper import (dead_host_mitigation, dead_host_detection,
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
# 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)
@ -50,7 +50,3 @@ def main(debug=False):
shared.vm_pool.put(vm_entry)
logger.info('No Resource Left. Emailing admin....')
if __name__ == '__main__':
main()