First attempt to enable Mongo Replicasets

This commit is contained in:
root 2011-11-11 16:26:59 +01:00
parent 8920f0d837
commit 3cd0eb6f1b
1 changed files with 17 additions and 11 deletions

View File

@ -38,19 +38,24 @@ URI_FORMAT = """\
def parse_url(url):
port = path = None
auth = userid = password = None
scheme = urlparse(url).scheme
parts = urlparse(url.replace("%s://" % (scheme, ), "http://"))
netloc = parts.netloc
if '@' in netloc:
auth, _, netloc = partition(parts.netloc, '@')
userid, _, password = partition(auth, ':')
hostname, _, port = partition(netloc, ':')
path = parts.path or ""
if path and path[0] == '/':
path = path[1:]
if scheme != 'mongodb':
netloc = parts.netloc
if '@' in netloc:
auth, _, netloc = partition(parts.netloc, '@')
userid, _, password = partition(auth, ':')
hostname, _, port = partition(netloc, ':')
path = parts.path or ""
if path and path[0] == '/':
path = path[1:]
port = int(port)
else:
hostname = url[len('mongodb://'):]
return dict({"hostname": hostname,
"port": port and int(port) or None,
"port": port or None,
"userid": userid or None,
"password": password or None,
"transport": scheme,
@ -386,14 +391,15 @@ class BrokerConnection(object):
port = fields["port"]
userid = fields["userid"]
password = fields["password"]
url = "%s://" % fields["transport"]
transport = fields["transport"]
url = "%s://" % transport
if userid:
url += userid
if include_password and password:
url += ':' + password
url += '@'
url += fields["hostname"]
if port:
if port and transport != "mongodb":
url += ':' + str(port)
url += '/' + fields["virtual_host"]
return url