Update backend API infra
This commit is contained in:
parent
e4a3a0e46b
commit
e6db3abad6
3 changed files with 369 additions and 56 deletions
|
|
@ -3,9 +3,10 @@ Author: Jose Stovall
|
||||||
Description: Common utilities used to fetch current server statuses
|
Description: Common utilities used to fetch current server statuses
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import List, Union
|
from typing import List
|
||||||
|
|
||||||
from docker import DockerClient
|
from docker import DockerClient
|
||||||
|
from docker.models.containers import Container
|
||||||
|
|
||||||
from server import Server
|
from server import Server
|
||||||
|
|
||||||
|
|
@ -19,24 +20,13 @@ def list_servers(client: DockerClient, all: bool = False) -> List[dict]:
|
||||||
(List[Dict[str, any]]) A list of results from __extract_info
|
(List[Dict[str, any]]) A list of results from __extract_info
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __parse(attrs: dict) -> Union[Server, None]:
|
containers: List[Container] = list(
|
||||||
"""
|
|
||||||
Retrieves only valuable fields from the a Minecraft Server's container attributes
|
|
||||||
Arguments:
|
|
||||||
attrs (Dict[str, any]): The container's attributes
|
|
||||||
Returns:
|
|
||||||
(Server): The server parsed out from the container's attributes
|
|
||||||
"""
|
|
||||||
params = Server.params_from_attrs(attrs)
|
|
||||||
return Server(params) if params else None
|
|
||||||
|
|
||||||
containers = list(
|
|
||||||
filter(
|
filter(
|
||||||
lambda x: "itzg/minecraft-server" in x.attrs["Config"]["Image"] and "net.forgeserv.hide" not in x.labels,
|
lambda x: "itzg/minecraft-server" in x.attrs["Config"]["Image"] and "net.forgeserv.hide" not in x.labels,
|
||||||
client.containers.list(all=all),
|
client.containers.list(all=all),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
ret = [__parse(c.attrs) for c in containers]
|
ret = [Server.from_container(c) for c in containers]
|
||||||
ret = list(filter(lambda x: x is not None, ret))
|
ret = list(filter(lambda x: x is not None, ret))
|
||||||
return [x.asdict() for x in ret] # type: ignore
|
return [x.asdict() for x in ret] # type: ignore
|
||||||
|
|
|
||||||
116
src/server.py
116
src/server.py
|
|
@ -1,12 +1,16 @@
|
||||||
import base64
|
import base64
|
||||||
import re
|
import re
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import List, Union
|
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
from typing import Any, List, Union
|
||||||
|
|
||||||
|
from docker.models.containers import Container
|
||||||
|
|
||||||
from ping import ServerPingResponse
|
from ping import ServerPingResponse
|
||||||
from ping import ping as ping_server
|
from ping import ping as ping_server
|
||||||
|
|
||||||
SPECIAL_CHAR = "§"
|
SPECIAL_CHAR = "§"
|
||||||
|
DYNMAP_LABEL_KEY = "net.forgeserv.dynmap"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
@ -34,6 +38,50 @@ class ServerConstructorParams:
|
||||||
online: int
|
online: int
|
||||||
max: int
|
max: int
|
||||||
players: List[Player]
|
players: List[Player]
|
||||||
|
dynmap: Union[str, None]
|
||||||
|
|
||||||
|
|
||||||
|
def ping_container_server(container: Container) -> Union[ServerPingResponse, None]:
|
||||||
|
"""Iterates through all Container:Host port binding pairs and attempts to ping the server
|
||||||
|
|
||||||
|
Args:
|
||||||
|
container (Container): The container whose port bindings to try to ping
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Union[ServerPingResponse, None]: The info derived from the Ping, if available, otherwise None (failure case)
|
||||||
|
"""
|
||||||
|
|
||||||
|
# container.ports looks like {'25565/tcp': [{'HostIp': '0.0.0.0', 'HostPort': '25567'}, {'HostIp': '::', 'HostPort': '25567'}] }
|
||||||
|
# we only want the host host IP and host port, so we can skip that and just look at the values and ignore the
|
||||||
|
# "{port}/{tcp|udp}" part
|
||||||
|
for ip_port_pairs in container.ports.values():
|
||||||
|
for ip_port_pair in ip_port_pairs:
|
||||||
|
try:
|
||||||
|
port = int(ip_port_pair["HostPort"])
|
||||||
|
return ping_server(getenv("HOST_IP", "localhost"), port=port)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def safe_get(d_in: dict, key: str) -> Any:
|
||||||
|
"""Attempts to get a heavily nested object in a k:v pair, safely and quickly
|
||||||
|
Nested keys are to be split using a slash (/), so dict["State"]["Health"]["Status"]
|
||||||
|
would mean that the key passed in would be "State/Health/Status"
|
||||||
|
|
||||||
|
Args:
|
||||||
|
d_in (dict): The dictionary to scan through
|
||||||
|
key (str): The key formatted as documented above
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
object: The dict value (can be anything) or None if we failed to find it
|
||||||
|
"""
|
||||||
|
keys = key.split("/")
|
||||||
|
subitem = d_in
|
||||||
|
for k in keys:
|
||||||
|
if k not in subitem:
|
||||||
|
return None
|
||||||
|
subitem = subitem[k]
|
||||||
|
return subitem
|
||||||
|
|
||||||
|
|
||||||
class Server:
|
class Server:
|
||||||
|
|
@ -48,6 +96,7 @@ class Server:
|
||||||
self.online: int = params.online
|
self.online: int = params.online
|
||||||
self.max: int = params.max
|
self.max: int = params.max
|
||||||
self.players: List[Player] = params.players
|
self.players: List[Player] = params.players
|
||||||
|
self.dynmap: Union[str, None] = params.dynmap
|
||||||
|
|
||||||
def asdict(self) -> dict:
|
def asdict(self) -> dict:
|
||||||
d = self.__dict__
|
d = self.__dict__
|
||||||
|
|
@ -55,53 +104,38 @@ class Server:
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def params_from_attrs(attrs: dict) -> Union[ServerConstructorParams, None]:
|
def from_container(container: Container):
|
||||||
"""Builds the class from the container attrs passed in
|
"""Attempts to build out a server instance from a given container
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
attrs (dict): The container attributes for the given MC container
|
container (Container): The container whose props should be analyzed
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Union[Server,None]: A server if parsing params was successful, None otherwise
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __ping_server(attrs: dict) -> Union[ServerPingResponse, None]:
|
ping_data = ping_container_server(container)
|
||||||
"""Iterates through all Container:Host port binding pairs and attempts to ping the server
|
if not ping_data:
|
||||||
|
|
||||||
Args:
|
|
||||||
attrs (dict): The container's attributes
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Union[ServerPingResponse, None]: The info derived from the Ping, if available, otherwise None (failure case)
|
|
||||||
"""
|
|
||||||
|
|
||||||
for key in attrs["HostConfig"]["PortBindings"]:
|
|
||||||
# We have to do this nested for loop to get each Container->Host binding to get the actual port of the server
|
|
||||||
# By default they'd otherwise all show up as 25565.. :/
|
|
||||||
for binding in attrs["HostConfig"]["PortBindings"][key]:
|
|
||||||
try:
|
|
||||||
ping_resp = ping_server(getenv("HOST_IP", "localhost"), port=int(binding["HostPort"]))
|
|
||||||
return ping_resp
|
|
||||||
except ValueError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
ping_resp = __ping_server(attrs)
|
log_info = Server.parse_log_for_info(container.attrs["State"]["Health"]["Log"][-1]["Output"])
|
||||||
if not ping_resp:
|
players = [Player(name=pl.name, uuid=pl.id) for pl in ping_data.players]
|
||||||
return None
|
dynmap = container.labels[DYNMAP_LABEL_KEY] if DYNMAP_LABEL_KEY in container.labels else None
|
||||||
|
|
||||||
log_info = Server.parse_log_for_info(attrs["State"]["Health"]["Log"][-1]["Output"])
|
return Server(
|
||||||
players = [Player(name=pl.name, uuid=pl.id) for pl in ping_resp.players]
|
ServerConstructorParams(
|
||||||
|
health=str(safe_get(container.attrs, "State/Health/Status")),
|
||||||
return ServerConstructorParams(
|
status=str(safe_get(container.attrs, "State/Status")),
|
||||||
health=attrs["State"]["Health"]["Status"],
|
type=Server.get_server_type(list(safe_get(container.attrs, "Config/Env"))),
|
||||||
status=attrs["State"]["Status"],
|
version=log_info.version,
|
||||||
type=Server.get_server_type(attrs["Config"]["Env"]),
|
icon=str(base64.b64encode(ping_data.icon).decode()) if ping_data.icon else None,
|
||||||
version=log_info.version,
|
motd=log_info.motd,
|
||||||
icon=str(base64.b64encode(ping_resp.icon).decode()) if ping_resp.icon else None,
|
name=container.name or container.id or "",
|
||||||
motd=log_info.motd,
|
online=len(players),
|
||||||
name=attrs["Name"][1:],
|
max=log_info.max,
|
||||||
online=len(players),
|
players=players,
|
||||||
max=log_info.max,
|
dynmap=dynmap,
|
||||||
players=players,
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
||||||
289
test.py
Normal file
289
test.py
Normal file
|
|
@ -0,0 +1,289 @@
|
||||||
|
attrs = {
|
||||||
|
"Id": "024f2f99bcba9e5a9f5f2697987e3a9af43fb3dbcc8e425ce5e03134e3ff30d3",
|
||||||
|
"Created": "2025-07-02T20:30:02.451704042Z",
|
||||||
|
"Path": "/start",
|
||||||
|
"Args": [],
|
||||||
|
"State": {
|
||||||
|
"Status": "running",
|
||||||
|
"Running": True,
|
||||||
|
"Paused": False,
|
||||||
|
"Restarting": False,
|
||||||
|
"OOMKilled": False,
|
||||||
|
"Dead": False,
|
||||||
|
"Pid": 74401,
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Error": "",
|
||||||
|
"StartedAt": "2025-07-02T20:30:02.638231929Z",
|
||||||
|
"FinishedAt": "0001-01-01T00:00:00Z",
|
||||||
|
"Health": {
|
||||||
|
"Status": "healthy",
|
||||||
|
"FailingStreak": 0,
|
||||||
|
"Log": [
|
||||||
|
{
|
||||||
|
"Start": "2025-07-02T20:41:26.553850822Z",
|
||||||
|
"End": "2025-07-02T20:41:26.59217197Z",
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Output": "localhost:25565 : version=Paper 1.21.7 online=0 max=24 motd=''\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Start": "2025-07-02T20:41:56.592714954Z",
|
||||||
|
"End": "2025-07-02T20:41:56.633054645Z",
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Output": "localhost:25565 : version=Paper 1.21.7 online=0 max=24 motd=''\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Start": "2025-07-02T20:42:26.633833589Z",
|
||||||
|
"End": "2025-07-02T20:42:26.671942378Z",
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Output": "localhost:25565 : version=Paper 1.21.7 online=0 max=24 motd=''\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Start": "2025-07-02T20:42:56.672923709Z",
|
||||||
|
"End": "2025-07-02T20:42:56.71248765Z",
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Output": "localhost:25565 : version=Paper 1.21.7 online=0 max=24 motd=''\n",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Start": "2025-07-02T20:43:26.712919559Z",
|
||||||
|
"End": "2025-07-02T20:43:26.755687762Z",
|
||||||
|
"ExitCode": 0,
|
||||||
|
"Output": "localhost:25565 : version=Paper 1.21.7 online=0 max=24 motd=''\n",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Image": "sha256:02509d97a6d37b472023b4e2532f0e7d8da1ad6505df7ad4bec6829de87134ad",
|
||||||
|
"ResolvConfPath": "/var/lib/docker/containers/024f2f99bcba9e5a9f5f2697987e3a9af43fb3dbcc8e425ce5e03134e3ff30d3/resolv.conf",
|
||||||
|
"HostnamePath": "/var/lib/docker/containers/024f2f99bcba9e5a9f5f2697987e3a9af43fb3dbcc8e425ce5e03134e3ff30d3/hostname",
|
||||||
|
"HostsPath": "/var/lib/docker/containers/024f2f99bcba9e5a9f5f2697987e3a9af43fb3dbcc8e425ce5e03134e3ff30d3/hosts",
|
||||||
|
"LogPath": "/var/lib/docker/containers/024f2f99bcba9e5a9f5f2697987e3a9af43fb3dbcc8e425ce5e03134e3ff30d3/024f2f99bcba9e5a9f5f2697987e3a9af43fb3dbcc8e425ce5e03134e3ff30d3-json.log",
|
||||||
|
"Name": "/UntouchableMC",
|
||||||
|
"RestartCount": 0,
|
||||||
|
"Driver": "overlay2",
|
||||||
|
"Platform": "linux",
|
||||||
|
"MountLabel": "",
|
||||||
|
"ProcessLabel": "",
|
||||||
|
"AppArmorProfile": "docker-default",
|
||||||
|
"ExecIDs": None,
|
||||||
|
"HostConfig": {
|
||||||
|
"Binds": ["/home/minecraft/Servers/Untouchable:/data"],
|
||||||
|
"ContainerIDFile": "",
|
||||||
|
"LogConfig": {"Type": "json-file", "Config": {}},
|
||||||
|
"NetworkMode": "bridge",
|
||||||
|
"PortBindings": {"25565/tcp": [{"HostIp": "", "HostPort": "25567"}], "8123/tcp": [{"HostIp": "", "HostPort": "8123"}]},
|
||||||
|
"RestartPolicy": {"Name": "unless-stopped", "MaximumRetryCount": 0},
|
||||||
|
"AutoRemove": False,
|
||||||
|
"VolumeDriver": "",
|
||||||
|
"VolumesFrom": None,
|
||||||
|
"ConsoleSize": [0, 0],
|
||||||
|
"CapAdd": ["AUDIT_WRITE", "CHOWN", "DAC_OVERRIDE", "FOWNER", "FSETID", "KILL", "MKNOD", "NET_BIND_SERVICE", "NET_RAW", "SETFCAP", "SETGID", "SETPCAP", "SETUID", "SYS_CHROOT"],
|
||||||
|
"CapDrop": [
|
||||||
|
"AUDIT_CONTROL",
|
||||||
|
"BLOCK_SUSPEND",
|
||||||
|
"DAC_READ_SEARCH",
|
||||||
|
"IPC_LOCK",
|
||||||
|
"IPC_OWNER",
|
||||||
|
"LEASE",
|
||||||
|
"LINUX_IMMUTABLE",
|
||||||
|
"MAC_ADMIN",
|
||||||
|
"MAC_OVERRIDE",
|
||||||
|
"NET_ADMIN",
|
||||||
|
"NET_BROADCAST",
|
||||||
|
"SYSLOG",
|
||||||
|
"SYS_ADMIN",
|
||||||
|
"SYS_BOOT",
|
||||||
|
"SYS_MODULE",
|
||||||
|
"SYS_NICE",
|
||||||
|
"SYS_PACCT",
|
||||||
|
"SYS_PTRACE",
|
||||||
|
"SYS_RAWIO",
|
||||||
|
"SYS_RESOURCE",
|
||||||
|
"SYS_TIME",
|
||||||
|
"SYS_TTY_CONFIG",
|
||||||
|
"WAKE_ALARM",
|
||||||
|
],
|
||||||
|
"CgroupnsMode": "private",
|
||||||
|
"Dns": [],
|
||||||
|
"DnsOptions": None,
|
||||||
|
"DnsSearch": None,
|
||||||
|
"ExtraHosts": [],
|
||||||
|
"GroupAdd": None,
|
||||||
|
"IpcMode": "private",
|
||||||
|
"Cgroup": "",
|
||||||
|
"Links": None,
|
||||||
|
"OomScoreAdj": 0,
|
||||||
|
"PidMode": "",
|
||||||
|
"Privileged": False,
|
||||||
|
"PublishAllPorts": False,
|
||||||
|
"ReadonlyRootfs": False,
|
||||||
|
"SecurityOpt": None,
|
||||||
|
"UTSMode": "",
|
||||||
|
"UsernsMode": "",
|
||||||
|
"ShmSize": 67108864,
|
||||||
|
"Runtime": "runc",
|
||||||
|
"Isolation": "",
|
||||||
|
"CpuShares": 0,
|
||||||
|
"Memory": 0,
|
||||||
|
"NanoCpus": 0,
|
||||||
|
"CgroupParent": "",
|
||||||
|
"BlkioWeight": 0,
|
||||||
|
"BlkioWeightDevice": None,
|
||||||
|
"BlkioDeviceReadBps": None,
|
||||||
|
"BlkioDeviceWriteBps": None,
|
||||||
|
"BlkioDeviceReadIOps": None,
|
||||||
|
"BlkioDeviceWriteIOps": None,
|
||||||
|
"CpuPeriod": 0,
|
||||||
|
"CpuQuota": 0,
|
||||||
|
"CpuRealtimePeriod": 0,
|
||||||
|
"CpuRealtimeRuntime": 0,
|
||||||
|
"CpusetCpus": "",
|
||||||
|
"CpusetMems": "",
|
||||||
|
"Devices": [],
|
||||||
|
"DeviceCgroupRules": None,
|
||||||
|
"DeviceRequests": [],
|
||||||
|
"MemoryReservation": 0,
|
||||||
|
"MemorySwap": 0,
|
||||||
|
"MemorySwappiness": None,
|
||||||
|
"OomKillDisable": None,
|
||||||
|
"PidsLimit": None,
|
||||||
|
"Ulimits": None,
|
||||||
|
"CpuCount": 0,
|
||||||
|
"CpuPercent": 0,
|
||||||
|
"IOMaximumIOps": 0,
|
||||||
|
"IOMaximumBandwidth": 0,
|
||||||
|
"MaskedPaths": [
|
||||||
|
"/proc/asound",
|
||||||
|
"/proc/acpi",
|
||||||
|
"/proc/interrupts",
|
||||||
|
"/proc/kcore",
|
||||||
|
"/proc/keys",
|
||||||
|
"/proc/latency_stats",
|
||||||
|
"/proc/timer_list",
|
||||||
|
"/proc/timer_stats",
|
||||||
|
"/proc/sched_debug",
|
||||||
|
"/proc/scsi",
|
||||||
|
"/sys/firmware",
|
||||||
|
"/sys/devices/virtual/powercap",
|
||||||
|
],
|
||||||
|
"ReadonlyPaths": ["/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger"],
|
||||||
|
"Init": False,
|
||||||
|
},
|
||||||
|
"GraphDriver": {
|
||||||
|
"Data": {
|
||||||
|
"ID": "024f2f99bcba9e5a9f5f2697987e3a9af43fb3dbcc8e425ce5e03134e3ff30d3",
|
||||||
|
"LowerDir": "/var/lib/docker/overlay2/01e51a6b86af3d5ab2a76e9f303bb3603460d1de679200e4d76cc8ba0be987e4-init/diff:/var/lib/docker/overlay2/b6c4224417689822462495db525c188cf8010b5e7645bf5a140141694e8da027/diff:/var/lib/docker/overlay2/f7ce9479368dd02eaa785660951b690be28dc0c3dcc3bdec88bdac87dc8754f9/diff:/var/lib/docker/overlay2/1bf12dd288cc6c2c356f25e187d028d703ea568d42859435820b1057cf49e292/diff:/var/lib/docker/overlay2/63ebdd49844afa420713c7d5dbe6f78f584ef59907806d250024a7177b4d7aeb/diff:/var/lib/docker/overlay2/c4ad77e8a3a7d52a81cca571ca10c13f01ae49eb41ff0dc20c5919aee752752e/diff:/var/lib/docker/overlay2/62802c8531267a1ffeb5c9c5150262c0cae4c48888ffaa45e4a235dbc5bb0627/diff:/var/lib/docker/overlay2/05945af853e4850ef2bb8157376b212a5c39633891275521251d9d0b95758f73/diff:/var/lib/docker/overlay2/4a73f385ab6701697380b98599796db18cc0eba3f4576082a22d48b12714cf69/diff:/var/lib/docker/overlay2/4b43b060c5e886cf3a9bf655d30ddc88c66f15aef903ab7bfef9a16aa6d6c82a/diff:/var/lib/docker/overlay2/d372e5bb1597ec8ab015267ba303da437b5c4234634e0a5505fa708642ead31d/diff:/var/lib/docker/overlay2/e504fbb3864dfa6ebee0f95f0219b894fe710a311c65d78cd13387347cc3384b/diff:/var/lib/docker/overlay2/94b04f350318854dd8805564c190afd9d14c3f17e41232a0dee15d4307da3914/diff:/var/lib/docker/overlay2/176ec8fe15717faffb6afbc504b8a385b6b3512984e62da346fea3b5cf006ada/diff:/var/lib/docker/overlay2/9fd3562264da278b917cce860092d8e8044cd7ac69954f5ae51a549fa70c9e48/diff:/var/lib/docker/overlay2/99cc7084d392c16498483063fe59a6c04dba6cedcf54ae0e264c0ce0d37c754b/diff:/var/lib/docker/overlay2/195dea39a0aab0e466000cd446595e26dd69598dd48bf6562f14c202b8229805/diff:/var/lib/docker/overlay2/4182df9810ae289adfad1f941e738a3eefdd8a66f1784de68df6440b135e1d05/diff:/var/lib/docker/overlay2/6f5719b0d6b4e8200c7c85b8c6b40c30a0199cefee6090e4f6a50fef322a9f7e/diff:/var/lib/docker/overlay2/3a2153cb9e727692d3a39447f547f03070d300ac7b2006e4597ac1277f9ef1ee/diff:/var/lib/docker/overlay2/60092a4ffa0145f096fd559f2235a9f37117d3eb6ec308731bc91843d1dbb881/diff:/var/lib/docker/overlay2/7b560cd590212817cbc86db44e66134e8b933d9ddf9856ca1287758ee9ab3ee7/diff:/var/lib/docker/overlay2/9bff3537a304fa8f0afe5e056f54caa075a299f0c3771959054c20b1c13d1607/diff:/var/lib/docker/overlay2/fcfa23ee8b397973e22e786991dee93e7c3a11d1f7656273e085c2ace1fb90d3/diff",
|
||||||
|
"MergedDir": "/var/lib/docker/overlay2/01e51a6b86af3d5ab2a76e9f303bb3603460d1de679200e4d76cc8ba0be987e4/merged",
|
||||||
|
"UpperDir": "/var/lib/docker/overlay2/01e51a6b86af3d5ab2a76e9f303bb3603460d1de679200e4d76cc8ba0be987e4/diff",
|
||||||
|
"WorkDir": "/var/lib/docker/overlay2/01e51a6b86af3d5ab2a76e9f303bb3603460d1de679200e4d76cc8ba0be987e4/work",
|
||||||
|
},
|
||||||
|
"Name": "overlay2",
|
||||||
|
},
|
||||||
|
"Mounts": [{"Type": "bind", "Source": "/home/minecraft/Servers/Untouchable", "Destination": "/data", "Mode": "", "RW": True, "Propagation": "rprivate"}],
|
||||||
|
"Config": {
|
||||||
|
"Hostname": "bb44cc4c7497",
|
||||||
|
"Domainname": "",
|
||||||
|
"User": "",
|
||||||
|
"AttachStdin": False,
|
||||||
|
"AttachStdout": False,
|
||||||
|
"AttachStderr": False,
|
||||||
|
"ExposedPorts": {"25565/tcp": {}, "8123/tcp": {}},
|
||||||
|
"Tty": False,
|
||||||
|
"OpenStdin": False,
|
||||||
|
"StdinOnce": False,
|
||||||
|
"Env": [
|
||||||
|
"ENABLE_RCON=True",
|
||||||
|
"MEMORY=6G",
|
||||||
|
"JAVA_HOME=/opt/java/openjdk",
|
||||||
|
"LANG=en_US.UTF-8",
|
||||||
|
"LC_ALL=en_US.UTF-8",
|
||||||
|
"TYPE=Paper",
|
||||||
|
"JAVA_VERSION=jdk-21.0.4+7",
|
||||||
|
"RCON_PORT=25575",
|
||||||
|
"PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||||
|
"LANGUAGE=en_US:en",
|
||||||
|
"VERSION=1.21.7",
|
||||||
|
"PAPERBUILD=15",
|
||||||
|
"EULA=True",
|
||||||
|
"RCON_PASSWORD=minecraft",
|
||||||
|
"SERVER_NAME=UntouchableMC",
|
||||||
|
"UID=1000",
|
||||||
|
"GID=1000",
|
||||||
|
],
|
||||||
|
"Cmd": None,
|
||||||
|
"Healthcheck": {"Test": ["CMD-SHELL", "mc-health"], "Interval": 30000000000, "StartPeriod": 120000000000, "Retries": 2},
|
||||||
|
"Image": "itzg/minecraft-server:java21",
|
||||||
|
"Volumes": {"/data": {}},
|
||||||
|
"WorkingDir": "/data",
|
||||||
|
"Entrypoint": ["/start"],
|
||||||
|
"MacAddress": "f2:8e:e3:0d:b4:7d",
|
||||||
|
"OnBuild": None,
|
||||||
|
"Labels": {
|
||||||
|
"net.forgeserv.dynmap": "https://untouchable.forgeserv.net/",
|
||||||
|
"org.opencontainers.image.authors": "Geoff Bourne <itzgeoff@gmail.com>",
|
||||||
|
"org.opencontainers.image.created": "2025-06-29T04:04:41.064Z",
|
||||||
|
"org.opencontainers.image.description": "Docker image that provides a Minecraft Server for Java Edition that automatically downloads selected version at startup",
|
||||||
|
"org.opencontainers.image.licenses": "Apache-2.0",
|
||||||
|
"org.opencontainers.image.ref.name": "ubuntu",
|
||||||
|
"org.opencontainers.image.revision": "c700880bbe7fddefa9582764d78c9a2fe570b5da",
|
||||||
|
"org.opencontainers.image.source": "https://github.com/itzg/docker-minecraft-server",
|
||||||
|
"org.opencontainers.image.title": "docker-minecraft-server",
|
||||||
|
"org.opencontainers.image.url": "https://github.com/itzg/docker-minecraft-server",
|
||||||
|
"org.opencontainers.image.version": "java21",
|
||||||
|
},
|
||||||
|
"StopSignal": "SIGTERM",
|
||||||
|
},
|
||||||
|
"NetworkSettings": {
|
||||||
|
"Bridge": "",
|
||||||
|
"SandboxID": "e40feccd4060ecf7edf46790e15612347b058777d6fde948bccd649b76f6905c",
|
||||||
|
"SandboxKey": "/var/run/docker/netns/e40feccd4060",
|
||||||
|
"Ports": {
|
||||||
|
"25565/tcp": [{"HostIp": "0.0.0.0", "HostPort": "25567"}, {"HostIp": "::", "HostPort": "25567"}],
|
||||||
|
"8123/tcp": [{"HostIp": "0.0.0.0", "HostPort": "8123"}, {"HostIp": "::", "HostPort": "8123"}],
|
||||||
|
},
|
||||||
|
"HairpinMode": False,
|
||||||
|
"LinkLocalIPv6Address": "",
|
||||||
|
"LinkLocalIPv6PrefixLen": 0,
|
||||||
|
"SecondaryIPAddresses": None,
|
||||||
|
"SecondaryIPv6Addresses": None,
|
||||||
|
"EndpointID": "58c35d71d82db0cee8600a0ece7e1cc47727419b5b819e01534384c943f483f2",
|
||||||
|
"Gateway": "172.17.0.1",
|
||||||
|
"GlobalIPv6Address": "",
|
||||||
|
"GlobalIPv6PrefixLen": 0,
|
||||||
|
"IPAddress": "172.17.0.9",
|
||||||
|
"IPPrefixLen": 16,
|
||||||
|
"IPv6Gateway": "",
|
||||||
|
"MacAddress": "f2:8e:e3:0d:b4:7d",
|
||||||
|
"Networks": {
|
||||||
|
"bridge": {
|
||||||
|
"IPAMConfig": {},
|
||||||
|
"Links": None,
|
||||||
|
"Aliases": None,
|
||||||
|
"MacAddress": "f2:8e:e3:0d:b4:7d",
|
||||||
|
"DriverOpts": None,
|
||||||
|
"GwPriority": 0,
|
||||||
|
"NetworkID": "782c1573d45acd98d782de4d73b76a2bb4af041dc4d6b2f1710e8d8558e0d666",
|
||||||
|
"EndpointID": "58c35d71d82db0cee8600a0ece7e1cc47727419b5b819e01534384c943f483f2",
|
||||||
|
"Gateway": "172.17.0.1",
|
||||||
|
"IPAddress": "172.17.0.9",
|
||||||
|
"IPPrefixLen": 16,
|
||||||
|
"IPv6Gateway": "",
|
||||||
|
"GlobalIPv6Address": "",
|
||||||
|
"GlobalIPv6PrefixLen": 0,
|
||||||
|
"DNSNames": None,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def safe_get(d_in: dict, key: str):
|
||||||
|
keys = key.split("/")
|
||||||
|
subitem = d_in
|
||||||
|
for k in keys:
|
||||||
|
if k not in subitem:
|
||||||
|
return None
|
||||||
|
subitem = subitem[k]
|
||||||
|
return subitem
|
||||||
|
|
||||||
|
|
||||||
|
print(safe_get(attrs, "State/Health/Statu"))
|
||||||
Loading…
Reference in a new issue