#NEWLINE# def to_dist_dict( self ) : #NEWLINE# #INDENT# 'Return dict representation of the Pool required by Polaris PDNS\n        to perform query distribution.\n\n        "_default" distribution table is always built.\n\n        Region-specific distribution tables are built only if the pool is using \n        a topology lb method and has an UP member.\n\n        Example:\n            {\n                \'status\' : True,\n                \'lb_method\': \'twrr\',\n                \'fallback\': \'any\', \n                \'max_addrs_returned\': 1,\n                \'dist_tables\': {\n                    \'_default\': {\n                        \'rotation\': [ \'192.168.1.1\', \'192.168.1.2\' ],\n                        \'num_unique_addrs\': 2,\n                        \'index\': 1\n                    },\n\n                    \'region1\': {\n                        \'rotation\': [ \'192.168.1.1\' ],\n                        \'num_unique_addrs\': 1,\n                        \'index\': 0\n                    },\n\n                    \'region2\': {\n                        \'rotation\': [ \'192.168.1.2\' ],\n                        \'num_unique_addrs\': 1,\n                        \'index\': 0\n                    },\n                }\n            }\n        ' #NEWLINE# obj = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# obj [ 'status' ] = self . status #NEWLINE# obj [ 'lb_method' ] = self . lb_method #NEWLINE# obj [ 'fallback' ] = self . fallback #NEWLINE# obj [ 'max_addrs_returned' ] = self . max_addrs_returned #NEWLINE# dist_tables = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# dist_tables [ '_default' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# dist_tables [ '_default' ] [ 'rotation' ] = [ ] #NEWLINE# dist_tables [ '_default' ] [ 'num_unique_addrs' ] = 0 #NEWLINE# if self . status : #NEWLINE# #INDENT# for member in self . members : #NEWLINE# #INDENT# if ( member . weight == 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not member . status ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# for i in range ( member . weight ) : #NEWLINE# #INDENT# dist_tables [ '_default' ] [ 'rotation' ] . append ( member . ip ) #NEWLINE# #UNINDENT# dist_tables [ '_default' ] [ 'num_unique_addrs' ] += 1 #NEWLINE# if ( self . lb_method == 'fogroup' ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# if ( self . lb_method == 'twrr' ) : #NEWLINE# #INDENT# if ( member . region not in dist_tables ) : #NEWLINE# #INDENT# dist_tables [ member . region ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# dist_tables [ member . region ] [ 'rotation' ] = [ ] #NEWLINE# dist_tables [ member . region ] [ 'num_unique_addrs' ] = 0 #NEWLINE# #UNINDENT# for i in range ( member . weight ) : #NEWLINE# #INDENT# dist_tables [ member . region ] [ 'rotation' ] . append ( member . ip ) #NEWLINE# #UNINDENT# dist_tables [ member . region ] [ 'num_unique_addrs' ] += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for member in self . members : #NEWLINE# #INDENT# if ( member . weight == 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( self . fallback == 'any' ) : #NEWLINE# #INDENT# for i in range ( member . weight ) : #NEWLINE# #INDENT# dist_tables [ '_default' ] [ 'rotation' ] . append ( member . ip ) #NEWLINE# #UNINDENT# dist_tables [ '_default' ] [ 'num_unique_addrs' ] += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for name in dist_tables : #NEWLINE# #INDENT# random . shuffle ( dist_tables [ name ] [ 'rotation' ] ) #NEWLINE# dist_tables [ name ] [ 'index' ] = int ( ( random . random ( ) * len ( dist_tables [ name ] [ 'rotation' ] ) ) ) #NEWLINE# #UNINDENT# obj [ 'dist_tables' ] = dist_tables #NEWLINE# return obj