Exemplo n.º 1
0
 def show_cluster_info(self):
     for instance in self.master_candidates:
         echo('M', end='', color='green')
         name_msg = ': {name} {host}:{port}'
         echo(name_msg.format(name=instance.name,
                              host=instance.host, port=instance.port))
         slot_msg = ','.join(['-'.join([str(s[0]), str(s[1] - 1)])
                              for s in instance.unbinded_slots])
         echo('\tslots:', slot_msg)
Exemplo n.º 2
0
 def show_cluster_info(self):
     for instance in self.master_candidates:
         echo('M', end='', color='green')
         name_msg = ': {name} {host}:{port}'
         echo(
             name_msg.format(name=instance.name,
                             host=instance.host,
                             port=instance.port))
         slot_msg = ','.join([
             '-'.join([str(s[0]), str(s[1] - 1)])
             for s in instance.unbinded_slots
         ])
         echo('\tslots:', slot_msg)
Exemplo n.º 3
0
def status(args):
    cluster = Cluster.from_node(Node.from_uri(args.cluster))
    dis = []
    for n in cluster.masters:
        slaves = ','.join([s['addr'] for s in n.slaves(n.name)])
        msg = '{} {}:{} {} {}'.format(n.name, n.host, n.port, len(n.slots),
                                      slaves)
        dis.append(msg)
    echo('\n'.join(dis))
    echo('Masters:', len(cluster.masters))
    echo('Slaves:', len(cluster.nodes) - len(cluster.masters))
    covered_slots = sum(len(n.slots) for n in cluster.masters)
    echo('Covered Slots:', covered_slots)
    if covered_slots == cluster.CLUSTER_HASH_SLOTS:
        echo('Cluster is healthy!')
    else:
        echo('!!!Cluster is not healthy!!!')
        echo('Either there is no cluster or exists cluster is not healthy.')
        echo('If there is no cluster then run "redis-clu create <master_list>" or')
        echo('"redis-clu fix {}" would be great if there is exists cluster!'.format(args.cluster))

    echo('\n')

    for master in cluster.masters:
        echo(master)
        echo('===========================')
        echo(master.execute_command('info', 'keyspace'))
        echo('\n')
Exemplo n.º 4
0
def create(args):
    creator = cli_helper.ClusterCreator(args.masters)
    if not creator.check():
        echo('Pre-requirements to create cluster.\n', color='red')
        echo('\t1. At least 2 redis instances must be provided.')
        echo('\t2. Should be set <cluster_enabled> on redis server conf.')
        echo('\t3. Should be removed all keys in db 0.')
        echo('\t4. Any redis instance should not be member of other cluster.')
        exit()
    creator.initialize_slots()
    creator.show_cluster_info()
    creator.bind_slots()
    creator.bind_config_epoch()
    creator.join_cluster()
    echo('Waiting for the cluster to join ', end='')
    sys.stdout.flush()
    time.sleep(1)
    while not creator.cluster.consistent():
        echo('.', end='')
        sys.stdout.flush()
        time.sleep(1)
Exemplo n.º 5
0
def status(args):
    cluster = Cluster.from_node(Node.from_uri(args.cluster))
    dis = []
    for n in cluster.masters:
        slaves = ','.join([s['addr'] for s in n.slaves(n.name)])
        msg = '{} {}:{} {} {}'.format(n.name, n.host, n.port, len(n.slots),
                                      slaves)
        dis.append(msg)
    echo('\n'.join(dis))
    echo('Masters:', len(cluster.masters))
    echo('Slaves:', len(cluster.nodes) - len(cluster.masters))
    covered_slots = sum(len(n.slots) for n in cluster.masters)
    echo('Covered Slots:', covered_slots)
    if covered_slots == cluster.CLUSTER_HASH_SLOTS:
        echo('Cluster is healthy!')
    else:
        echo('!!!Cluster is not healthy!!!')
        echo('Either there is no cluster or exists cluster is not healthy.')
        echo(
            'If there is no cluster then run "redis-clu create <master_list>" or'
        )
        echo('"redis-clu fix {}" would be great if there is exists cluster!'.
             format(args.cluster))

    echo('\n')

    for master in cluster.masters:
        echo(master)
        echo('===========================')
        echo(master.execute_command('info', 'keyspace'))
        echo('\n')
Exemplo n.º 6
0
def create(args):
    creator = cli_helper.ClusterCreator(args.masters)
    if not creator.check():
        echo('Pre-requirements to create cluster.\n', color='red')
        echo('\t1. At least 2 redis instances must be provided.')
        echo('\t2. Should be set <cluster_enabled> on redis server conf.')
        echo('\t3. Should be removed all keys in db 0.')
        echo('\t4. Any redis instance should not be member of other cluster.')
        exit()
    creator.initialize_slots()
    creator.show_cluster_info()
    creator.bind_slots()
    creator.bind_config_epoch()
    creator.join_cluster()
    echo('Waiting for the cluster to join ', end='')
    sys.stdout.flush()
    time.sleep(1)
    while not creator.cluster.consistent():
        echo('.', end='')
        sys.stdout.flush()
        time.sleep(1)