Commit 75868fcb authored by Daniele Venzano's avatar Daniele Venzano

Consul support for Swarm URLs

Merge from Quang-Nhat Hoang-Xuan private tree
parent 3f71cbb0
......@@ -22,6 +22,11 @@ from typing import Iterable, Callable, Dict, Any, Union
import humanfriendly
from consul import Consul
except ImportError:
Consul = None
from kazoo.client import KazooClient
except ImportError:
......@@ -123,6 +128,18 @@ def zookeeper_swarm(zk_server_list: str, path='/docker') -> str:
return master.decode('utf-8')
def consul_swarm(consul_ip: str, path='/docker') -> str:
Using consul as discovery service, find the currently active Swarm master.
:param consul_ip: consul ip address
:param path: Swarm path in Consul
:return: Swarm master connection string
leader_key = 'docker/swarm/leader'
consul_client = Consul(consul_ip)
key_val = consul_client.kv.get(leader_key)
master = key_val[1]['Value']
return master.decode('utf-8')
class SwarmClient:
"""The Swarm client class that wraps the Docker API."""
......@@ -132,6 +149,9 @@ class SwarmClient:
if 'zk://' in url:
url = url[len('zk://'):]
manager = zookeeper_swarm(url)
elif 'consul://' in url:
url = url[len('consul://'):]
manager = consul_swarm(url)
elif 'http://' or 'https://' in url:
manager = url
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment