1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Fixes module unload & adds host, port and allow-remote-console command line args.

This commit is contained in:
Jeremy 2015-01-23 13:01:23 -07:00
parent 59f940625a
commit 39e3ca91a9
6 changed files with 36 additions and 23 deletions

View File

@ -128,7 +128,7 @@ class Config(object):
dumped on the disk. dumped on the disk.
:param section: Section name :param section: Section name
:param content: A dictonary with section content :param content: A dictionary with section content
""" """
self._config[section] = content self._config[section] = content

View File

@ -72,11 +72,12 @@ def locale_check():
def parse_arguments(): def parse_arguments():
parser = argparse.ArgumentParser(description='GNS 3 server') parser = argparse.ArgumentParser(description="GNS3 server version {}".format(__version__))
parser.add_argument('--local', parser.add_argument("-l", "--host", help="run on the given host/IP address", default="127.0.0.1", nargs="?")
action="store_true", parser.add_argument("-p", "--port", type=int, help="run on the given port", default=8000, nargs="?")
dest='local', parser.add_argument("-v", "--version", help="show the version", action="version", version=__version__)
help='Local mode (allow some insecure operations)') 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() args = parser.parse_args()
config = Config.instance() config = Config.instance()
@ -84,7 +85,16 @@ def parse_arguments():
if args.local: if args.local:
server_config["local"] = "true" 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) 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). # TODO: migrate command line options to argparse (don't forget the quiet mode).
current_year = datetime.date.today().year current_year = datetime.date.today().year
# TODO: Renable the test when we will have command line # TODO: Renable the test when we will have command line
# user_log = logging.getLogger('user_facing') # user_log = logging.getLogger('user_facing')
# if not options.quiet: # if not options.quiet:
@ -107,7 +116,6 @@ def main():
# user_log.propagate = False # user_log.propagate = False
# END OLD LOG CODE # END OLD LOG CODE
user_log = init_logger(logging.DEBUG, quiet=False) user_log = init_logger(logging.DEBUG, quiet=False)
# FIXME END Temporary
parse_arguments() parse_arguments()
@ -115,10 +123,8 @@ def main():
user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
server_config = Config.instance().get_section_config("Server") server_config = Config.instance().get_section_config("Server")
if server_config["local"]: if server_config.getboolean("local"):
log.warning("Local mode is enabled. Beware it's allow a full control on your filesystem") log.warning("Local mode is enabled. Beware, clients will have full control on your filesystem")
# TODO: end todo
# we only support Python 3 version >= 3.3 # we only support Python 3 version >= 3.3
if sys.version_info < (3, 3): if sys.version_info < (3, 3):
@ -137,9 +143,9 @@ def main():
log.critical("The current working directory doesn't exist") log.critical("The current working directory doesn't exist")
return return
# TODO: Renable console_bind_to_any when we will have command line parsing host = server_config["host"]
# server = Server(options.host, options.port, options.console_bind_to_any) port = int(server_config["port"])
server = Server("127.0.0.1", 8000, False) server = Server(host, port)
server.run() server.run()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -106,6 +106,7 @@ class BaseManager:
if hasattr(BaseManager, "_instance"): if hasattr(BaseManager, "_instance"):
BaseManager._instance = None BaseManager._instance = None
log.debug("Module {} unloaded".format(self.module_name))
def get_vm(self, uuid): def get_vm(self, uuid):
""" """

View File

@ -17,17 +17,19 @@
import socket import socket
import ipaddress import ipaddress
import asyncio
from aiohttp.web import HTTPConflict from aiohttp.web import HTTPConflict
from gns3server.config import Config
import logging
log = logging.getLogger(__name__)
class PortManager: class PortManager:
""" """
:param host: IP address to bind for console connections :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._console_host = host
self._udp_host = host self._udp_host = host
@ -37,7 +39,11 @@ class PortManager:
self._used_tcp_ports = set() self._used_tcp_ports = set()
self._used_udp_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: if ipaddress.ip_address(host).version == 6:
self._console_host = "::" self._console_host = "::"
else: else:

View File

@ -42,13 +42,13 @@ log = logging.getLogger(__name__)
class Server: class Server:
def __init__(self, host, port, console_bind_to_any): def __init__(self, host, port):
self._host = host self._host = host
self._port = port self._port = port
self._loop = None self._loop = None
self._start_time = time.time() 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 # TODO: server config file support, to be reviewed
# # get the projects and temp directories from the configuration file (passed to the modules) # # get the projects and temp directories from the configuration file (passed to the modules)
@ -80,7 +80,7 @@ class Server:
for module in MODULES: for module in MODULES:
log.debug("Unloading module {}".format(module.__name__)) log.debug("Unloading module {}".format(module.__name__))
m = module.instance() m = module.instance()
self._loop.run_until_complete(m.unload()) asyncio.async(m.unload())
self._loop.stop() self._loop.stop()
def _signal_handling(self): def _signal_handling(self):

View File

@ -57,7 +57,7 @@ def _get_unused_port():
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def server(request, loop, port_manager): def server(request, loop, port_manager):
"""A GNS 3 server""" """A GNS3 server"""
port = _get_unused_port() port = _get_unused_port()
host = "localhost" host = "localhost"