Exemple #1
0
def add_disk_cluster(cluster_name, datajson):
    """
        向环中添加磁盘
        :param ringjson:
        :return:
        """
    status = ''
    message = ''
    resp = {"status": status, "message": message}
    policy_num = ''
    ip = datajson.get('ip')
    port = datajson.get('port')
    zone = datajson.get('zone')
    device = datajson.get('device')
    weight = datajson.get('weight')
    region = datajson.get('region')
    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('-')
    replication_ip = datajson.get('replication_ip')
    replication_port = datajson.get('replication_port')
    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.add_disk_2_ring(ring_name=ring_name,
                                         region=region,
                                         zone=zone,
                                         ip=ip,
                                         port=port,
                                         disk_device=device,
                                         weight=weight,
                                         replication_ip=replication_ip,
                                         replication_port=replication_port)
        else:
            content = rm.add_disk_2_ring(region=region,
                                         zone=zone,
                                         ip=ip,
                                         port=port,
                                         disk_device=device,
                                         weight=weight,
                                         replication_ip=replication_ip,
                                         replication_port=replication_port,
                                         policy=True,
                                         policy_num=policy_num)

    except Exception, error:
        status = 501
        message = str(error)
Exemple #2
0
def add_disk_2_ring(ring_name,
                    region,
                    zone,
                    ip,
                    port,
                    disk_device,
                    weight,
                    replication_ip='',
                    replication_port='',
                    policy_num='',
                    cluster_name='',
                    taskid=None):

    rm = RingManager(cluster_name)
    try:
        if not policy_num:
            ring_name = ring_name.split('.')[0]
            content = rm.add_disk_2_ring(ring_name=ring_name,
                                         region=region,
                                         zone=zone,
                                         ip=ip,
                                         port=port,
                                         disk_device=disk_device,
                                         weight=weight,
                                         replication_ip=replication_ip,
                                         replication_port=replication_port)
        else:
            content = rm.add_disk_2_ring(region=region,
                                         zone=zone,
                                         ip=ip,
                                         port=port,
                                         disk_device=disk_device,
                                         weight=weight,
                                         replication_ip=replication_ip,
                                         replication_port=replication_port,
                                         policy=True,
                                         policy_num=policy_num)
        message = content
    except Exception, error:
        message = str(error)
        assert False