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()
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()
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)
def run_cmds(instream): s = connect_softnic() cli = BESSCLI(s, commands, fin=instream, history_file=None) cli.loop()