def run_flent(gui=False): if sys.version_info[:2] < (3, 6): sys.stderr.write("Sorry, Flent requires v3.6 or later of Python.\n") sys.exit(1) try: try: locale.setlocale(locale.LC_ALL, '') except locale.Error: pass from flent import batch from flent.settings import load from flent.loggers import setup_console, get_logger setup_console() logger = get_logger(__name__) logger.debug("Flent executed as %s in PID %d", sys.argv, os.getpid()) try: signal.signal(signal.SIGTERM, handle_sigterm) settings = load(sys.argv[1:]) if gui or settings.GUI: from flent.gui import run_gui return run_gui(settings) else: b = batch.new(settings) b.run() except RuntimeError as e: logger.exception(str(e)) except KeyboardInterrupt: try: b.kill() except NameError: pass # Proper behaviour on SIGINT is re-killing self with SIGINT to properly # signal to surrounding shell what happened. # Ref: http://mywiki.wooledge.org/SignalTrap try: signal.signal(signal.SIGINT, signal.SIG_DFL) os.kill(os.getpid(), signal.SIGINT) except: return 1 # Just in case... finally: try: signal.signal(signal.SIGTERM, signal.SIG_DFL) except: pass return 0
def run_flent(gui=False): if sys.version_info[:3] < (2, 7, 3): sys.stderr.write("Sorry, Flent requires v2.7.3 or later of Python.\n") sys.exit(1) try: locale.setlocale(locale.LC_ALL, "") from flent import batch from flent.settings import load try: signal.signal(signal.SIGTERM, handle_sigterm) settings = load(sys.argv[1:]) if gui or settings.GUI: from flent.gui import run_gui return run_gui(settings) else: b = batch.new(settings) b.run() except RuntimeError as e: try: if not settings.DEBUG_ERROR: sys.stderr.write("Fatal error: %s\n" % str(e)) return 1 else: raise except NameError: sys.stderr.write("Fatal error: %s\n" % str(e)) return 1 except KeyboardInterrupt: try: b.kill() except NameError: pass # Proper behaviour on SIGINT is re-killing self with SIGINT to properly # signal to surrounding shell what happened. # Ref: http://mywiki.wooledge.org/SignalTrap try: signal.signal(signal.SIGINT, signal.SIG_DFL) os.kill(os.getpid(), signal.SIGINT) except: return 1 # Just in case... finally: try: signal.signal(signal.SIGTERM, signal.SIG_DFL) except: pass return 0
def run_flent(gui=False): if sys.version_info[:3] < (2, 7, 3): sys.stderr.write("Sorry, Flent requires v2.7.3 or later of Python.\n") sys.exit(1) try: locale.setlocale(locale.LC_ALL, '') from flent import batch from flent.settings import load try: signal.signal(signal.SIGTERM, handle_sigterm) settings = load(sys.argv[1:]) if gui or settings.GUI: from flent.gui import run_gui return run_gui(settings) else: b = batch.new(settings) b.run() except RuntimeError as e: try: if not settings.DEBUG_ERROR: sys.stderr.write("Fatal error: %s\n" % str(e)) return 1 else: raise except NameError: sys.stderr.write("Fatal error: %s\n" % str(e)) return 1 except KeyboardInterrupt: try: b.kill() except NameError: pass # Proper behaviour on SIGINT is re-killing self with SIGINT to properly # signal to surrounding shell what happened. # Ref: http://mywiki.wooledge.org/SignalTrap try: signal.signal(signal.SIGINT, signal.SIG_DFL) os.kill(os.getpid(), signal.SIGINT) except: return 1 # Just in case... finally: try: signal.signal(signal.SIGTERM, signal.SIG_DFL) except: pass return 0
def load_gui(settings): from flent import gui gui.run_gui(settings) # does not return
def test_start_gui(self): from flent import gui gui.run_gui(self.settings, test_mode=True)
def run_flent(gui=False): if sys.version_info[:2] < (3, 5): sys.stderr.write("Sorry, Flent requires v3.5 or later of Python.\n") sys.exit(1) try: try: locale.setlocale(locale.LC_ALL, '') except locale.Error: pass from flent import batch from flent.settings import load from flent.loggers import setup_console, get_logger setup_console() logger = get_logger(__name__) try: signal.signal(signal.SIGTERM, handle_sigterm) settings = load(sys.argv[1:]) if (settings.TOPO): sys.path.append(os.path.dirname(os.path.abspath( settings.TOPO))) print(os.path.dirname(os.path.abspath(settings.TOPO))) filename = os.path.basename(settings.TOPO) print(filename) topology = import_module(filename[:-3]) (client_ns, client_ip, server_ns, server_ip) = topology.run() new_args = arg_parse() # exec_subprocess("ip netns exec n1 ping 10.2.2.2 -c 5") # TODO: Set server_ns and client_ns here t1 = threading.Thread(target=server, args=(server_ns, )) t2 = threading.Thread(target=client, args=( client_ns, new_args, server_ip, )) t1.start() time.sleep(2.0) t2.start() t1.join() t2.join() # run user script pass elif gui or settings.GUI: from flent.gui import run_gui return run_gui(settings) else: b = batch.new(settings) b.run() except RuntimeError as e: logger.exception(str(e)) except KeyboardInterrupt: try: b.kill() except NameError: pass # Proper behaviour on SIGINT is re-killing self with SIGINT to properly # signal to surrounding shell what happened. # Ref: http://mywiki.wooledge.org/SignalTrap try: signal.signal(signal.SIGINT, signal.SIG_DFL) os.kill(os.getpid(), signal.SIGINT) except: return 1 # Just in case... finally: try: signal.signal(signal.SIGTERM, signal.SIG_DFL) except: pass return 0