parameters: (self, servers)
return_statement: return list(itertools.chain(*chunks))
docstring: mix down and active servers equally distributed
docstring_summary: mix down and active servers equally distributed
docstring_tokens: mix down and active servers equally distributed
function: def _reorder_servers_by_status_for_batch(self, servers):
          """ mix down and active servers equally distributed """
          try:
              slb_group_status = self.slb_client.summarized_group_server_statuses()
              server_down_svrs = []
              pulled_svrs = []
  
              if slb_group_status:
                  server_down_svrs = slb_group_status['server'][False]
                  pulled_svrs = self.slb_client.pulled_servers()
  
          except SLBClientError as e:
              logger.exception(e)
              raise e
          except KeyError as e:
              raise TarsError('Parse SLB response error {}'.format(e))
  
          if server_down_svrs:
              servers = servers.exclude(ip_address__in=server_down_svrs)
              logger.warn('filter out servers {} whose member status down'.format(server_down_svrs))
  
          if not servers.exists():
              raise TarsError('no server to be batched or all servers are physical down')
  
          # make disabled and enabled ones interpolated, in case that all active servers
          # are batched into one and pulled out under certain circumstances
          disabled_svrs = servers.exclude(ip_address__in=pulled_svrs).values()
          enabled_svrs = servers.filter(ip_address__in=pulled_svrs).values()
  
          # the whole process is a func(x) mapping a smaller set into a bigger set, which is
          # very similar to slicing servers into batches
          shorter_one = min(enabled_svrs, disabled_svrs, key=len)
          longer_one = disabled_svrs if shorter_one is enabled_svrs else enabled_svrs
  
          chunk_num = len(shorter_one) or 1
          chunk_size = int(len(longer_one)/chunk_num)
  
          chunks = [longer_one[i: i + chunk_size] for i in range(0, len(longer_one), chunk_size)]
  
          for i, x in enumerate(shorter_one):
              chunks[i].append(x)
  
          return list(itertools.chain(*chunks))
function_tokens: def _reorder_servers_by_status_for_batch ( self , servers ) : try : slb_group_status = self . slb_client . summarized_group_server_statuses ( ) server_down_svrs = [ ] pulled_svrs = [ ] if slb_group_status : server_down_svrs = slb_group_status [ 'server' ] [ False ] pulled_svrs = self . slb_client . pulled_servers ( ) except SLBClientError as e : logger . exception ( e ) raise e except KeyError as e : raise TarsError ( 'Parse SLB response error {}' . format ( e ) ) if server_down_svrs : servers = servers . exclude ( ip_address__in = server_down_svrs ) logger . warn ( 'filter out servers {} whose member status down' . format ( server_down_svrs ) ) if not servers . exists ( ) : raise TarsError ( 'no server to be batched or all servers are physical down' ) # make disabled and enabled ones interpolated, in case that all active servers # are batched into one and pulled out under certain circumstances disabled_svrs = servers . exclude ( ip_address__in = pulled_svrs ) . values ( ) enabled_svrs = servers . filter ( ip_address__in = pulled_svrs ) . values ( ) # the whole process is a func(x) mapping a smaller set into a bigger set, which is # very similar to slicing servers into batches shorter_one = min ( enabled_svrs , disabled_svrs , key = len ) longer_one = disabled_svrs if shorter_one is enabled_svrs else enabled_svrs chunk_num = len ( shorter_one ) or 1 chunk_size = int ( len ( longer_one ) / chunk_num ) chunks = [ longer_one [ i : i + chunk_size ] for i in range ( 0 , len ( longer_one ) , chunk_size ) ] for i , x in enumerate ( shorter_one ) : chunks [ i ] . append ( x ) return list ( itertools . chain ( * chunks ) )