def equalize(node1, node2):
 keys = [key for key in os.listdir(KEY_DIRECTORY) if key.endswith('.key')]
 keyname = keys[0].split('.')[0]
 to_move = (abs((node1['load'] - node2['load'])) / 2)
 mb_to_move = round((to_move / (1024 ** 2)), 2)
 if (node1['load'] > node2['load']):
  logging.info('Moving {} MiB from {} to {}'.format(mb_to_move, node1['ip'], node2['ip']))
  percentile = (100 - int(((to_move / node1['load']) * 100)))
  new_token = ssh(node1['ip'], keyname, 'appscale-get-token {}'.format(percentile), method=check_output).strip()
  repair = [new_token, node1['token']]
  cleanup_ip = node1['ip']
 else:
  logging.info('Moving {} MiB from {} to {}'.format(mb_to_move, node2['ip'], node1['ip']))
  percentile = int(((to_move / node2['load']) * 100))
  new_token = ssh(node2['ip'], keyname, 'appscale-get-token {}'.format(percentile), method=check_output).strip()
  repair = [node1['token'], new_token]
  cleanup_ip = node2['ip']
 logging.info('Moving {} to {}'.format(node1['ip'], (new_token[:60] + '...')))
 ssh(node1['ip'], keyname, '{} move {}'.format(NODE_TOOL, new_token))
 start = (repair[0][:60] + '...')
 end = (repair[1][:60] + '...')
 logging.info('Repairing {} to {}'.format(start, end))
 check_output([NODE_TOOL, 'repair', '-st', repair[0], '-et', repair[1]])
 logging.info('Cleaning up {}'.format(cleanup_ip))
 ssh(cleanup_ip, keyname, '{} cleanup'.format(NODE_TOOL))

def equalize ( node1 , node2 ) : keys = [ key for key in os . listdir ( KEY_DIRECTORY ) if key . endswith ( '.key' ) ] keyname = keys [ 0 ] . split ( '.' ) [ 0 ] to_move = ( abs ( ( node1 [ 'load' ] - node2 [ 'load' ] ) ) / 2 ) mb_to_move = round ( ( to_move / ( 1024 ** 2 ) ) , 2 ) if ( node1 [ 'load' ] > node2 [ 'load' ] ) : logging . info ( 'Moving {} MiB from {} to {}' . format ( mb_to_move , node1 [ 'ip' ] , node2 [ 'ip' ] ) ) percentile = ( 100 - int ( ( ( to_move / node1 [ 'load' ] ) * 100 ) ) ) new_token = ssh ( node1 [ 'ip' ] , keyname , 'appscale-get-token {}' . format ( percentile ) , method = check_output ) . strip ( ) repair = [ new_token , node1 [ 'token' ] ] cleanup_ip = node1 [ 'ip' ] else : logging . info ( 'Moving {} MiB from {} to {}' . format ( mb_to_move , node2 [ 'ip' ] , node1 [ 'ip' ] ) ) percentile = int ( ( ( to_move / node2 [ 'load' ] ) * 100 ) ) new_token = ssh ( node2 [ 'ip' ] , keyname , 'appscale-get-token {}' . format ( percentile ) , method = check_output ) . strip ( ) repair = [ node1 [ 'token' ] , new_token ] cleanup_ip = node2 [ 'ip' ] logging . info ( 'Moving {} to {}' . format ( node1 [ 'ip' ] , ( new_token [ : 60 ] + '...' ) ) ) ssh ( node1 [ 'ip' ] , keyname , '{} move {}' . format ( NODE_TOOL , new_token ) ) start = ( repair [ 0 ] [ : 60 ] + '...' ) end = ( repair [ 1 ] [ : 60 ] + '...' ) logging . info ( 'Repairing {} to {}' . format ( start , end ) ) check_output ( [ NODE_TOOL , 'repair' , '-st' , repair [ 0 ] , '-et' , repair [ 1 ] ] ) logging . info ( 'Cleaning up {}' . format ( cleanup_ip ) ) ssh ( cleanup_ip , keyname , '{} cleanup' . format ( NODE_TOOL ) )
equalize image using local histogram .