aboutsummaryrefslogtreecommitdiffstats
path: root/docker_net.py
diff options
context:
space:
mode:
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("/")