@@ -371,7 +371,26 @@ def split_hosts(hosts, default_port=DEFAULT_PORT):
371371_BAD_DB_CHARS = re .compile ('[' + re .escape (r'/ "$' ) + ']' )
372372
373373_ALLOWED_TXT_OPTS = frozenset (
374- ['authsource' , 'authSource' , 'replicaset' , 'replicaSet' ])
374+ ['authsource' , 'authSource' , 'replicaset' , 'replicaSet' , 'loadbalanced' ,
375+ 'loadBalanced' ])
376+
377+
378+ def _check_options (nodes , options ):
379+ # Ensure directConnection was not True if there are multiple seeds.
380+ if len (nodes ) > 1 and options .get ('directconnection' ):
381+ raise ConfigurationError (
382+ 'Cannot specify multiple hosts with directConnection=true' )
383+
384+ if options .get ('loadbalanced' ):
385+ if len (nodes ) > 1 :
386+ raise ConfigurationError (
387+ 'Cannot specify multiple hosts with loadBalanced=true' )
388+ if options .get ('directconnection' ):
389+ raise ConfigurationError (
390+ 'Cannot specify directConnection=true with loadBalanced=true' )
391+ if options .get ('replicaset' ):
392+ raise ConfigurationError (
393+ 'Cannot specify replicaSet with loadBalanced=true' )
375394
376395
377396def parse_uri (uri , default_port = DEFAULT_PORT , validate = True , warn = False ,
@@ -509,17 +528,17 @@ def parse_uri(uri, default_port=DEFAULT_PORT, validate=True, warn=False,
509528 dns_options , validate , warn , normalize )
510529 if set (parsed_dns_options ) - _ALLOWED_TXT_OPTS :
511530 raise ConfigurationError (
512- "Only authSource and replicaSet are supported from DNS" )
531+ "Only authSource, replicaSet, and loadBalanced are "
532+ "supported from DNS" )
513533 for opt , val in parsed_dns_options .items ():
514534 if opt not in options :
515535 options [opt ] = val
516536 if "ssl" not in options :
517537 options ["ssl" ] = True if validate else 'true'
518538 else :
519539 nodes = split_hosts (hosts , default_port = default_port )
520- if len (nodes ) > 1 and options .get ('directConnection' ):
521- raise ConfigurationError (
522- "Cannot specify multiple hosts with directConnection=true" )
540+
541+ _check_options (nodes , options )
523542
524543 return {
525544 'nodelist' : nodes ,
0 commit comments