Get swarm nodes + robust fallback

This commit is contained in:
Einar Forselv 2020-03-08 18:36:07 +01:00
parent 13d8e07a33
commit 07a19f7f42
1 changed files with 12 additions and 0 deletions

View File

@ -37,6 +37,18 @@ def list_containers() -> List[dict]:
return [c.attrs for c in all_containers]
def get_swarm_nodes():
client = docker_client()
# NOTE: If not a swarm node docker.errors.APIError is raised
# 503 Server Error: Service Unavailable
# ("This node is not a swarm manager. Use "docker swarm init" or
# "docker swarm join" to connect this node to swarm and try again.")
try:
return client.nodes.list()
except docker.errors.APIError:
return []
def remove_containers(containers: List['Container']):
client = docker_client()
logger.info('Attempting to delete stale backup process containers')