Initialize docker stack repo
This commit is contained in:
14
homeassistant/config/docker_containers_summary.py
Executable file
14
homeassistant/config/docker_containers_summary.py
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess, json
|
||||
cmd = ["/usr/bin/curl", "--unix-socket", "/var/run/docker.sock", "-s", "http://localhost/containers/json?all=1"]
|
||||
raw = subprocess.check_output(cmd, text=True)
|
||||
data = json.loads(raw)
|
||||
lines = []
|
||||
for c in data:
|
||||
name = c.get("Names", ["?"])[0].lstrip("/")
|
||||
state = c.get("State", "?")
|
||||
status = c.get("Status", "?")
|
||||
image = c.get("Image", "?")
|
||||
lines.append(f"{name} | {state} | {status} | {image}")
|
||||
out = {"count": len(lines), "list": sorted(lines)}
|
||||
print(json.dumps(out, ensure_ascii=False))
|
||||
Reference in New Issue
Block a user