Beispiel #1
0
def create_ring(cluster_name,
                ring_name,
                part_power,
                replicas,
                min_part_hours,
                policy_num,
                taskid=None):
    rm = RingManager(cluster_name)
    try:
        if policy_num:
            content = rm.create(part_power=part_power,
                                replicas=replicas,
                                min_part_hours=min_part_hours,
                                policy=True,
                                policy_num=policy_num)

        else:
            ring_name = ring_name.split('.')[0]
            content = rm.create(ring_name=ring_name,
                                part_power=part_power,
                                replicas=replicas,
                                min_part_hours=min_part_hours)

        message = content
    except Exception, error:
        message = str(error)
        assert False
Beispiel #2
0
def add_ring_2cluster(cluster_name, ringjson):
    """
    添加环数据到数据库
    :param ringjson:
    :return:
    """
    status = ''
    message = ''
    resp = {"status": status, "message": message}
    policy_num = ''
    replicas = ringjson.get('replicas')
    part_power = ringjson.get('part_power')
    ring_name = ringjson.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('-')
    min_part_hours = ringjson.get('min_part_hours')
    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 policy_num:
            content = rm.create(part_power=part_power,
                                replicas=replicas,
                                min_part_hours=min_part_hours,
                                policy=True,
                                policy_num=policy_num)

        else:
            ring_name = ring_name.split('.')[0]
            content = rm.create(ring_name=ring_name,
                                part_power=part_power,
                                replicas=replicas,
                                min_part_hours=min_part_hours)
    except Exception, error:
        status = 501
        message = str(error)
Beispiel #3
0
        content = pm.add(num=policy_num,
                         name=policy_name,
                         deprecated=deprecated,
                         policy_type=policy_type)
    except Exception, error:
        status = 501
        message = str(error)
    else:
        status = 201
        message = content
        if sync_policy_ring:
            try:
                rm = RingManager(cluster_name)
                content = rm.create(part_power=part_power,
                                    replicas=replicas,
                                    min_part_hours=min_part_hours,
                                    policy=True,
                                    policy_num=policy_num)
            except Exception, error:
                status = 501
                message = str(error)
            else:
                status = 201
                message = content
    resp.update({"status": status, "message": message})
    return resp, status


def del_policy_2cluster(cluster_name, policyjson):
    """
    弃用集群中的存储策略