begin adding port support, catch OSError from Flask

This commit is contained in:
Nico Schottelius 2019-12-31 13:13:19 +01:00
parent 29dfacfadb
commit 71c3f9d978
2 changed files with 36 additions and 21 deletions

View file

@ -34,6 +34,8 @@ if __name__ == '__main__':
subparsers = arg_parser.add_subparsers(dest="command")
api_parser = subparsers.add_parser("api", parents=[parent_parser])
api_parser.add_argument("--port", "-p")
host_parser = subparsers.add_parser("host")
host_parser.add_argument("--hostname", required=True)

View file

@ -17,7 +17,7 @@ from uncloud.shared import shared
from . import schemas
from .helper import generate_mac, mac2ipv6
from uncloud import UncloudException
logger = logging.getLogger(__name__)
@ -561,29 +561,42 @@ api.add_resource(ListHost, "/host/list")
api.add_resource(CreateNetwork, "/network/create")
def main(debug=False):
def main(debug=False, port=None):
try:
image_stores = list(
shared.etcd_client.get_prefix(
settings["etcd"]["image_store_prefix"], value_in_json=True
)
)
if not image_stores:
data = {
"is_public": True,
"type": "ceph",
"name": "images",
"description": "first ever public image-store",
"attributes": {"list": [], "key": [], "pool": "images"},
}
except KeyError:
image_stores = False
shared.etcd_client.put(
join_path(
settings["etcd"]["image_store_prefix"], uuid4().hex
),
json.dumps(data),
)
# Do not inject default values that might be very wrong
# fail when required, not before
#
# if not image_stores:
# data = {
# "is_public": True,
# "type": "ceph",
# "name": "images",
# "description": "first ever public image-store",
# "attributes": {"list": [], "key": [], "pool": "images"},
# }
# shared.etcd_client.put(
# join_path(
# settings["etcd"]["image_store_prefix"], uuid4().hex
# ),
# json.dumps(data),
# )
if port:
app_port = port
try:
app.run(host="::", debug=False)
except OSError as e:
raise UncloudException("Failed to start Flask: {}".format(e))
if __name__ == "__main__":