Beispiel #1
0
def rebalance(cluster_name, datajson):
    """
    平衡环
    :param datajson:
    :return:
    """
    status = ''
    message = ''
    resp = {"status": status, "message": message}
    policy_num = ''
    ring_name = datajson.get('ring_name')
    ring_name = ring_name if ring_name.endswith(
        '.ring.gz') else ring_name + '.ring.gz'
    if 'object-' in ring_name:
        obj_ring, policy_num = ring_name.rstrip('.ring.gz').split('-')
    sfo_clu_nodes = SfoClusterNodesMethod.query_host_list_by_cluster_name(
        cluster_name)
    if not sfo_clu_nodes:
        raise ValueError('Not Master Node in %s' % cluster_name)
    # 建立task 任务
    rm = RingManager(cluster_name)
    try:
        if not policy_num:
            ring_name = ring_name.split('.')[0]
            content = rm.rebalance(ring_name=ring_name)
        else:
            content = rm.rebalance(policy_num=policy_num, policy=True)
    except Exception, error:
        status = 501
        message = str(error)
Beispiel #2
0
def rebalance(ring_name, policy_num, cluster_name, taskid=None):
    rm = RingManager(cluster_name)
    try:
        if not policy_num:
            ring_name = ring_name.split('.')[0]
            content = rm.rebalance(ring_name=ring_name)
        else:
            content = rm.rebalance(policy_num=policy_num, policy=True)
        message = content
    except Exception, error:
        message = str(error)
        assert False