blob: 8b8ecb7fbb42cb3b1f7cac67128203191d65f4a3 [file] [log] [blame]
Filip Pytloun2720a0d2016-11-02 14:15:55 +01001#!/usr/bin/env python
2
3import os
4import yaml
5import subprocess
6
7
8def main():
9 output = {}
10 if os.path.exists('/var/lib/docker/swarm/control.sock'):
11 try:
12 output["docker_swarm_tokens"] = {
13 'worker': subprocess.check_output(["docker", "swarm", "join-token", "-q", "worker"]).strip(),
14 'manager': subprocess.check_output(["docker", "swarm", "join-token", "-q", "manager"]).strip()
15 }
16 except subprocess.CalledProcessError:
17 pass
18
19 if os.path.exists('/var/lib/docker/swarm/state.json'):
20 with open('/var/lib/docker/swarm/state.json') as fh:
21 state = yaml.load(fh)
22 for key, value in state[0].iteritems():
23 output["docker_swarm_%s" % key] = value
24
25 if os.path.exists('/var/lib/docker/swarm/docker-state.json'):
26 with open('/var/lib/docker/swarm/docker-state.json') as fh:
27 state = yaml.load(fh)
28 for key, value in state.iteritems():
29 output["docker_swarm_%s" % key] = value
30
31 if output:
32 return output
33 else:
34 return None