<s> __author__ = '<STR_LIT>' <EOL> from base import DocumentWrapper <EOL> class Cluster ( DocumentWrapper ) : <EOL> def __init__ ( self , cluster_document ) : <EOL> DocumentWrapper . __init__ ( self , cluster_document ) <EOL> self . _members = self . _resolve_members ( "<STR_LIT>" ) <EOL> def _resolve_members ( self , member_prop ) : <EOL> member_documents = self . get_property ( member_prop ) <EOL> members = [ ] <EOL> member_type = self . get_member_type ( ) <EOL> if member_documents : <EOL> for mem_doc in member_documents : <EOL> member = member_type ( mem_doc ) <EOL> members . append ( member ) <EOL> return members <EOL> def get_member_type ( self ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def get_description ( self ) : <EOL> return self . get_ignore_str_property ( "<STR_LIT:description>" ) <EOL> def get_members ( self ) : <EOL> return self . _members <EOL> def get_servers ( self ) : <EOL> servers = [ ] <EOL> for member in self . get_members ( ) : <EOL> if member . get_server ( ) : <EOL> servers . append ( member . get_server ( ) ) <EOL> return servers <EOL> def get_members_info ( self ) : <EOL> info = [ ] <EOL> for member in self . get_members ( ) : <EOL> server = member . get_server ( ) <EOL> if server is not None : <EOL> info . append ( server . id ) <EOL> else : <EOL> info . append ( "<STR_LIT>" ) <EOL> return info <EOL> def get_repl_key ( self ) : <EOL> return self . get_property ( "<STR_LIT>" ) <EOL> def has_member_server ( self , server ) : <EOL> return self . get_member_for ( server ) is not None <EOL> def get_member_for ( self , server ) : <EOL> for member in self . get_members ( ) : <EOL> if ( member . get_server ( ) and <EOL> member . get_server ( ) . id == server . id ) : <EOL> return member <EOL> return None <EOL> def get_status ( self ) : <EOL> """<STR_LIT>""" <EOL> def get_default_server ( self ) : <EOL> """<STR_LIT>""" <EOL> def is_auth ( self ) : <EOL> if self . get_repl_key ( ) : <EOL> return True <EOL> else : <EOL> auth_servers = filter ( lambda s : s . is_auth ( ) , self . get_servers ( ) ) <EOL> return auth_servers and len ( auth_servers ) > <NUM_LIT:0> <EOL> def get_mongo_uri_template ( self , db = None ) : <EOL> auth = self . is_auth ( ) <EOL> if not db : <EOL> if auth : <EOL> db = "<STR_LIT>" <EOL> else : <EOL> db = "<STR_LIT>" <EOL> else : <EOL> db = "<STR_LIT:/>" + db <EOL> server_uri_templates = [ ] <EOL> for server in self . get_servers ( ) : <EOL> if server . is_cluster_connection_member ( ) : <EOL> server_uri_templates . append ( server . get_address_display ( ) ) <EOL> creds = "<STR_LIT>" if auth else "<STR_LIT>" <EOL> return "<STR_LIT>" % ( creds , "<STR_LIT:U+002C>" . join ( server_uri_templates ) , db , self . id ) </s>
