From 5a18fc7e13a5b7b54d5ef896b6b59e1547f6f84c Mon Sep 17 00:00:00 2001 From: forest Date: Thu, 2 Sep 2021 12:34:51 -0500 Subject: [PATCH] add comments describing how to correct async creates / handle fails --- capsulflask/db.py | 2 +- capsulflask/hub_api.py | 4 ++++ capsulflask/spoke_api.py | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/capsulflask/db.py b/capsulflask/db.py index 0c291a0..8dac950 100644 --- a/capsulflask/db.py +++ b/capsulflask/db.py @@ -114,7 +114,7 @@ def init_app(app, is_running_server): -def get_model(): +def get_model() -> DBModel: if 'db_model' not in g: connection = current_app.config['PSYCOPG2_CONNECTION_POOL'].getconn() cursor = connection.cursor() diff --git a/capsulflask/hub_api.py b/capsulflask/hub_api.py index 634ec21..4f3a1ea 100644 --- a/capsulflask/hub_api.py +++ b/capsulflask/hub_api.py @@ -169,6 +169,10 @@ def can_claim_create(payload, host_id) -> (str, str): return payload, "" def on_create_claimed(payload, host_id): + # TODO this happens when the create operation is assigned to one spoke, not when the create actually succeeds... + # VMs should probably start out in the "creating" state, and change to "booting" when the create.sh script succeeds. + # VMs should not be billable until they reach the booting state. + # see the corresponding TODO in spoke_api.handle_create get_model().create_vm( email=payload['email'], id=payload['id'], diff --git a/capsulflask/spoke_api.py b/capsulflask/spoke_api.py index f7513aa..c178572 100644 --- a/capsulflask/spoke_api.py +++ b/capsulflask/spoke_api.py @@ -144,6 +144,10 @@ def handle_create(operation_id, request_body): return abort(503, f"hub did not cleanly handle our request to claim the create operation") if assignment_status == "assigned": + # TODO this should probably be spun off as a coroutine + # and at the end of that coroutine, we should set the VM's state from "creating" to "booting" + # see the corresponding TODO in hub_api.on_create_claimed + try: current_app.config['SPOKE_MODEL'].create( email=request_body['email'],