示例#1
0
def process_array_with_master_node_fields(node_properties_as_array):
    host, port = util.split_address(node_properties_as_array[1])
    if is_ip(host):
        start_slot = 0
        end_slot = 0
        if len(node_properties_as_array) is 9:
            start_slot, end_slot = process_start_end_slots(
                node_properties_as_array[8])
        master_node = MasterNode(start_slot, end_slot, host, int(port),
                                 node_properties_as_array[0])
        logger.debug(master_node)
        return master_node
    return None
示例#2
0
def extract_masters_without_slots(all_nodes):
    master_nodes_to_return = []
    i = 0
    while i < len(all_nodes):
        node = all_nodes[i]
        if not ('slave' in node or 'noaddr' in node):
            node_as_array = re.compile(' ').split(node)
            if 8 >= len(node_as_array) > 1:
                host, port = util.split_address(node_as_array[1])
                if is_ip(host):
                    master_node_to_add = MasterNode(0, 0, host, int(port),
                                                    node_as_array[0])
                    logger.debug(master_node_to_add)
                    master_nodes_to_return.append(master_node_to_add)
        i += 1
    return master_nodes_to_return
示例#3
0
def add_node_to_cluster(source, target, target_role):
    for redis_node_address in target:
        host, port = split_address(redis_node_address)
        if is_ip(host):
            is_valid_redis_node(redis_node_address)
            logging.info('Adding %s with the %s role to the cluster ', target, target_role)
            full_node_address = host + ":" + str(port)
            cmd = ['--cluster', 'add-node', full_node_address, source]
            if target_role == "slave":
                cmd.append("--cluster-slave")
            result = run_redis_cli_cmd(cmd, True)
            if result.returncode == 0:
                logging.info('[V] Node %s was added to the cluster with role %s', full_node_address, target_role)
            else:
                logging.error(
                    '[X] Node %s was NOT added to the cluster. '
                    'Check if the given node is in clustered mode, '
                    'if is it empty or if this node is already part of the cluster',
                    full_node_address)
        else:
            logging.error(
                '[X] %s node does not have a valid address', target)
示例#4
0
def extract_cluster_masters_with_slots(array_of_all_nodes):
    master_nodes = []
    i = 0
    while i < len(array_of_all_nodes):
        element = array_of_all_nodes[i]
        if is_ip(element):
            try:
                master_node_to_add = MasterNode(int(array_of_all_nodes[i - 2]),
                                                int(array_of_all_nodes[i - 1]),
                                                array_of_all_nodes[i],
                                                int(array_of_all_nodes[i + 1]),
                                                array_of_all_nodes[i + 2])
                logger.debug(master_node_to_add)
                master_nodes.append(master_node_to_add)
                i += 3
                continue
            except (TypeError, ValueError):
                i += 1
                continue

        i += 1

    return master_nodes