Ejemplo n.º 1
0
def menu_show_pgs(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    pgs_ids = []
    for pg_json in json_data['data']['pg_list']:
        for pgs_id in pg_json['pg_data']['pgs_ID_List']:
            pgs_ids.append(pgs_id)

    if len(pgs_ids) == 0:
        print yellow('There is no PGS.')
        return

    # Show PGS list
    pgs_ids.sort()
    for i in range(len(pgs_ids)):
        if i != 0 and i % 16 == 0:
            print ''
        sys.stdout.write(yellow('%4d' % pgs_ids[i]))

    # Select PGS
    s = prompt(cyan('\nInput PGS_ID(number) SHOW_MEMLOG(y/N)'))
    try:
        toks = s.split(' ')
        pgs_id = int(toks[0])
        if len(toks) == 2 and string.lower(toks[1]) == 'y':
            memlog = True
        else:
            memlog = False
        show_pgs(json_data, pgs_id, memlog)
    except:
        warn(red("Failed to show pgs info. %s" % sys.exc_info()[0]))
Ejemplo n.º 2
0
def menu_show_pgs(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    pgs_ids = []
    for pg_json in json_data['data']['pg_list']:
        for pgs_id in pg_json['pg_data']['pgs_ID_List']:
            pgs_ids.append(pgs_id)

    if len(pgs_ids) == 0:
        print yellow('There is no PGS.')
        return

    # Show PGS list
    pgs_ids.sort()
    for i in range(len(pgs_ids)):
        if i != 0 and i % 16 == 0:
            print ''
        sys.stdout.write(yellow('%4d' % pgs_ids[i]))

    # Select PGS
    s = prompt(cyan('\nSelect PGS number'))
    try:
        pgs_id = int(s.split(' ')[0])
        show_pgs(cluster_name, pgs_id)
    except:
        pass
Ejemplo n.º 3
0
def menu_show_pgs_list(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    pg_ids = []
    for pg_json in json_data['data']['pg_list']:
        pg_ids.append(int(pg_json['pg_id']))

    if len(pg_ids) == 0:
        print yellow('There is no PGS.')
        return

    # Show PG list
    pg_ids.sort()
    for i in range(len(pg_ids)):
        if i != 0 and i % 16 == 0:
            print ''
        sys.stdout.write(yellow('%4d' % pg_ids[i]))

    # Select PG
    s = prompt(cyan('\nSelect PG number'))

    try:
        pg_id = int(s)
        if show_pgs_list(cluster_name, pg_id, True, json_data) == False:
            prompt("Press <Enter> to continue...")
    except:
        pass
Ejemplo n.º 4
0
def menu_show_pgs(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    pgs_ids = []
    for pg_json in json_data['data']['pg_list']:
        for pgs_id in pg_json['pg_data']['pgs_ID_List']:
            pgs_ids.append(pgs_id)

    if len(pgs_ids) == 0:
        print yellow('There is no PGS.')
        return

    # Show PGS list
    pgs_ids.sort()
    for i in range(len(pgs_ids)):
        if i != 0 and i % 16 == 0:
            print ''
        sys.stdout.write(yellow('%4d' % pgs_ids[i]))

    # Select PGS
    s = prompt(cyan('\nInput PGS_ID(number) SHOW_MEMLOG(y/N)'))
    try:
        toks = s.split(' ')
        pgs_id = int(toks[0])
        if len(toks) == 2 and string.lower(toks[1]) == 'y':
            memlog = True
        else:
            memlog = False
        show_pgs(json_data, pgs_id, memlog)
    except:
        warn(red("Failed to show pgs info. %s" % sys.exc_info()[0]))
Ejemplo n.º 5
0
def menu_show_pgs(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    pgs_ids = []
    for pg_json in json_data['data']['pg_list']:
        for pgs_id in pg_json['pg_data']['pgs_ID_List']:
            pgs_ids.append(pgs_id)

    if len(pgs_ids) == 0:
        print yellow('There is no PGS.')
        return

    # Show PGS list
    pgs_ids.sort()
    for i in range(len(pgs_ids)):
        if i != 0 and i % 16 == 0:
            print ''
        sys.stdout.write(yellow('%4d' % pgs_ids[i]))

    # Select PGS
    s = prompt(cyan('\nSelect PGS number'))
    try:
        pgs_id = int(s.split(' ')[0])
        show_pgs(cluster_name, pgs_id)
    except:
        pass
Ejemplo n.º 6
0
def menu_show_pgs_list(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    pg_ids = []
    for pg_json in json_data['data']['pg_list']:
        pg_ids.append(int(pg_json['pg_id']))

    if len(pg_ids) == 0:
        print yellow('There is no PGS.')
        return

    # Show PG list
    pg_ids.sort()
    for i in range(len(pg_ids)):
        if i != 0 and i % 16 == 0:
            print ''
        sys.stdout.write(yellow('%4d' % pg_ids[i]))

    # Select PG
    s = prompt(cyan('\nSelect PG number'))

    try:
        pg_id = int(s)
        if show_pgs_list(cluster_name, pg_id, True, json_data) == False:
            prompt("Press <Enter> to continue...")
    except:
        pass
Ejemplo n.º 7
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.º 8
0
def menu_show_all(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    print ''
    if show_gw_list(cluster_name) == False:
        prompt("Press <Enter> to continue...")
    print ''

    header = True
    for pg in sorted(json_data['data']['pg_list'], key=lambda x: int(x['pg_id'])):
        if show_pgs_list(cluster_name, int(pg['pg_id']), header, json_data) == False:
            prompt("Press <Enter> to continue...")
        header = False
    print ''
Ejemplo n.º 9
0
def menu_show_pg_list(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    pg_infos = []

    pg_ids = []
    for pg in json_data['data']['pg_list']:
        pg_ids.append(pg['pg_id'])
        
    pg_infos = cm.pg_infos(cluster_name, pg_ids)

    print yellow(PG_HEADER)
    for pg_info in pg_infos:
        print yellow(PG_FORMAT % pg_info)
    print yellow(PG_PARTITION)
Ejemplo n.º 10
0
def menu_show_pg_list(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    pg_infos = []

    pg_ids = []
    for pg in json_data['data']['pg_list']:
        pg_ids.append(pg['pg_id'])
        
    pg_infos = cm.pg_infos(cluster_name, pg_ids)

    print yellow(PG_HEADER)
    for pg_info in pg_infos:
        print yellow(PG_FORMAT % pg_info)
    print yellow(PG_PARTITION)
Ejemplo n.º 11
0
def show_all(cluster_name, memlog):
    # Check cluster
    cluster_json = cm.cluster_info(cluster_name)
    if cluster_json == None: return

    print ''
    if show_gw_list(cluster_name) == False:
        prompt("Press <Enter> to continue...")
    print ''

    pgs_list = get_all_pgs_info(cluster_name, memlog)

    print yellow(PG_PGS_HEADER)
    for pg in sorted(cluster_json['data']['pg_list'], key=lambda x: int(x['pg_id'])):
        print_pgs_with_pg(cluster_json, int(pg['pg_id']),
                filter(lambda pgs: pgs['pgs_id'] in pg['pg_data']['pgs_ID_List'], pgs_list))
        print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
    print ''
Ejemplo n.º 12
0
def menu_show_all(cluster_name):
    # Check cluster
    json_data = cm.cluster_info(cluster_name)
    if json_data == None: return

    print ''
    if show_gw_list(cluster_name) == False:
        prompt("Press <Enter> to continue...")
    print ''

    header = True
    for pg in sorted(json_data['data']['pg_list'],
                     key=lambda x: int(x['pg_id'])):
        if show_pgs_list(cluster_name, int(pg['pg_id']), header,
                         json_data) == False:
            prompt("Press <Enter> to continue...")
        header = False
    print ''
Ejemplo n.º 13
0
def show_all(cluster_name, memlog):
    # Check cluster
    cluster_json = cm.cluster_info(cluster_name)
    if cluster_json == None: return

    print ''
    if show_gw_list(cluster_name) == False:
        prompt("Press <Enter> to continue...")
    print ''

    pgs_list = get_all_pgs_info(cluster_name, memlog)

    print yellow(PG_PGS_HEADER)
    for pg in sorted(cluster_json['data']['pg_list'], key=lambda x: int(x['pg_id'])):
        print_pgs_with_pg(cluster_json, int(pg['pg_id']),
                filter(lambda pgs: pgs['pgs_id'] in pg['pg_data']['pgs_ID_List'], pgs_list))
        print yellow(PG_PARTITION[:-1] + PGS_PARTITION)
    print ''
Ejemplo n.º 14
0
def show_pgs_list(cluster_name, pg_id, print_header, cluster_json=None, memlog=False, skip_warn=False):
    # Check cluster
    if cluster_json == None:
        cluster_json = cm.cluster_info(cluster_name)
        if cluster_json == None:
            return False

    pg = filter(lambda pg: int(pg['pg_id']) == pg_id, cluster_json['data']['pg_list'])
    if len(pg) == 0:
        warn(red("PG '%d' doesn't exist." % pg_id))
        return True
    pg = pg[0]

    # Get pgs info
    pgs_list = get_deployed_pgs_info(cluster_name, pg['pg_data']['pgs_ID_List'], memlog)

    # Print
    print yellow(PG_PGS_HEADER)
    print_pgs_with_pg(cluster_json, pg_id, pgs_list, skip_warn=skip_warn)
    print yellow(PG_PGS_PARTITION)
    print ''
Ejemplo n.º 15
0
def show_pgs_list(cluster_name, pg_id, print_header, cluster_json=None, memlog=False, skip_warn=False):
    # Check cluster
    if cluster_json == None:
        cluster_json = cm.cluster_info(cluster_name)
        if cluster_json == None:
            return False

    pg = filter(lambda pg: int(pg['pg_id']) == pg_id, cluster_json['data']['pg_list'])
    if len(pg) == 0:
        warn(red("PG '%d' doesn't exist." % pg_id))
        return True
    pg = pg[0]

    # Get pgs info
    pgs_list = get_deployed_pgs_info(cluster_name, pg['pg_data']['pgs_ID_List'], memlog)

    # Print
    print yellow(PG_PGS_HEADER)
    print_pgs_with_pg(cluster_json, pg_id, pgs_list, skip_warn=skip_warn)
    print yellow(PG_PGS_PARTITION)
    print ''
Ejemplo n.º 16
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