Filip Pytloun | 2720a0d | 2016-11-02 14:15:55 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import yaml |
| 5 | import subprocess |
| 6 | |
| 7 | |
| 8 | def 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 |