From e7755708846f62bb132a21b4380f24476804996a Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 31 Dec 2019 14:06:51 +0100 Subject: [PATCH] Make uncloud host running --- uncloud/api/main.py | 7 +++---- uncloud/host/main.py | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/uncloud/api/main.py b/uncloud/api/main.py index 861c1bc..93bada7 100644 --- a/uncloud/api/main.py +++ b/uncloud/api/main.py @@ -590,11 +590,10 @@ def main(debug=False, port=None): # json.dumps(data), # ) - if port: - app_port = port - try: - app.run(host="::", debug=False) + app.run(host="::", + port=port, + debug=debug) except OSError as e: raise UncloudException("Failed to start Flask: {}".format(e)) diff --git a/uncloud/host/main.py b/uncloud/host/main.py index 80527c9..d1e7c9a 100755 --- a/uncloud/host/main.py +++ b/uncloud/host/main.py @@ -1,6 +1,7 @@ import argparse import multiprocessing as mp import time +from uuid import uuid4 from uncloud.common.request import RequestEntry, RequestType from uncloud.shared import shared @@ -42,7 +43,21 @@ def maintenance(host): def main(hostname): host_pool = shared.host_pool host = next(filter(lambda h: h.hostname == hostname, host_pool.hosts), None) - assert host is not None, "No such host with name = {}".format(hostname) + + # Does not yet exist, create it + if not host: + host_key = join_path( + settings["etcd"]["host_prefix"], uuid4().hex + ) + host_entry = { + "specs": "", + "hostname": hostname, + "status": "DEAD", + "last_heartbeat": "", + } + shared.etcd_client.put( + host_key, host_entry, value_in_json=True + ) try: heartbeat_updating_process = mp.Process(target=update_heartbeat, args=(hostname,))