예제 #1
0
def set_weight(ring_name,
               disk_device,
               weight,
               ip,
               port,
               policy_num,
               cluster_name,
               taskid=None):
    rm = RingManager(cluster_name)
    try:
        if not policy_num:
            ring_name = ring_name.split('.')[0]
            content = rm.set_weight(ring_name=ring_name,
                                    weight=weight,
                                    disk_device=disk_device,
                                    ip=ip,
                                    port=port)
        else:
            content = rm.set_weight(policy_num=policy_num,
                                    weight=weight,
                                    disk_device=disk_device,
                                    ip=ip,
                                    port=port,
                                    policy=True)
        message = content
    except Exception, error:
        message = str(error)
        assert False
예제 #2
0
def set_weight(cluster_name, datajson):
    """
    更改环的权重
    :param ringjson:
    :return:
    """
    status = ''
    message = ''
    resp = {"status": status, "message": message}
    policy_num = ''
    ip = datajson.get('ip')
    port = datajson.get('port')
    weight = datajson.get('weight')
    device = datajson.get('device')
    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)
    rm = RingManager(cluster_name)
    try:
        if not policy_num:
            ring_name = ring_name.split('.')[0]
            content = rm.set_weight(ring_name=ring_name,
                                    weight=weight,
                                    disk_device=device,
                                    ip=ip,
                                    port=port)
        else:
            content = rm.set_weight(policy_num=policy_num,
                                    weight=weight,
                                    disk_device=device,
                                    ip=ip,
                                    port=port,
                                    policy=True)
    except Exception, error:
        status = 501
        message = str(error)