示例#1
0
def wfm_ports_for_switch(ctx, switch_id):
    message = create_dump_state_by_switch(ctx.correlation_id,
                                          'wfm/kilda.topo.disco-bolt',
                                          switch_id)

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    if not records:
        LOG.error("wfm/kilda.topo.disco-bolt NO RESPONSE")

    retval = {}

    for record in records:
        data = json.loads(record.value)
        payload = data['payload']

        for port in payload['state']['discovery']:

            if port['consecutive_success'] == 0:
                status = 'DOWN'
            elif port['consecutive_failure'] == 0:
                status = 'UP'
            else:
                status = 'N/A'

            retval[int(port['port_id'])] = {
                'WFM_ISL_FOUND': 'FOUND' if port['found_isl'] else 'NOT FOUND',
                'WFM_ISL_STATUS': '{}'.format(status)
            }

    return retval
示例#2
0
def list_command(ctx):
    message = create_list(ctx.correlation_id)
    LOG.debug('command = {}'.format(message.serialize()))

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    print_table(records)
示例#3
0
def dump_state_command(ctx, destination, border, output_type):
    message = create_dump_state(ctx.correlation_id, destination=destination)
    LOG.debug('command = {}'.format(message.serialize()))

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    if output_type == 'table':
        print_table(records, border)
    elif output_type == 'json':
        for record in records:
            data = json.loads(record.value)
            print(pprint.pformat(data))
示例#4
0
def list_command(ctx):
    message = create_list(ctx.correlation_id)
    LOG.debug('command = {}'.format(message.serialize()))

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    table = PrettyTable(['Topology', 'Component', 'Task ID'])
    for record in records:
        data = json.loads(record.value)
        payload = data['payload']
        LOG.debug(pprint.pformat(data))
        table.add_row(
            [payload['topology'], payload['component'], payload['task_id']])
    print(table)
示例#5
0
def dump_state_command(ctx, destination, border, output_type, allow_dangerous_operation):

    if not allow_dangerous_operation:
        click.secho("DON'T RUN ON PRODUCTION MAY CAUSE OVERSIZED KAFKA MESSAGE",
                    blink=True, bold=True)
        return

    message = create_dump_state(ctx.correlation_id, destination=destination)
    LOG.debug('command = {}'.format(message.serialize()))

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    if output_type == 'table':
        print_table(records, border)
    elif output_type == 'json':
        for record in records:
            data = json.loads(record.value)
            print(pprint.pformat(data))
def wfm_ports_for_switch(ctx, switch_id):
    message = create_dump_state_by_switch(ctx.correlation_id,
                                          'wfm/kilda.topo.disco-bolt',
                                          switch_id)

    with receive_with_context_async(ctx) as records:
        send_with_context(ctx, message.serialize())

    if not records:
        LOG.error("wfm/kilda.topo.disco-bolt NO RESPONSE")

    retval = {}

    for record in records:
        data = json.loads(record.value)
        payload = data['payload']

        for port in payload['state']['discovery']:
            retval[int(port['port_id'])] = {
                'WFM_ISL_STATUS': 'UP' if port['found_isl'] else 'DOWN'
            }

    return retval