Merge branch 'master' of code.ungleich.ch:uncloud/uncloud
This commit is contained in:
commit
469d03467d
7 changed files with 16 additions and 42 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',
|
||||||
|
@ -48,12 +41,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))
|
||||||
|
@ -64,16 +54,10 @@ 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)
|
||||||
name = arguments.pop('command')
|
name = arguments.pop('command')
|
||||||
mod = importlib.import_module('uncloud.{}.main'.format(name))
|
mod = importlib.import_module('uncloud.{}.main'.format(name))
|
||||||
|
|
|
@ -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…
Reference in a new issue