#NEWLINE# def get_hostports_from_backends( hmap , backends , haproxy_instance_count ) : #NEWLINE# #INDENT# hostports = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# regex = re . compile ( '^(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\d+)$' , re . IGNORECASE ) #NEWLINE# counts = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for backend in backends : #NEWLINE# #INDENT# svname = backend [ hmap [ 'svname' ] ] #NEWLINE# if ( svname in counts ) : #NEWLINE# #INDENT# counts [ svname ] += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# counts [ svname ] = 1 #NEWLINE# #UNINDENT# if ( counts [ svname ] == haproxy_instance_count ) : #NEWLINE# #INDENT# m = regex . match ( svname ) #NEWLINE# host = '.' . join ( m . group ( 1 , 2 , 3 , 4 ) ) #NEWLINE# port = m . group ( 5 ) #NEWLINE# if ( host in hostports ) : #NEWLINE# #INDENT# hostports [ host ] . append ( int ( port ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# hostports [ host ] = [ int ( port ) ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return hostports