mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Fixes module unload & adds host, port and allow-remote-console command line args.
This commit is contained in:
parent
59f940625a
commit
39e3ca91a9
@ -128,7 +128,7 @@ class Config(object):
|
||||
dumped on the disk.
|
||||
|
||||
:param section: Section name
|
||||
:param content: A dictonary with section content
|
||||
:param content: A dictionary with section content
|
||||
"""
|
||||
|
||||
self._config[section] = content
|
||||
|
@ -72,11 +72,12 @@ def locale_check():
|
||||
|
||||
def parse_arguments():
|
||||
|
||||
parser = argparse.ArgumentParser(description='GNS 3 server')
|
||||
parser.add_argument('--local',
|
||||
action="store_true",
|
||||
dest='local',
|
||||
help='Local mode (allow some insecure operations)')
|
||||
parser = argparse.ArgumentParser(description="GNS3 server version {}".format(__version__))
|
||||
parser.add_argument("-l", "--host", help="run on the given host/IP address", default="127.0.0.1", nargs="?")
|
||||
parser.add_argument("-p", "--port", type=int, help="run on the given port", default=8000, nargs="?")
|
||||
parser.add_argument("-v", "--version", help="show the version", action="version", version=__version__)
|
||||
parser.add_argument("-L", "--local", action="store_true", help="Local mode (allow some insecure operations)")
|
||||
parser.add_argument("-A", "--allow-remote-console", dest="allow", action="store_true", help="Allow remote connections to console ports")
|
||||
args = parser.parse_args()
|
||||
|
||||
config = Config.instance()
|
||||
@ -84,7 +85,16 @@ def parse_arguments():
|
||||
|
||||
if args.local:
|
||||
server_config["local"] = "true"
|
||||
else:
|
||||
server_config["local"] = "false"
|
||||
|
||||
if args.allow:
|
||||
server_config["allow_remote_console"] = "true"
|
||||
else:
|
||||
server_config["allow_remote_console"] = "false"
|
||||
|
||||
server_config["host"] = args.host
|
||||
server_config["port"] = str(args.port)
|
||||
config.set_section_config("Server", server_config)
|
||||
|
||||
|
||||
@ -96,7 +106,6 @@ def main():
|
||||
# TODO: migrate command line options to argparse (don't forget the quiet mode).
|
||||
|
||||
current_year = datetime.date.today().year
|
||||
|
||||
# TODO: Renable the test when we will have command line
|
||||
# user_log = logging.getLogger('user_facing')
|
||||
# if not options.quiet:
|
||||
@ -107,7 +116,6 @@ def main():
|
||||
# user_log.propagate = False
|
||||
# END OLD LOG CODE
|
||||
user_log = init_logger(logging.DEBUG, quiet=False)
|
||||
# FIXME END Temporary
|
||||
|
||||
parse_arguments()
|
||||
|
||||
@ -115,10 +123,8 @@ def main():
|
||||
user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
|
||||
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
if server_config["local"]:
|
||||
log.warning("Local mode is enabled. Beware it's allow a full control on your filesystem")
|
||||
|
||||
# TODO: end todo
|
||||
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):
|
||||
@ -137,9 +143,9 @@ def main():
|
||||
log.critical("The current working directory doesn't exist")
|
||||
return
|
||||
|
||||
# TODO: Renable console_bind_to_any when we will have command line parsing
|
||||
# server = Server(options.host, options.port, options.console_bind_to_any)
|
||||
server = Server("127.0.0.1", 8000, False)
|
||||
host = server_config["host"]
|
||||
port = int(server_config["port"])
|
||||
server = Server(host, port)
|
||||
server.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -106,6 +106,7 @@ class BaseManager:
|
||||
|
||||
if hasattr(BaseManager, "_instance"):
|
||||
BaseManager._instance = None
|
||||
log.debug("Module {} unloaded".format(self.module_name))
|
||||
|
||||
def get_vm(self, uuid):
|
||||
"""
|
||||
|
@ -17,17 +17,19 @@
|
||||
|
||||
import socket
|
||||
import ipaddress
|
||||
import asyncio
|
||||
from aiohttp.web import HTTPConflict
|
||||
from gns3server.config import Config
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PortManager:
|
||||
|
||||
"""
|
||||
:param host: IP address to bind for console connections
|
||||
"""
|
||||
|
||||
def __init__(self, host="127.0.0.1", console_bind_to_any=False):
|
||||
def __init__(self, host="127.0.0.1"):
|
||||
|
||||
self._console_host = host
|
||||
self._udp_host = host
|
||||
@ -37,7 +39,11 @@ class PortManager:
|
||||
self._used_tcp_ports = set()
|
||||
self._used_udp_ports = set()
|
||||
|
||||
if console_bind_to_any:
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
remote_console_connections = server_config.getboolean("allow_remote_console")
|
||||
|
||||
if remote_console_connections:
|
||||
log.warning("Remote console connections are allowed")
|
||||
if ipaddress.ip_address(host).version == 6:
|
||||
self._console_host = "::"
|
||||
else:
|
||||
|
@ -42,13 +42,13 @@ log = logging.getLogger(__name__)
|
||||
|
||||
class Server:
|
||||
|
||||
def __init__(self, host, port, console_bind_to_any):
|
||||
def __init__(self, host, port):
|
||||
|
||||
self._host = host
|
||||
self._port = port
|
||||
self._loop = None
|
||||
self._start_time = time.time()
|
||||
self._port_manager = PortManager(host, console_bind_to_any)
|
||||
self._port_manager = PortManager(host)
|
||||
|
||||
# TODO: server config file support, to be reviewed
|
||||
# # get the projects and temp directories from the configuration file (passed to the modules)
|
||||
@ -80,7 +80,7 @@ class Server:
|
||||
for module in MODULES:
|
||||
log.debug("Unloading module {}".format(module.__name__))
|
||||
m = module.instance()
|
||||
self._loop.run_until_complete(m.unload())
|
||||
asyncio.async(m.unload())
|
||||
self._loop.stop()
|
||||
|
||||
def _signal_handling(self):
|
||||
|
@ -57,7 +57,7 @@ def _get_unused_port():
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def server(request, loop, port_manager):
|
||||
"""A GNS 3 server"""
|
||||
"""A GNS3 server"""
|
||||
|
||||
port = _get_unused_port()
|
||||
host = "localhost"
|
||||
|
Loading…
Reference in New Issue
Block a user