Add support for ZooKeeper/Exhibitor DCS URI in patronictl ... -d

This commit is contained in:
Oleksandr Shulgin
2016-02-23 16:44:09 +01:00
parent 61feb47da8
commit 2f84e9f4ec
+9 -2
View File
@@ -16,6 +16,7 @@ from six.moves.urllib_parse import urlparse
import logging
from .etcd import Etcd
from .zookeeper import ZooKeeper
from .exceptions import PatroniCtlException
from .postgresql import parseurl
@@ -44,12 +45,12 @@ def parse_dcs(dcs):
parsed = urlparse('//' + dcs)
if scheme == '':
default_schemes = {'2181': 'zookeeper', '8500': 'consul'}
default_schemes = {'2181': 'zookeeper', '8181': 'exhibitor', '8500': 'consul'}
scheme = default_schemes.get(str(parsed.port), 'etcd')
port = parsed.port
if port is None:
default_ports = {'consul': 8500, 'zookeeper': 2181}
default_ports = {'consul': 8500, 'zookeeper': 2181, 'exhibitor': 8181}
port = default_ports.get(str(scheme), 4001)
return {'scheme': str(scheme), 'hostname': str(parsed.hostname), 'port': int(port)}
@@ -103,6 +104,12 @@ def get_dcs(config, scope):
if scheme == 'etcd':
return Etcd(name=scope, config={'scope': scope, 'host': '{0}:{1}'.format(hostname, port)})
if scheme == 'zookeeper':
return ZooKeeper(name=scope, config={'scope': scope, 'hosts': [hostname], 'port': port})
if scheme == 'exhibitor':
return ZooKeeper(name=scope, config={'scope': scope, 'exhibitor': {'hosts': [hostname], 'port': port}})
raise PatroniCtlException('Can not find suitable configuration of distributed configuration store')