aboutsummaryrefslogtreecommitdiffstats
path: root/docker_net.py
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2024-06-05 09:31:20 +0100
committerjwansek <eddie.atten.ea29@gmail.com>2024-06-05 09:31:20 +0100
commita8e7d91e8cdc3c48568fee9c8ca69bdc3ae28ef9 (patch)
tree10a4b000d7cddf7be439dc3f9990ac2fd19c62cd /docker_net.py
parentd399ef3df2ac08cfc6b58fa50abc3e4ad1cf4af6 (diff)
downloadTasmotaCLI-a8e7d91e8cdc3c48568fee9c8ca69bdc3ae28ef9.tar.gz
TasmotaCLI-a8e7d91e8cdc3c48568fee9c8ca69bdc3ae28ef9.zip
Added script to automatically fetch the mqtt IP
Diffstat (limited to 'docker_net.py')
-rw-r--r--docker_net.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/docker_net.py b/docker_net.py
new file mode 100644
index 0000000..dd6f705
--- /dev/null
+++ b/docker_net.py
@@ -0,0 +1,12 @@
+import docker
+import os
+
+def get_mqtt_addr():
+ if os.getuid() != 0:
+ raise Exception("You must be root to access the docker API and fetch the container's network")
+
+ client = docker.from_env()
+ containers = client.networks.get("poweredagay_default").attrs["Containers"]
+ for k, v in containers.items():
+ if "mqtt_1" in v["Name"]:
+ return v["IPv4Address"].split("/")