Ejemplo n.º 1
0
def do_transaction(args):
    subcommands = ['list', 'show', 'status']

    if args.subcommand not in subcommands:
        print('Unknown sub-command, expecting one of {0}'.format(
            subcommands))
        return

    if args.url is not None:
        url = args.url
    else:
        url = 'http://localhost:8800'

    web_client = SawtoothClient(url)

    try:
        if args.subcommand == 'list':
            if args.all:
                tsctids = web_client.get_transaction_list()
            else:
                tsctids = \
                    web_client.get_transaction_list(
                        block_count=args.blockcount)

            print_trans_info(args, web_client, tsctids)

        elif args.subcommand == 'show':
            tsct_info = \
                web_client.get_transaction(
                    transaction_id=args.transactionID,
                    field=args.key)
            print(pretty_print_dict(tsct_info))
            return
        elif args.subcommand == 'status':
            tsct_status = web_client.get_transaction_status(args.transactionID)
            if tsct_status == transaction.Status.committed:
                print('transaction committed')
            elif tsct_status == transaction.Status.pending:
                print('transaction still uncommitted')
            elif tsct_status == transaction.Status.unknown:
                print('unknown transaction')
            elif tsct_status == transaction.Status.failed:
                print('transaction failed to validate.')
            else:
                print('transaction returned unexpected status code {0}'
                      .format(tsct_status))
            return

    except MessageException as e:
        raise CliException(e)
Ejemplo n.º 2
0
def do_transaction(args):
    subcommands = ['list', 'show', 'status']

    if args.subcommand not in subcommands:
        print 'Unknown sub-command, expecting one of {0}'.format(
            subcommands)
        return

    if args.url is not None:
        url = args.url
    else:
        url = 'http://localhost:8800'

    web_client = SawtoothClient(url)

    try:
        if args.subcommand == 'list':
            if args.all:
                tsctids = web_client.get_transaction_list()
            else:
                tsctids = \
                    web_client.get_transaction_list(
                        block_count=args.blockcount)

            print_trans_info(args, web_client, tsctids)

        elif args.subcommand == 'show':
            tsct_info = \
                web_client.get_transaction(
                    transaction_id=args.transactionID,
                    field=args.key)
            print pretty_print_dict(tsct_info)
            return
        elif args.subcommand == 'status':
            tsct_status = web_client.get_transaction_status(args.transactionID)
            if tsct_status == transaction.Status.committed:
                print 'transaction committed'
            elif tsct_status == transaction.Status.pending:
                print 'transaction still uncommitted'
            elif tsct_status == transaction.Status.unknown:
                print 'unknown transaction'
            elif tsct_status == transaction.Status.failed:
                print 'transaction failed to validate.'
            else:
                print 'transaction returned unexpected status code {0}'\
                    .format(tsct_status)
            return

    except MessageException as e:
        raise CliException(e)
Ejemplo n.º 3
0
def do_transaction(args):
    subcommands = ['list', 'show', 'status']

    if args.subcommand not in subcommands:
        print 'Unknown sub-command, expecting one of {0}'.format(subcommands)
        return

    if args.url is not None:
        url = args.url
    else:
        url = 'http://localhost:8800'

    web_client = SawtoothClient(url)

    try:
        if args.subcommand == 'list':
            if args.all:
                tsctids = web_client.get_transaction_list()
            else:
                tsctids = \
                    web_client.get_transaction_list(
                        block_count=args.blockcount)

            if args.format == 'default':
                print '{:20} {:20} {:6} {:30} {:12} {:18} {:40}'.format(
                    'TRANS', 'BLOCK', 'STATUS', 'TXNTYPE', 'NODENAME', 'HOST',
                    'DOMAIN')

                for txn_id in tsctids:
                    trans_id, in_block, tran_status, txn_type, node_name,\
                        host, domain = get_trans_info(web_client, txn_id)
                    print '{:20} {:20} {:6} {:30} {:12} {:18} {:40}'.format(
                        trans_id, in_block, tran_status, txn_type, node_name,
                        host, domain)
                return

            elif args.format == 'csv':
                try:
                    writer = csv.writer(sys.stdout)
                    writer.writerow(('TRANS', 'BLOCK', 'STATUS', 'TXNTYPE',
                                     'NODENAME', 'HOST', 'DOMAIN'))
                    for txn_id in tsctids:
                        writer.writerow((get_trans_info(web_client, txn_id)))
                except csv.Error as e:
                    raise CliException(e)

            elif args.format == 'json' or args.format == 'yaml':
                json_dict = []
                for txn_id in tsctids:
                    trans_id, in_block, tran_status, txn_type, node_name,\
                        host, domain = get_trans_info(web_client, txn_id)
                    json_block = {
                        'TRANS': trans_id,
                        'BLOCK': in_block,
                        'STATUS': tran_status,
                        'TXNTYPE': txn_type,
                        'NODENAME': node_name,
                        'HOST': host,
                        'DOMAIN': domain
                    }
                    json_dict.append(json_block)

                if args.format == 'json':
                    print json.dumps(json_dict)
                else:
                    print yaml.dump(json_dict, default_flow_style=False)

            else:
                raise CliException("unknown format option: {}".format(
                    args.format))

        elif args.subcommand == 'show':
            tsct_info = \
                web_client.get_transaction(
                    transaction_id=args.transactionID,
                    field=args.key)
            print pretty_print_dict(tsct_info)
            return
        elif args.subcommand == 'status':
            tsct_status = web_client.get_transaction_status(args.transactionID)
            if tsct_status == transaction.Status.committed:
                print 'transaction committed'
            elif tsct_status == transaction.Status.pending:
                print 'transaction still uncommitted'
            elif tsct_status == transaction.Status.unknown:
                print 'unknown transaction'
            elif tsct_status == transaction.Status.failed:
                print 'transaction failed to validate.'
            else:
                print 'transaction returned unexpected status code {0}'\
                    .format(tsct_status)
            return

    except MessageException as e:
        raise CliException(e)