From 07a19f7f42be49bf9a61b347504b656ee9dc54d4 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Sun, 8 Mar 2020 18:36:07 +0100 Subject: [PATCH] Get swarm nodes + robust fallback --- src/restic_compose_backup/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/restic_compose_backup/utils.py b/src/restic_compose_backup/utils.py index e1e35ee..1debddd 100644 --- a/src/restic_compose_backup/utils.py +++ b/src/restic_compose_backup/utils.py @@ -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')