Key setup fucking works
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
import docker
|
import docker
|
||||||
from game_tables import GameTable
|
from game_tables import GameTable
|
||||||
|
from key_tables import KeyTable
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def build_container_routing_labels(prefix: str, strip_prefix=True):
|
def build_container_routing_labels(prefix: str, strip_prefix=True):
|
||||||
@@ -23,7 +26,6 @@ def build_container_routing_labels(prefix: str, strip_prefix=True):
|
|||||||
|
|
||||||
return labels
|
return labels
|
||||||
|
|
||||||
|
|
||||||
def stop_container(docker_id):
|
def stop_container(docker_id):
|
||||||
try:
|
try:
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
@@ -34,7 +36,7 @@ def stop_container(docker_id):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def start_foundry_container(table: GameTable, version=12):
|
def start_foundry_container(table: GameTable, key: KeyTable, version=12):
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
container = None
|
container = None
|
||||||
|
|
||||||
@@ -50,11 +52,13 @@ def start_foundry_container(table: GameTable, version=12):
|
|||||||
else:
|
else:
|
||||||
image = "felddy/foundryvtt:{version}".format(version=version)
|
image = "felddy/foundryvtt:{version}".format(version=version)
|
||||||
labels = build_container_routing_labels(table.game_table_link, False)
|
labels = build_container_routing_labels(table.game_table_link, False)
|
||||||
|
os.makedirs("/data/" + table.game_table_link + "/Config", exist_ok=True)
|
||||||
|
shutil.copyfile(src="/data/keys/" + key.key_file, dst="/data/"+table.game_table_link+"/Config/license.json")
|
||||||
volumes = {
|
volumes = {
|
||||||
"/home/cow/Projects/dockertesting/server_data_mount/{prefix}".format(
|
"/home/cow/Projects/dockertesting/data/{prefix}".format(
|
||||||
prefix=table.game_table_link
|
prefix=table.game_table_link
|
||||||
): {"bind": "/data", "mode": "rw"},
|
): {"bind": "/data", "mode": "rw"},
|
||||||
"/home/cow/Projects/dockertesting/server_data_mount/foundry_cache": {
|
"/home/cow/Projects/dockertesting/data/container_cache": {
|
||||||
"bind": "/data/container_cache"
|
"bind": "/data/container_cache"
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from flask import g
|
from flask import g
|
||||||
from sqlite3 import connect, Connection, Cursor
|
from sqlite3 import connect, Connection, Cursor
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
def get_db():
|
def get_db():
|
||||||
@@ -23,8 +24,9 @@ CREATE TABLE IF NOT EXISTS "game_tables" (
|
|||||||
|
|
||||||
_key_table_create = """
|
_key_table_create = """
|
||||||
CREATE TABLE IF NOT EXISTS "game_keys" (
|
CREATE TABLE IF NOT EXISTS "game_keys" (
|
||||||
"key" TEXT NOT NULL,
|
"key" TEXT NOT NULL,
|
||||||
"game_table_id" INTEGER,
|
"game_table_id" INTEGER,
|
||||||
|
"key_file" TEXT NOT NULL,
|
||||||
PRIMARY KEY("key")
|
PRIMARY KEY("key")
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -5,19 +5,21 @@ from database import SmartCursor
|
|||||||
class KeyTable:
|
class KeyTable:
|
||||||
key: str
|
key: str
|
||||||
game_table_id: number
|
game_table_id: number
|
||||||
|
key_file: str
|
||||||
created: bool
|
created: bool
|
||||||
updated: bool
|
updated: bool
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, key: str, game_table_id: int, created: bool = True, updated: bool = True
|
self, key: str, game_table_id: int, key_file: str, created: bool = True, updated: bool = True
|
||||||
):
|
):
|
||||||
self.key = key
|
self.key = key
|
||||||
self.game_table_id = game_table_id
|
self.game_table_id = game_table_id
|
||||||
|
self.key_file = key_file
|
||||||
self.created = created
|
self.created = created
|
||||||
self.updated = updated
|
self.updated = updated
|
||||||
|
|
||||||
def toJson(self):
|
def toJson(self):
|
||||||
return {"key": self.key, "table_id": self.game_table_id}
|
return {"key": self.key, "table_id": self.game_table_id, "key_file": self.key_file}
|
||||||
|
|
||||||
def reserve(self, game_table_id):
|
def reserve(self, game_table_id):
|
||||||
self.game_table_id = game_table_id
|
self.game_table_id = game_table_id
|
||||||
@@ -64,7 +66,7 @@ class KeyService:
|
|||||||
def get_key_for_table(self, game_table_id, cursor=None) -> KeyTable:
|
def get_key_for_table(self, game_table_id, cursor=None) -> KeyTable:
|
||||||
with SmartCursor(cursor, self.connection) as smartCursor:
|
with SmartCursor(cursor, self.connection) as smartCursor:
|
||||||
smartCursor.execute(
|
smartCursor.execute(
|
||||||
"""SELECT key, game_table_id
|
"""SELECT key, game_table_id, key_file
|
||||||
FROM game_keys
|
FROM game_keys
|
||||||
WHERE game_table_id = ?""",
|
WHERE game_table_id = ?""",
|
||||||
(game_table_id,),
|
(game_table_id,),
|
||||||
@@ -74,21 +76,21 @@ class KeyService:
|
|||||||
if row == None:
|
if row == None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return KeyTable(row[0], row[1])
|
return KeyTable(row[0], row[1], row[2])
|
||||||
|
|
||||||
def get_reserved_keys(self, cursor=None) -> KeyTable:
|
def get_reserved_keys(self, cursor=None) -> KeyTable:
|
||||||
with SmartCursor(cursor, self.connection) as smartCursor:
|
with SmartCursor(cursor, self.connection) as smartCursor:
|
||||||
smartCurosr.execute("""SELECT key, game_table_id
|
smartCurosr.execute("""SELECT key, game_table_id, key_file
|
||||||
FROM game_keys
|
FROM game_keys
|
||||||
WHERE game_table_id IS NOT NULL""")
|
WHERE game_table_id IS NOT NULL""")
|
||||||
rows = smartCursor.fetchall()
|
rows = smartCursor.fetchall()
|
||||||
|
|
||||||
return [KeyTable(row[0], row[1]) for row in rows]
|
return [KeyTable(row[0], row[1, row[2]]) for row in rows]
|
||||||
|
|
||||||
def get_free_keys(self, cursor=None) -> KeyTable:
|
def get_free_keys(self, cursor=None) -> KeyTable:
|
||||||
with SmartCursor(cursor, self.connection) as smartCursor:
|
with SmartCursor(cursor, self.connection) as smartCursor:
|
||||||
smartCursor.execute("""SELECT key, game_table_id
|
smartCursor.execute("""SELECT key, game_table_id, key_file
|
||||||
FROM game_keys
|
FROM game_keys
|
||||||
WHERE game_table_id IS NULL""")
|
WHERE game_table_id IS NULL""")
|
||||||
rows = smartCursor.fetchall()
|
rows = smartCursor.fetchall()
|
||||||
return [KeyTable(row[0], row[1]) for row in rows]
|
return [KeyTable(row[0], row[1], row[2]) for row in rows]
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ def activate_table(table_id):
|
|||||||
|
|
||||||
keys[0].reserve(table.game_table_id)
|
keys[0].reserve(table.game_table_id)
|
||||||
table.active = True
|
table.active = True
|
||||||
table.docker_id = container_managment.start_foundry_container(table)
|
table.docker_id = container_managment.start_foundry_container(table, keys[0])
|
||||||
keys[0].commit(cursor)
|
keys[0].commit(cursor)
|
||||||
table.commit(cursor)
|
table.commit(cursor)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user