mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Rename socket.error to OSError.
Server shutdown management.
This commit is contained in:
parent
f4dd096a8b
commit
27379682df
@ -20,10 +20,9 @@ import os
|
|||||||
import datetime
|
import datetime
|
||||||
import sys
|
import sys
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import logging
|
|
||||||
import tornado.options
|
import tornado.options
|
||||||
from .server import Server
|
from gns3server.server import Server
|
||||||
from .version import __version__
|
from gns3server.version import __version__
|
||||||
|
|
||||||
# command line options
|
# command line options
|
||||||
from tornado.options import define
|
from tornado.options import define
|
||||||
@ -60,9 +59,6 @@ def main():
|
|||||||
tornado.options.print_help()
|
tornado.options.print_help()
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
# FIXME: log everything for now (excepting DEBUG)
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
|
|
||||||
from tornado.options import options
|
from tornado.options import options
|
||||||
server = Server(options.host,
|
server = Server(options.host,
|
||||||
options.port,
|
options.port,
|
||||||
|
@ -71,7 +71,7 @@ class DynamipsHypervisor(object):
|
|||||||
self._socket = socket.create_connection((self._host,
|
self._socket = socket.create_connection((self._host,
|
||||||
self._port),
|
self._port),
|
||||||
self._timeout)
|
self._timeout)
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
raise DynamipsError("Could not connect to server: {}".format(e))
|
raise DynamipsError("Could not connect to server: {}".format(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -362,7 +362,7 @@ class DynamipsHypervisor(object):
|
|||||||
with socket.socket(socket.AF_INET, socket_type) as s:
|
with socket.socket(socket.AF_INET, socket_type) as s:
|
||||||
s.bind((host, port)) # the port is available if bind is a success
|
s.bind((host, port)) # the port is available if bind is a success
|
||||||
return port
|
return port
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
if e.errno == errno.EADDRINUSE: # socket already in use
|
if e.errno == errno.EADDRINUSE: # socket already in use
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -428,7 +428,7 @@ class DynamipsHypervisor(object):
|
|||||||
command = command.strip() + '\n'
|
command = command.strip() + '\n'
|
||||||
log.debug("sending {}".format(command))
|
log.debug("sending {}".format(command))
|
||||||
self.socket.sendall(command.encode('utf-8'))
|
self.socket.sendall(command.encode('utf-8'))
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
raise DynamipsError("Lost communication with {host}:{port} :{error}"
|
raise DynamipsError("Lost communication with {host}:{port} :{error}"
|
||||||
.format(host=self._host, port=self._port, error=e))
|
.format(host=self._host, port=self._port, error=e))
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ class DynamipsHypervisor(object):
|
|||||||
try:
|
try:
|
||||||
chunk = self.socket.recv(1024) # match to Dynamips' buffer size
|
chunk = self.socket.recv(1024) # match to Dynamips' buffer size
|
||||||
buf += chunk.decode("utf-8")
|
buf += chunk.decode("utf-8")
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
raise DynamipsError("Communication timed out with {host}:{port} :{error}"
|
raise DynamipsError("Communication timed out with {host}:{port} :{error}"
|
||||||
.format(host=self._host, port=self._port, error=e))
|
.format(host=self._host, port=self._port, error=e))
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ class HypervisorManager(object):
|
|||||||
try:
|
try:
|
||||||
with socket.create_connection((host, port), timeout):
|
with socket.create_connection((host, port), timeout):
|
||||||
pass
|
pass
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
last_exception = e
|
last_exception = e
|
||||||
continue
|
continue
|
||||||
connection_success = True
|
connection_success = True
|
||||||
|
@ -798,7 +798,7 @@ class IOUDevice(object):
|
|||||||
with socket.socket(socket.AF_INET, socket_type) as s:
|
with socket.socket(socket.AF_INET, socket_type) as s:
|
||||||
s.bind((host, port)) # the port is available if bind is a success
|
s.bind((host, port)) # the port is available if bind is a success
|
||||||
return port
|
return port
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
if e.errno == errno.EADDRINUSE: # socket already in use
|
if e.errno == errno.EADDRINUSE: # socket already in use
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -61,7 +61,7 @@ class Server(object):
|
|||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||||
sock.bind(('127.0.0.1', 0))
|
sock.bind(('127.0.0.1', 0))
|
||||||
self._zmq_port = sock.getsockname()[1]
|
self._zmq_port = sock.getsockname()[1]
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
log.warn("could not pick up a random port for the ZeroMQ server: {}".format(e))
|
log.warn("could not pick up a random port for the ZeroMQ server: {}".format(e))
|
||||||
self._zmq_port = port + 1 # let's try this server port + 1
|
self._zmq_port = port + 1 # let's try this server port + 1
|
||||||
self._ipc = ipc
|
self._ipc = ipc
|
||||||
@ -137,10 +137,10 @@ class Server(object):
|
|||||||
try:
|
try:
|
||||||
print("Starting server on {}:{}".format(self._host, self._port))
|
print("Starting server on {}:{}".format(self._host, self._port))
|
||||||
tornado_app.listen(self._port, address=self._host)
|
tornado_app.listen(self._port, address=self._host)
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
if e.errno == errno.EADDRINUSE: # socket already in use
|
if e.errno == errno.EADDRINUSE: # socket already in use
|
||||||
logging.critical("socket in use for port {}".format(self._port))
|
logging.critical("socket in use for {}:{}".format(self._host, self._port))
|
||||||
raise SystemExit
|
self._cleanup()
|
||||||
|
|
||||||
ioloop = tornado.ioloop.IOLoop.instance()
|
ioloop = tornado.ioloop.IOLoop.instance()
|
||||||
stream = zmqstream.ZMQStream(router, ioloop)
|
stream = zmqstream.ZMQStream(router, ioloop)
|
||||||
@ -212,7 +212,7 @@ class Server(object):
|
|||||||
|
|
||||||
# terminate all modules
|
# terminate all modules
|
||||||
for module in self._modules:
|
for module in self._modules:
|
||||||
module.join(timeout=1)
|
#module.join(timeout=1)
|
||||||
if module.is_alive():
|
if module.is_alive():
|
||||||
log.info("terminating {}".format(module.name))
|
log.info("terminating {}".format(module.name))
|
||||||
module.terminate()
|
module.terminate()
|
||||||
|
Loading…
Reference in New Issue
Block a user