#NEWLINE# def sniff_hosts( self , initial = False ) : #NEWLINE# #INDENT# '\n        Obtain a list of nodes from the cluster and create a new connection\n        pool using the information retrieved.\n\n        To extract the node connection parameters use the ``nodes_to_host_callback``.\n\n        :arg initial: flag indicating if this is during startup\n            (``sniff_on_start``), ignore the ``sniff_timeout`` if ``True``\n        ' #NEWLINE# previous_sniff = self . last_sniff #NEWLINE# try : #NEWLINE# #INDENT# self . last_sniff = time . time ( ) #NEWLINE# for c in chain ( self . connection_pool . connections , self . seed_connections ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( _ , headers , node_info ) = c . perform_request ( 'GET' , '/_nodes/_all/clear' , timeout = ( self . sniff_timeout if ( not initial ) else None ) ) #NEWLINE# node_info = self . deserializer . loads ( node_info , headers . get ( 'content-type' ) ) #NEWLINE# break #NEWLINE# #UNINDENT# except ( ConnectionError , SerializationError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise TransportError ( 'N/A' , 'Unable to sniff hosts.' ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# self . last_sniff = previous_sniff #NEWLINE# raise #NEWLINE# #UNINDENT# hosts = [ ] #NEWLINE# address = ( self . connection_class . transport_schema + '_address' ) #NEWLINE# for n in node_info [ 'nodes' ] . values ( ) : #NEWLINE# #INDENT# match = ADDRESS_RE . search ( n . get ( address , '' ) ) #NEWLINE# if ( not match ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# host = match . groupdict ( ) #NEWLINE# if ( 'port' in host ) : #NEWLINE# #INDENT# host [ 'port' ] = int ( host [ 'port' ] ) #NEWLINE# #UNINDENT# host = self . host_info_callback ( n , host ) #NEWLINE# if ( host is not None ) : #NEWLINE# #INDENT# hosts . append ( host ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not hosts ) : #NEWLINE# #INDENT# raise TransportError ( 'N/A' , 'Unable to sniff hosts - no viable hosts found.' ) #NEWLINE# #UNINDENT# self . set_connections ( hosts )