From 6041306a2a5e484fce87589ef2ad83d03039daee Mon Sep 17 00:00:00 2001 From: 3wc <3wc.cyberia@doesthisthing.work> Date: Sun, 11 Jul 2021 12:35:35 +0200 Subject: [PATCH] Updates for upstream IP handling --- capsulflask/console.py | 2 +- capsulflask/db.py | 2 +- capsulflask/db_model.py | 4 ++-- capsulflask/publicapi.py | 4 +++- capsulflask/schema_migrations/16_down_api_tokens.py | 2 -- capsulflask/schema_migrations/17_down_api_tokens.py | 2 ++ .../{16_up_api_tokens.py => 17_up_api_tokens.py} | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) delete mode 100644 capsulflask/schema_migrations/16_down_api_tokens.py create mode 100644 capsulflask/schema_migrations/17_down_api_tokens.py rename capsulflask/schema_migrations/{16_up_api_tokens.py => 17_up_api_tokens.py} (87%) diff --git a/capsulflask/console.py b/capsulflask/console.py index c7aa24c..0105177 100644 --- a/capsulflask/console.py +++ b/capsulflask/console.py @@ -236,7 +236,7 @@ def _create(vm_sizes, operating_systems, public_keys_for_account, server_data): """) if len(errors) == 0: - id = makeCapsulId() + id = make_capsul_id() get_model().create_vm( email=session["account"], id=id, diff --git a/capsulflask/db.py b/capsulflask/db.py index 2bca40e..8b79ab5 100644 --- a/capsulflask/db.py +++ b/capsulflask/db.py @@ -43,7 +43,7 @@ def init_app(app, is_running_server): hasSchemaVersionTable = False actionWasTaken = False schemaVersion = 0 - desiredSchemaVersion = 16 + desiredSchemaVersion = 17 cursor = connection.cursor() diff --git a/capsulflask/db_model.py b/capsulflask/db_model.py index 6cb3643..ee71cc8 100644 --- a/capsulflask/db_model.py +++ b/capsulflask/db_model.py @@ -183,8 +183,8 @@ class DBModel: def create_vm(self, email, id, size, os, ssh_authorized_keys): self.cursor.execute(""" - INSERT INTO vms (email, id, size, os) - VALUES (%s, %s, %s, %s) + INSERT INTO vms (email, id, size, os, network_name, host) + VALUES (%s, %s, %s, %s, 'virbr1', 'baikal') """, (email, id, size, os) ) diff --git a/capsulflask/publicapi.py b/capsulflask/publicapi.py index 413a06a..90c12ec 100644 --- a/capsulflask/publicapi.py +++ b/capsulflask/publicapi.py @@ -10,7 +10,7 @@ from nanoid import generate from capsulflask.auth import account_required from capsulflask.db import get_model -bp = Blueprint("webapi", __name__, url_prefix="/api") +bp = Blueprint("publicapi", __name__, url_prefix="/api") @bp.route("/capsul/create", methods=["POST"]) @account_required @@ -25,6 +25,8 @@ def capsul_create(): account_balance = get_account_balance(get_vms(), get_payments(), datetime.datetime.utcnow()) capacity_avaliable = current_app.config["HUB_MODEL"].capacity_avaliable(512*1024*1024) + request.json['ssh_authorized_key_count'] = 1 + id, errors = _create( vm_sizes, operating_systems, diff --git a/capsulflask/schema_migrations/16_down_api_tokens.py b/capsulflask/schema_migrations/16_down_api_tokens.py deleted file mode 100644 index 5f3f93e..0000000 --- a/capsulflask/schema_migrations/16_down_api_tokens.py +++ /dev/null @@ -1,2 +0,0 @@ -DROP TABLE api_keys; -UPDATE schemaversion SET version = 15; diff --git a/capsulflask/schema_migrations/17_down_api_tokens.py b/capsulflask/schema_migrations/17_down_api_tokens.py new file mode 100644 index 0000000..c915d4a --- /dev/null +++ b/capsulflask/schema_migrations/17_down_api_tokens.py @@ -0,0 +1,2 @@ +DROP TABLE api_keys; +UPDATE schemaversion SET version = 16; diff --git a/capsulflask/schema_migrations/16_up_api_tokens.py b/capsulflask/schema_migrations/17_up_api_tokens.py similarity index 87% rename from capsulflask/schema_migrations/16_up_api_tokens.py rename to capsulflask/schema_migrations/17_up_api_tokens.py index ae15dbd..e17d67e 100644 --- a/capsulflask/schema_migrations/16_up_api_tokens.py +++ b/capsulflask/schema_migrations/17_up_api_tokens.py @@ -6,4 +6,4 @@ CREATE TABLE api_tokens ( token TEXT NOT NULL ); -UPDATE schemaversion SET version = 16; +UPDATE schemaversion SET version = 17;