def main(): """ Entry point for GNS3 server """ level = logging.INFO args = parse_arguments(sys.argv[1:], Config.instance().get_section_config("Server")) if args.debug: level = logging.DEBUG user_log = init_logger(level, quiet=args.quiet) user_log.info("GNS3 server version {}".format(__version__)) current_year = datetime.date.today().year user_log.info( "Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) for config_file in Config.instance().get_config_files(): user_log.info("Config file {} loaded".format(config_file)) set_config(args) server_config = Config.instance().get_section_config("Server") if server_config.getboolean("local"): log.warning( "Local mode is enabled. Beware, clients will have full control on your filesystem" ) # we only support Python 3 version >= 3.3 if sys.version_info < (3, 3): raise RuntimeError("Python 3.3 or higher is required") user_log.info( "Running with Python {major}.{minor}.{micro} and has PID {pid}".format( major=sys.version_info[0], minor=sys.version_info[1], micro=sys.version_info[2], pid=os.getpid())) # check for the correct locale (UNIX/Linux only) locale_check() try: os.getcwd() except FileNotFoundError: log.critical("The current working directory doesn't exist") return Project.clean_project_directory() CrashReport.instance() host = server_config["host"] port = int(server_config["port"]) server = Server.instance(host, port) try: server.run() except Exception as e: log.critical("Critical error while running the server: {}".format(e), exc_info=1) CrashReport.instance().capture_exception() return
def shutdown(request, response): config = Config.instance() if config.get_section_config("Server").getboolean("local", False) is False: raise HTTPForbidden(text="You can only stop a local server") # close all the projects first pm = ProjectManager.instance() projects = pm.projects tasks = [] for project in projects: tasks.append(asyncio. async (project.close())) if tasks: done, _ = yield from asyncio.wait(tasks) for future in done: try: future.result() except Exception as e: log.error("Could not close project {}".format(e), exc_info=1) continue # then shutdown the server itself from gns3server.server import Server server = Server.instance() asyncio. async (server.shutdown_server()) response.set_status(201)
def shutdown(request, response): config = Config.instance() if config.get_section_config("Server").getboolean("local", False) is False: raise HTTPForbidden(text="You can only stop a local server") # close all the projects first pm = ProjectManager.instance() projects = pm.projects tasks = [] for project in projects: tasks.append(asyncio.async(project.close())) if tasks: done, _ = yield from asyncio.wait(tasks) for future in done: try: future.result() except Exception as e: log.error("Could not close project {}".format(e), exc_info=1) continue # then shutdown the server itself from gns3server.server import Server server = Server.instance() asyncio.async(server.shutdown_server()) response.set_status(201)
def main(): """ Entry point for GNS3 server """ level = logging.INFO args = parse_arguments(sys.argv[1:], Config.instance().get_section_config("Server")) if args.debug: level = logging.DEBUG user_log = init_logger(level, logfile=args.log, quiet=args.quiet) user_log.info("GNS3 server version {}".format(__version__)) current_year = datetime.date.today().year user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) for config_file in Config.instance().get_config_files(): user_log.info("Config file {} loaded".format(config_file)) set_config(args) server_config = Config.instance().get_section_config("Server") if server_config.getboolean("local"): log.warning("Local mode is enabled. Beware, clients will have full control on your filesystem") # we only support Python 3 version >= 3.3 if sys.version_info < (3, 3): raise RuntimeError("Python 3.3 or higher is required") user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format( major=sys.version_info[0], minor=sys.version_info[1], micro=sys.version_info[2], pid=os.getpid())) # check for the correct locale (UNIX/Linux only) locale_check() try: os.getcwd() except FileNotFoundError: log.critical("The current working directory doesn't exist") return Project.clean_project_directory() CrashReport.instance() host = server_config["host"] port = int(server_config["port"]) server = Server.instance(host, port) try: server.run() except OSError as e: # This is to ignore OSError: [WinError 0] The operation completed successfully exception on Windows. if not sys.platform.startswith("win") and not e.winerror == 0: raise except Exception as e: log.critical("Critical error while running the server: {}".format(e), exc_info=1) CrashReport.instance().capture_exception() return
def run(): args = parse_arguments(sys.argv[1:]) if args.daemon and sys.platform.startswith("win"): log.critical("Daemon is not supported on Windows") sys.exit(1) if args.pid: pid_lock(args.pid) level = logging.INFO if args.debug: level = logging.DEBUG user_log = init_logger(level, logfile=args.log, quiet=args.quiet) user_log.info("GNS3 server version {}".format(__version__)) current_year = datetime.date.today().year user_log.info( "Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) for config_file in Config.instance().get_config_files(): user_log.info("Config file {} loaded".format(config_file)) set_config(args) server_config = Config.instance().get_section_config("Server") if server_config.getboolean("local"): log.warning( "Local mode is enabled. Beware, clients will have full control on your filesystem" ) # we only support Python 3 version >= 3.4 if sys.version_info < (3, 4): raise SystemExit("Python 3.4 or higher is required") user_log.info( "Running with Python {major}.{minor}.{micro} and has PID {pid}".format( major=sys.version_info[0], minor=sys.version_info[1], micro=sys.version_info[2], pid=os.getpid())) # check for the correct locale (UNIX/Linux only) locale_check() try: os.getcwd() except FileNotFoundError: log.critical("The current working directory doesn't exist") return Project.clean_project_directory() CrashReport.instance() host = server_config["host"] port = int(server_config["port"]) server = Server.instance(host, port) try: server.run() except OSError as e: # This is to ignore OSError: [WinError 0] The operation completed successfully exception on Windows. if not sys.platform.startswith("win") and not e.winerror == 0: raise except Exception as e: log.critical("Critical error while running the server: {}".format(e), exc_info=1) CrashReport.instance().capture_exception() return if args.pid: log.info("Remove PID file %s", args.pid) try: os.remove(args.pid) except OSError as e: log.critical("Can't remove pid file %s: %s", args.pid, str(e))