Ejemplo n.º 1
0
def show_pgs_list(cluster_name, pg_id, print_header, cluster_json=None):
    # Check cluster
    if cluster_json == None:
        cluster_json = cm.cluster_info(cluster_name)
        if cluster_json == None:
            return False

    exist = [k for loop_pg_data in cluster_json['data']['pg_list'] 
                    for k, v in loop_pg_data.iteritems() if k == 'pg_id' and int(v) == pg_id]
    if len(exist) == 0:
        warn(red("PG '%d' doesn't exist." % pg_id))
        return True

    # get specific pg info
    pg = cm.pg_info(cluster_name, pg_id, cluster_json)

    if print_header:
        print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
        print yellow(PG_COLUMN[:-1] + PGS_COLUMN)
        print yellow(PG_PARTITION[:-1] + PGS_PARTITION)

    # get all pgs info
    pgs_list = cm.get_pgs_list(cluster_name, pg_id, cluster_json)  
    if None == pgs_list:
        print yellow('| %-57s |' % ("There is no PGS in PG '%d'." % pg_id))
        print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
        return True

    for id, data in pgs_list.items():
        data['active_role'] = util.get_role_of_smr(data['ip'], data['mgmt_port'], verbose=False)
        if data['active_role'] == 'M':
            data['quorum'] = remote.get_quorum(data)
        else:
            data['quorum'] = ''

    pgs_state = True
    begin = True
    for pgs_id, pgs in sorted(pgs_list.items(), key=lambda x: int(x[0])):
        if pgs['active_role'] == 'M':
            bold = True
        else:
            bold = False

        if begin:
            prefix_pg = PG_FORMAT[:-1] % pg
            begin = False
        else:
            prefix_pg = PG_PREFIX[:-1]

        if pgs['active_role'] != pgs['smr_role']:
            print yellow(prefix_pg[:-1]), magenta(PGS_FORMAT % pgs)
            pgs_state = False
        elif pgs['active_role'] == 'M' or pgs['active_role'] == 'S':
            print yellow(prefix_pg[:-1]), yellow(PGS_FORMAT % pgs, bold)
        else:
            print yellow(prefix_pg[:-1]), red(PGS_FORMAT % pgs)
            pgs_state = False
            
    print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
    return pgs_state
Ejemplo n.º 2
0
def show_pgs(cluster_name, pgs_id):
    pgs = cm.pgs_info(cluster_name, pgs_id)
    if pgs == None:
        warn(red("PGS '%d' doesn't exist." % pgs_id))
        return

    pgs = pgs['data']
    pgs['active_role'] = util.get_role_of_smr(pgs['ip'],
                                              pgs['mgmt_port'],
                                              verbose=False)
    if pgs['active_role'] == 'M':
        pgs['quorum'] = remote.get_quorum(pgs)
    else:
        pgs['quorum'] = ''

    pg = cm.pg_info(cluster_name, pgs['pg_ID'])
    if pg == None:
        warn(red("PG '%d' doesn't exist." % pgs['pg_ID']))
        return

    if pgs['active_role'] == 'M':
        bold = True
    else:
        bold = False

    prefix_pg = PG_FORMAT[:-1] % pg

    # Print
    print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
    print yellow(PG_COLUMN[:-1] + PGS_COLUMN)
    print yellow(PG_PARTITION[:-1] + PGS_PARTITION)

    if pgs['active_role'] != pgs['smr_role']:
        print yellow(prefix_pg[:-1]), magenta(PGS_FORMAT % pgs)
    elif pgs['active_role'] == 'M' or pgs['active_role'] == 'S':
        print yellow(prefix_pg[:-1]), yellow(PGS_FORMAT % pgs, bold)
    else:
        print yellow(prefix_pg[:-1]), red(PGS_FORMAT % pgs)

    print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
Ejemplo n.º 3
0
def print_pgs_with_pg(cluster_json, pg_id, pgs_list, skip_warn=False):
    # get specific pg info
    pg = cm.pg_info(cluster_json['data']['cluster_name'], pg_id, cluster_json)

    begin = True
    warn = False
    for pgs in sorted(pgs_list, key=lambda x: int(x['pgs_id'])):
        bold, color_function, abnormal = pgs_view_style(pgs)

        if abnormal:
            warn = True

        if begin:
            prefix_pg = PG_FORMAT[:-1] % pg
            begin = False
        else:
            prefix_pg = PG_PREFIX[:-1]

        print yellow(prefix_pg[:-1]), color_function(PGS_FORMAT % pgs, bold)

    if not skip_warn and warn:        
        prompt("Press <Enter> to continue...")
Ejemplo n.º 4
0
def print_pgs_with_pg(cluster_json, pg_id, pgs_list, skip_warn=False):
    # get specific pg info
    pg = cm.pg_info(cluster_json['data']['cluster_name'], pg_id, cluster_json)

    begin = True
    warn = False
    for pgs in sorted(pgs_list, key=lambda x: int(x['pgs_id'])):
        bold, color_function, abnormal = pgs_view_style(pgs)

        if abnormal:
            warn = True

        if begin:
            prefix_pg = PG_FORMAT[:-1] % pg
            begin = False
        else:
            prefix_pg = PG_PREFIX[:-1]

        print yellow(prefix_pg[:-1]), color_function(PGS_FORMAT % pgs, bold)

    if not skip_warn and warn:        
        prompt("Press <Enter> to continue...")
Ejemplo n.º 5
0
def show_pgs(cluster_name, pgs_id):
    pgs = cm.pgs_info(cluster_name, pgs_id)
    if pgs == None:
        warn(red("PGS '%d' doesn't exist." % pgs_id))
        return

    pgs = pgs['data']
    pgs['active_role'] = util.get_role_of_smr(pgs['ip'], pgs['mgmt_port'], verbose=False)
    if pgs['active_role'] == 'M':
        pgs['quorum'] = remote.get_quorum(pgs)
    else:
        pgs['quorum'] = ''

    pg = cm.pg_info(cluster_name, pgs['pg_ID'])
    if pg == None:
        warn(red("PG '%d' doesn't exist." % pgs['pg_ID']))
        return

    if pgs['active_role'] == 'M': 
        bold = True
    else: 
        bold = False

    prefix_pg = PG_FORMAT[:-1] % pg

    # Print
    print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
    print yellow(PG_COLUMN[:-1] + PGS_COLUMN)
    print yellow(PG_PARTITION[:-1] + PGS_PARTITION)

    if pgs['active_role'] != pgs['smr_role']:
        print yellow(prefix_pg[:-1]), magenta(PGS_FORMAT % pgs)
    elif pgs['active_role'] == 'M' or pgs['active_role'] == 'S':
        print yellow(prefix_pg[:-1]), yellow(PGS_FORMAT % pgs, bold)
    else:
        print yellow(prefix_pg[:-1]), red(PGS_FORMAT % pgs)
            
    print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
Ejemplo n.º 6
0
def show_pgs_list(cluster_name, pg_id, print_header, cluster_json=None):
    # Check cluster
    if cluster_json == None:
        cluster_json = cm.cluster_info(cluster_name)
        if cluster_json == None:
            return False

    exist = [
        k for loop_pg_data in cluster_json['data']['pg_list']
        for k, v in loop_pg_data.iteritems()
        if k == 'pg_id' and int(v) == pg_id
    ]
    if len(exist) == 0:
        warn(red("PG '%d' doesn't exist." % pg_id))
        return True

    # get specific pg info
    pg = cm.pg_info(cluster_name, pg_id, cluster_json)

    if print_header:
        print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
        print yellow(PG_COLUMN[:-1] + PGS_COLUMN)
        print yellow(PG_PARTITION[:-1] + PGS_PARTITION)

    # get all pgs info
    pgs_list = cm.get_pgs_list(cluster_name, pg_id, cluster_json)
    if None == pgs_list:
        print yellow('| %-57s |' % ("There is no PGS in PG '%d'." % pg_id))
        print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
        return True

    for id, data in pgs_list.items():
        # Get active role
        data['active_role'] = util.get_role_of_smr(data['ip'],
                                                   data['mgmt_port'],
                                                   verbose=False)
        if data['active_role'] == 'M':
            data['quorum'] = remote.get_quorum(data)
        else:
            data['quorum'] = ''

        # Get memlog
        host = config.USERNAME + '@' + data['ip'].encode('ascii')
        with settings(hide('warnings', 'running', 'stdout', 'user'),
                      hosts=[host]):
            data['memlog'] = execute(remote.exist_smr_memlog,
                                     data['smr_base_port'])[host]

    pgs_state = True
    begin = True
    for pgs_id, pgs in sorted(pgs_list.items(), key=lambda x: int(x[0])):
        if pgs['active_role'] == 'M':
            bold = True
        else:
            bold = False

        if begin:
            prefix_pg = PG_FORMAT[:-1] % pg
            begin = False
        else:
            prefix_pg = PG_PREFIX[:-1]

        if pgs['active_role'] != pgs['smr_role']:
            print yellow(prefix_pg[:-1]), magenta(PGS_FORMAT % pgs)
            pgs_state = False
        elif pgs['active_role'] == 'M' or pgs['active_role'] == 'S':
            print yellow(prefix_pg[:-1]), yellow(PGS_FORMAT % pgs, bold)
        else:
            print yellow(prefix_pg[:-1]), red(PGS_FORMAT % pgs)
            pgs_state = False

    print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
    return pgs_state