More debugging
This commit is contained in:
parent
bbbb592cb7
commit
03e5b7e7d8
6 changed files with 17 additions and 14 deletions
|
|
@ -11,7 +11,7 @@ import asyncio
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
from websockets.asyncio.server import serve, ServerConnection
|
from websockets.asyncio.server import serve, ServerConnection
|
||||||
|
|
||||||
from common import get_server_info
|
from common import list_servers
|
||||||
import docker
|
import docker
|
||||||
from docker import DockerClient
|
from docker import DockerClient
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ class RestServer:
|
||||||
|
|
||||||
def index(self):
|
def index(self):
|
||||||
try:
|
try:
|
||||||
data = get_server_info(self._client, all=bool(request.args.get("all")))
|
data = list_servers(self._client, all=bool(request.args.get("all")))
|
||||||
|
|
||||||
if request.args.get("sort"):
|
if request.args.get("sort"):
|
||||||
data = sorted(data, key=lambda x: x[request.args.get("sort")])
|
data = sorted(data, key=lambda x: x[request.args.get("sort")])
|
||||||
|
|
@ -48,7 +48,7 @@ class RestServer:
|
||||||
class WebSocketServer:
|
class WebSocketServer:
|
||||||
def __init__(self, docker_client: DockerClient):
|
def __init__(self, docker_client: DockerClient):
|
||||||
self._client = docker_client
|
self._client = docker_client
|
||||||
self.cache = json.dumps(get_server_info(self._client, all=True))
|
self.cache = json.dumps(list_servers(self._client, all=True))
|
||||||
|
|
||||||
async def __loop_infinitely(self, conn: ServerConnection):
|
async def __loop_infinitely(self, conn: ServerConnection):
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -61,11 +61,11 @@ class WebSocketServer:
|
||||||
await asyncio.Future()
|
await asyncio.Future()
|
||||||
|
|
||||||
async def __wait_for_change(self, conn: ServerConnection):
|
async def __wait_for_change(self, conn: ServerConnection):
|
||||||
new = json.dumps(get_server_info(self._client, all=True))
|
new = json.dumps(list_servers(self._client, all=True))
|
||||||
|
|
||||||
while new == self.cache:
|
while new == self.cache:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
new = json.dumps(get_server_info(self._client, all=True))
|
new = json.dumps(list_servers(self._client, all=True))
|
||||||
self.cache = new
|
self.cache = new
|
||||||
await conn.send(new)
|
await conn.send(new)
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ def main() -> None:
|
||||||
|
|
||||||
wss_thread.start()
|
wss_thread.start()
|
||||||
RestServer(client).run(host="0.0.0.0", port=int(env["REST_PORT"]) if "REST_PORT" in env else 9090)
|
RestServer(client).run(host="0.0.0.0", port=int(env["REST_PORT"]) if "REST_PORT" in env else 9090)
|
||||||
# wss_thread.join()
|
wss_thread.join()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ def parse_server(attrs: dict) -> Union[Server, None]:
|
||||||
return Server(params) if params else None
|
return Server(params) if params else None
|
||||||
|
|
||||||
|
|
||||||
def get_server_info(client: DockerClient, all: bool = False) -> List[dict]:
|
def list_servers(client: DockerClient, all: bool = False) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
Distills the container data for all servers on the current host into a usable format
|
Distills the container data for all servers on the current host into a usable format
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ def ping(ip, port=25565):
|
||||||
while len(data) != length:
|
while len(data) != length:
|
||||||
chunk = sock.recv(length - len(data))
|
chunk = sock.recv(length - len(data))
|
||||||
if not chunk:
|
if not chunk:
|
||||||
raise ValueError("connection abborted")
|
raise ValueError("connection aborted")
|
||||||
|
|
||||||
data += chunk
|
data += chunk
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import docker
|
||||||
from flask import Flask, jsonify, request
|
from flask import Flask, jsonify, request
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
from common import get_server_info
|
from common import list_servers
|
||||||
|
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
@ -20,7 +20,7 @@ CORS(app)
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
try:
|
try:
|
||||||
data = get_server_info(client, all=bool(request.args.get("all")))
|
data = list_servers(client, all=bool(request.args.get("all")))
|
||||||
|
|
||||||
if request.args.get("sort"):
|
if request.args.get("sort"):
|
||||||
data = sorted(data, key=lambda x: x[request.args.get("sort")])
|
data = sorted(data, key=lambda x: x[request.args.get("sort")])
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ import docker
|
||||||
from docker import DockerClient
|
from docker import DockerClient
|
||||||
from websockets.asyncio.server import ServerConnection, serve
|
from websockets.asyncio.server import ServerConnection, serve
|
||||||
|
|
||||||
from common import get_server_info
|
from common import list_servers
|
||||||
|
|
||||||
|
|
||||||
def __fetch(client: DockerClient):
|
def __fetch(client: DockerClient):
|
||||||
return json.dumps(get_server_info(client, all=True))
|
return json.dumps(list_servers(client, all=True))
|
||||||
|
|
||||||
|
|
||||||
CLIENT = docker.from_env()
|
CLIENT = docker.from_env()
|
||||||
|
|
@ -38,11 +38,11 @@ async def __setup(host: str, port: int = 8008):
|
||||||
async def __wait_for_change(conn: ServerConnection):
|
async def __wait_for_change(conn: ServerConnection):
|
||||||
global CACHE
|
global CACHE
|
||||||
|
|
||||||
new = json.dumps(get_server_info(CLIENT, all=True))
|
new = json.dumps(list_servers(CLIENT, all=True))
|
||||||
|
|
||||||
while new == CACHE:
|
while new == CACHE:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
new = json.dumps(get_server_info(CLIENT, all=True))
|
new = json.dumps(list_servers(CLIENT, all=True))
|
||||||
CACHE = new
|
CACHE = new
|
||||||
await conn.send(new)
|
await conn.send(new)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,9 @@ class Server:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
print(f"Pinging localhost:{int(port)}")
|
||||||
server_ping_info = ping_server("localhost", port=int(port))
|
server_ping_info = ping_server("localhost", port=int(port))
|
||||||
|
print(f"Pinged: {server_ping_info}")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -83,6 +85,7 @@ class Server:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
log_info = Server.parse_log_for_info(attrs["State"]["Health"]["Log"][-1]["Output"])
|
log_info = Server.parse_log_for_info(attrs["State"]["Health"]["Log"][-1]["Output"])
|
||||||
|
print(f"Log Info is done! \n\tlog_info.max={log_info.max}\n\tlog_info.motd={log_info.motd}\n\tlog_info.version={log_info.version}")
|
||||||
players = [Player(name=pl.name, uuid=pl.id) for pl in server_ping_info.players]
|
players = [Player(name=pl.name, uuid=pl.id) for pl in server_ping_info.players]
|
||||||
|
|
||||||
return ServerConstructorParams(
|
return ServerConstructorParams(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue