mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Add a --quiet mode to gns3server
This commit is contained in:
parent
3b465890b6
commit
23686215fe
@ -34,6 +34,7 @@ define("host", default="0.0.0.0", help="run on the given host/IP address", type=
|
|||||||
define("port", default=8000, help="run on the given port", type=int)
|
define("port", default=8000, help="run on the given port", type=int)
|
||||||
define("ipc", default=False, help="use IPC for module communication", type=bool)
|
define("ipc", default=False, help="use IPC for module communication", type=bool)
|
||||||
define("version", default=False, help="show the version", type=bool)
|
define("version", default=False, help="show the version", type=bool)
|
||||||
|
define("quiet", default=False, help="do not show output on stdout", type=bool)
|
||||||
|
|
||||||
|
|
||||||
def locale_check():
|
def locale_check():
|
||||||
@ -96,6 +97,10 @@ def main():
|
|||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
current_year = datetime.date.today().year
|
current_year = datetime.date.today().year
|
||||||
|
if options.quiet:
|
||||||
|
log.info("GNS3 server version {}".format(__version__))
|
||||||
|
log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
|
||||||
|
else:
|
||||||
print("GNS3 server version {}".format(__version__))
|
print("GNS3 server version {}".format(__version__))
|
||||||
print("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
|
print("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
|
||||||
|
|
||||||
@ -103,10 +108,14 @@ def main():
|
|||||||
if sys.version_info < (3, 3):
|
if sys.version_info < (3, 3):
|
||||||
raise RuntimeError("Python 3.3 or higher is required")
|
raise RuntimeError("Python 3.3 or higher is required")
|
||||||
|
|
||||||
print("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(major=sys.version_info[0],
|
if options.quiet:
|
||||||
minor=sys.version_info[1],
|
log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
|
||||||
micro=sys.version_info[2],
|
major=sys.version_info[0], minor=sys.version_info[1],
|
||||||
pid=os.getpid()))
|
micro=sys.version_info[2], pid=os.getpid()))
|
||||||
|
else:
|
||||||
|
print("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
|
# check for the correct locale
|
||||||
# (UNIX/Linux only)
|
# (UNIX/Linux only)
|
||||||
@ -118,9 +127,7 @@ def main():
|
|||||||
log.critical("the current working directory doesn't exist")
|
log.critical("the current working directory doesn't exist")
|
||||||
return
|
return
|
||||||
|
|
||||||
server = Server(options.host,
|
server = Server(options.host, options.port, options.ipc, options.quiet)
|
||||||
options.port,
|
|
||||||
ipc=options.ipc)
|
|
||||||
server.load_modules()
|
server.load_modules()
|
||||||
server.run()
|
server.run()
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class Server(object):
|
|||||||
(r"/upload", FileUploadHandler),
|
(r"/upload", FileUploadHandler),
|
||||||
(r"/login", LoginHandler)]
|
(r"/login", LoginHandler)]
|
||||||
|
|
||||||
def __init__(self, host, port, ipc=False):
|
def __init__(self, host, port, ipc, quiet):
|
||||||
|
|
||||||
self._host = host
|
self._host = host
|
||||||
self._port = port
|
self._port = port
|
||||||
@ -78,6 +78,7 @@ class Server(object):
|
|||||||
log.critical("server cannot listen to {}: {}".format(self._host, e))
|
log.critical("server cannot listen to {}: {}".format(self._host, e))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
self._ipc = ipc
|
self._ipc = ipc
|
||||||
|
self._quiet = quiet
|
||||||
self._modules = []
|
self._modules = []
|
||||||
|
|
||||||
# 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)
|
||||||
@ -188,11 +189,13 @@ class Server(object):
|
|||||||
**settings) # FIXME: debug mode!
|
**settings) # FIXME: debug mode!
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("Starting server on {}:{} (Tornado v{}, PyZMQ v{}, ZMQ v{})".format(self._host,
|
if self._quiet:
|
||||||
self._port,
|
log.info("Starting server on {}:{} (Tornado v{}, PyZMQ v{}, ZMQ v{})".format(
|
||||||
tornado.version,
|
self._host, self._port, tornado.version, zmq.__version__, zmq.zmq_version()))
|
||||||
zmq.__version__,
|
else:
|
||||||
zmq.zmq_version()))
|
print("Starting server on {}:{} (Tornado v{}, PyZMQ v{}, ZMQ v{})".format(
|
||||||
|
self._host, self._port, tornado.version, zmq.__version__, zmq.zmq_version()))
|
||||||
|
|
||||||
kwargs = {"address": self._host}
|
kwargs = {"address": self._host}
|
||||||
|
|
||||||
if ssl_options:
|
if ssl_options:
|
||||||
@ -230,6 +233,9 @@ class Server(object):
|
|||||||
try:
|
try:
|
||||||
ioloop.start()
|
ioloop.start()
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
if self._quiet:
|
||||||
|
log.info("\nExiting...")
|
||||||
|
else:
|
||||||
print("\nExiting...")
|
print("\nExiting...")
|
||||||
self._cleanup()
|
self._cleanup()
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@
|
|||||||
# number has been incremented)
|
# number has been incremented)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Startup script for GNS3 Server Cloud Instance
|
Startup script for a GNS3 Server Cloud Instance. It generates certificates,
|
||||||
|
config files and usernames before finally starting the gns3server process
|
||||||
|
on the instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -67,12 +69,12 @@ Options:
|
|||||||
|
|
||||||
""" % (SCRIPT_NAME)
|
""" % (SCRIPT_NAME)
|
||||||
|
|
||||||
# Parse cmd line options
|
|
||||||
def parse_cmd_line(argv):
|
def parse_cmd_line(argv):
|
||||||
"""
|
"""
|
||||||
Parse command line arguments
|
Parse command line arguments
|
||||||
|
|
||||||
argv: Pass in cmd line arguments
|
argv: Passed in sys.argv
|
||||||
"""
|
"""
|
||||||
|
|
||||||
short_args = "dvh"
|
short_args = "dvh"
|
||||||
@ -88,10 +90,7 @@ def parse_cmd_line(argv):
|
|||||||
print(usage)
|
print(usage)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
cmd_line_option_list = {}
|
cmd_line_option_list = {'debug': False, 'verbose': True, 'data': None}
|
||||||
cmd_line_option_list["debug"] = False
|
|
||||||
cmd_line_option_list["verbose"] = True
|
|
||||||
cmd_line_option_list["data"] = None
|
|
||||||
|
|
||||||
if sys.platform == "linux":
|
if sys.platform == "linux":
|
||||||
cmd_line_option_list['syslog'] = "/dev/log"
|
cmd_line_option_list['syslog'] = "/dev/log"
|
||||||
@ -101,14 +100,14 @@ def parse_cmd_line(argv):
|
|||||||
cmd_line_option_list['syslog'] = ('localhost',514)
|
cmd_line_option_list['syslog'] = ('localhost',514)
|
||||||
|
|
||||||
for opt, val in opts:
|
for opt, val in opts:
|
||||||
if (opt in ("-h", "--help")):
|
if opt in ("-h", "--help"):
|
||||||
print(usage)
|
print(usage)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif (opt in ("-d", "--debug")):
|
elif opt in ("-d", "--debug"):
|
||||||
cmd_line_option_list["debug"] = True
|
cmd_line_option_list["debug"] = True
|
||||||
elif (opt in ("-v", "--verbose")):
|
elif opt in ("-v", "--verbose"):
|
||||||
cmd_line_option_list["verbose"] = True
|
cmd_line_option_list["verbose"] = True
|
||||||
elif (opt in ("--data")):
|
elif opt in ("--data",):
|
||||||
cmd_line_option_list["data"] = ast.literal_eval(val)
|
cmd_line_option_list["data"] = ast.literal_eval(val)
|
||||||
|
|
||||||
return cmd_line_option_list
|
return cmd_line_option_list
|
||||||
@ -124,10 +123,10 @@ def set_logging(cmd_options):
|
|||||||
log_level = logging.INFO
|
log_level = logging.INFO
|
||||||
log_level_console = logging.WARNING
|
log_level_console = logging.WARNING
|
||||||
|
|
||||||
if cmd_options['verbose'] == True:
|
if cmd_options['verbose'] is True:
|
||||||
log_level_console = logging.INFO
|
log_level_console = logging.INFO
|
||||||
|
|
||||||
if cmd_options['debug'] == True:
|
if cmd_options['debug'] is True:
|
||||||
log_level_console = logging.DEBUG
|
log_level_console = logging.DEBUG
|
||||||
log_level = logging.DEBUG
|
log_level = logging.DEBUG
|
||||||
|
|
||||||
@ -138,24 +137,30 @@ def set_logging(cmd_options):
|
|||||||
console_log.setLevel(log_level_console)
|
console_log.setLevel(log_level_console)
|
||||||
console_log.setFormatter(formatter)
|
console_log.setFormatter(formatter)
|
||||||
|
|
||||||
syslog_hndlr = SysLogHandler(
|
syslog_handler = SysLogHandler(
|
||||||
address=cmd_options['syslog'],
|
address=cmd_options['syslog'],
|
||||||
facility=SysLogHandler.LOG_KERN
|
facility=SysLogHandler.LOG_KERN
|
||||||
)
|
)
|
||||||
|
|
||||||
syslog_hndlr.setFormatter(sys_formatter)
|
syslog_handler.setFormatter(sys_formatter)
|
||||||
|
|
||||||
log.setLevel(log_level)
|
log.setLevel(log_level)
|
||||||
log.addHandler(console_log)
|
log.addHandler(console_log)
|
||||||
log.addHandler(syslog_hndlr)
|
log.addHandler(syslog_handler)
|
||||||
|
|
||||||
return log
|
return log
|
||||||
|
|
||||||
def _generate_certs():
|
|
||||||
cmd = []
|
|
||||||
cmd.append("%s/cert_utils/create_cert.sh" % (SCRIPT_PATH))
|
|
||||||
|
|
||||||
log.debug("Generating certs ...")
|
def _generate_certs():
|
||||||
|
"""
|
||||||
|
Generate a self-signed certificate for SSL-enabling the WebSocket
|
||||||
|
connection. The certificate is sent back to the client so it can
|
||||||
|
verify the authenticity of the server.
|
||||||
|
|
||||||
|
:return: A 2-tuple of strings containing (server_key, server_cert)
|
||||||
|
"""
|
||||||
|
cmd = ["{}/cert_utils/create_cert.sh".format(SCRIPT_PATH)]
|
||||||
|
log.debug("Generating certs with cmd: {}".format(' '.join(cmd)))
|
||||||
output_raw = subprocess.check_output(cmd, shell=False,
|
output_raw = subprocess.check_output(cmd, shell=False,
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
@ -164,11 +169,15 @@ def _generate_certs():
|
|||||||
log.debug(output)
|
log.debug(output)
|
||||||
return (output[-2], output[-1])
|
return (output[-2], output[-1])
|
||||||
|
|
||||||
def _start_gns3server():
|
|
||||||
cmd = []
|
|
||||||
cmd.append("gns3server")
|
|
||||||
|
|
||||||
log.info("Starting gns3server ...")
|
def _start_gns3server():
|
||||||
|
"""
|
||||||
|
Start up the gns3 server.
|
||||||
|
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
cmd = ['gns3server', '--quiet']
|
||||||
|
log.info("Starting gns3server with cmd {}".format(cmd))
|
||||||
subprocess.Popen(cmd, shell=False)
|
subprocess.Popen(cmd, shell=False)
|
||||||
|
|
||||||
|
|
||||||
@ -187,7 +196,6 @@ def main():
|
|||||||
log.info("Received shutdown signal")
|
log.info("Received shutdown signal")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
# Setup signal to catch Control-C / SIGINT and SIGTERM
|
# Setup signal to catch Control-C / SIGINT and SIGTERM
|
||||||
signal.signal(signal.SIGINT, _shutdown)
|
signal.signal(signal.SIGINT, _shutdown)
|
||||||
signal.signal(signal.SIGTERM, _shutdown)
|
signal.signal(signal.SIGTERM, _shutdown)
|
||||||
@ -229,12 +237,14 @@ def main():
|
|||||||
|
|
||||||
cert_file.close()
|
cert_file.close()
|
||||||
|
|
||||||
|
# Return a stringified dictionary on stdout. The gui captures this to get
|
||||||
|
# things like the server cert.
|
||||||
client_data['SSL_CRT_FILE'] = server_crt
|
client_data['SSL_CRT_FILE'] = server_crt
|
||||||
client_data['SSL_CRT'] = cert_data
|
client_data['SSL_CRT'] = cert_data
|
||||||
client_data['WEB_USERNAME'] = cloud_config['CLOUD_SERVER']['WEB_USERNAME']
|
client_data['WEB_USERNAME'] = cloud_config['CLOUD_SERVER']['WEB_USERNAME']
|
||||||
client_data['WEB_PASSWORD'] = cloud_config['CLOUD_SERVER']['WEB_PASSWORD']
|
client_data['WEB_PASSWORD'] = cloud_config['CLOUD_SERVER']['WEB_PASSWORD']
|
||||||
|
|
||||||
print(client_data)
|
print(client_data)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user