コード例 #1
0
ファイル: cmdline.py プロジェクト: gaybro8777/trafficgen
def run_cli():
    interactive = sys.stdin.isatty() and sys.stdout.isatty()

    # Colorize output to standard error
    if interactive and sys.stderr.isatty():
        stderr = ColorizedOutput(sys.stderr, '\033[31m')  # red (not bright)
    else:
        stderr = sys.stderr

    try:
        hist_file = os.path.expanduser('~/.trafficgen_history')
        open(hist_file, 'a+').close()
    except:
        print >> stderr, 'Error: Cannot open ~/.trafficgen_history'
        hist_file = None
        raise

    try:
        s = bess.BESS()
        s.connect()
    except bess.BESS.APIError as e:
        print >> stderr, e.message, '(bessd daemon is not running?)'

    cli = TGENCLI(s,
                  generator_commands,
                  ferr=stderr,
                  interactive=interactive,
                  history_file=hist_file)
    print('Starting BESS...')
    bess_commands._do_start(cli, '-k')
    cli.loop()
コード例 #2
0
ファイル: bessctl.py プロジェクト: keonjang/bess
def run_cli():
    try:
        hist_file = os.path.expanduser('~/.bess_history')
        open(hist_file, 'a+').close()
    except:
        print >> sys.stderr, 'Error: Cannot open ~/.bess_history'
        hist_file = None
        raise

    s = connect_softnic()
    cli = BESSCLI(s, commands, history_file=hist_file)
    cli.loop()
コード例 #3
0
ファイル: cmdline.py プロジェクト: gaybro8777/trafficgen
def run_cmds(instream):
    try:
        s = bess.BESS()
        s.connect()
    except bess.BESS.APIError:
        # show no error msg, since user might be about to launch the daemon
        pass

    cli = TGENCLI(s,
                  generator_commands,
                  fin=instream,
                  ferr=sys.stderr,
                  interactive=False)
    print('Starting BESS...')
    bess_commands._do_start(cli, '-k')
    cli.loop()

    # end of loop due to error?
    if cli.stop_loop:
        if cli.last_cmd:
            cli.ferr.write('  Command failed: %s\n' % cli.last_cmd)
        sys.exit(1)
コード例 #4
0
ファイル: bessctl.py プロジェクト: keonjang/bess
def run_cmds(instream):
    s = connect_softnic()
    cli = BESSCLI(s, commands, fin=instream, history_file=None)
    cli.loop()