Working with hard resets
This commit is contained in:
@@ -2,6 +2,8 @@ import docker
|
||||
from game_tables import GameTable
|
||||
from key_tables import KeyTable
|
||||
import os
|
||||
import socket
|
||||
import inspect
|
||||
from flask import current_app
|
||||
|
||||
|
||||
@@ -26,8 +28,19 @@ def build_container_routing_labels(prefix: str, strip_prefix=True):
|
||||
|
||||
return labels
|
||||
|
||||
def delete_container(docker_id) -> bool:
|
||||
if not docker_id:
|
||||
return False
|
||||
|
||||
def stop_container(docker_id):
|
||||
try:
|
||||
client = docker.from_env()
|
||||
container = client.containers.get(docker_id)
|
||||
container.remove()
|
||||
return True
|
||||
except docker.errors.NotFound, docker.errors.APIError:
|
||||
return False
|
||||
|
||||
def stop_container(docker_id) -> bool:
|
||||
try:
|
||||
client = docker.from_env()
|
||||
container = client.containers.get(docker_id)
|
||||
@@ -40,6 +53,7 @@ def stop_container(docker_id):
|
||||
def start_foundry_container(table: GameTable, key: KeyTable):
|
||||
client = docker.from_env()
|
||||
container = None
|
||||
networkName = client.containers.get(socket.gethostname()).attrs["HostConfig"]["NetworkMode"]
|
||||
|
||||
if table.docker_id != None and table.docker_id != 0:
|
||||
try:
|
||||
@@ -60,7 +74,7 @@ def start_foundry_container(table: GameTable, key: KeyTable):
|
||||
): {"bind": "/data", "mode": "rw"},
|
||||
"{data_bind}/container_cache".format(
|
||||
data_bind=os.environ.get("FOUNDRY_DATA_BIND")
|
||||
): {"bind": "/data/container_cache", "mode": "ro"},
|
||||
): {"bind": "/data/container_cache", "mode": "rw"},
|
||||
}
|
||||
environment = [
|
||||
"FOUNDRY_ROUTE_PREFIX={prefix}".format(prefix=table.game_table_link),
|
||||
@@ -77,6 +91,7 @@ def start_foundry_container(table: GameTable, key: KeyTable):
|
||||
environment=environment,
|
||||
ports=ports,
|
||||
detach=True,
|
||||
network=networkName
|
||||
)
|
||||
|
||||
return container.id
|
||||
|
||||
@@ -15,8 +15,8 @@ CREATE TABLE IF NOT EXISTS "game_tables" (
|
||||
"game_table_id" INTEGER NOT NULL UNIQUE,
|
||||
"game_table_name" TEXT UNIQUE,
|
||||
"game_table_link" TEXT UNIQUE,
|
||||
"version" INTEGER
|
||||
"active" INTEGER DEFAULT 0,
|
||||
"version" INTEGER,
|
||||
"active" INTEGER,
|
||||
"game_key" TEXT,
|
||||
"docker_id" TEXT,
|
||||
PRIMARY KEY("game_table_id")
|
||||
|
||||
@@ -3,7 +3,7 @@ import sqlite3
|
||||
import container_managment
|
||||
from database import SmartCursor, get_db, init_db
|
||||
import tables
|
||||
|
||||
import os
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -54,6 +54,8 @@ def delete_table(table_id):
|
||||
if table == None:
|
||||
return jsonify({}), 404
|
||||
|
||||
container_managment.delete_container(table.docker_id)
|
||||
|
||||
table.delete()
|
||||
with SmartCursor(connection=db) as smartCursor:
|
||||
table.commit(smartCursor)
|
||||
@@ -87,6 +89,8 @@ def activate_table(table_id):
|
||||
keyService = KeyService(db)
|
||||
gameService = GameService(db)
|
||||
|
||||
hard = bool(request.get_json()["hard"])
|
||||
|
||||
keys = keyService.get_free_keys(cursor)
|
||||
table = gameService.read_by_id(table_id, cursor)
|
||||
|
||||
@@ -104,6 +108,8 @@ def activate_table(table_id):
|
||||
current_app.logger.info(table.docker_id)
|
||||
key.reserve(table.game_table_id)
|
||||
table.active = True
|
||||
if hard:
|
||||
container_managment.delete_container(table.docker_id)
|
||||
table.docker_id = container_managment.start_foundry_container(table, key)
|
||||
key.commit(cursor)
|
||||
table.commit(cursor)
|
||||
|
||||
Reference in New Issue
Block a user