1
0
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:
grossmj 2014-04-06 11:37:34 -06:00
parent f4dd096a8b
commit 27379682df
5 changed files with 13 additions and 17 deletions

View File

@ -20,10 +20,9 @@ import os
import datetime
import sys
import multiprocessing
import logging
import tornado.options
from .server import Server
from .version import __version__
from gns3server.server import Server
from gns3server.version import __version__
# command line options
from tornado.options import define
@ -60,9 +59,6 @@ def main():
tornado.options.print_help()
raise SystemExit
# FIXME: log everything for now (excepting DEBUG)
logging.basicConfig(level=logging.INFO)
from tornado.options import options
server = Server(options.host,
options.port,

View File

@ -71,7 +71,7 @@ class DynamipsHypervisor(object):
self._socket = socket.create_connection((self._host,
self._port),
self._timeout)
except socket.error as e:
except OSError as e:
raise DynamipsError("Could not connect to server: {}".format(e))
try:
@ -362,7 +362,7 @@ class DynamipsHypervisor(object):
with socket.socket(socket.AF_INET, socket_type) as s:
s.bind((host, port)) # the port is available if bind is a success
return port
except socket.error as e:
except OSError as e:
if e.errno == errno.EADDRINUSE: # socket already in use
continue
else:
@ -428,7 +428,7 @@ class DynamipsHypervisor(object):
command = command.strip() + '\n'
log.debug("sending {}".format(command))
self.socket.sendall(command.encode('utf-8'))
except socket.error as e:
except OSError as e:
raise DynamipsError("Lost communication with {host}:{port} :{error}"
.format(host=self._host, port=self._port, error=e))
@ -439,7 +439,7 @@ class DynamipsHypervisor(object):
try:
chunk = self.socket.recv(1024) # match to Dynamips' buffer size
buf += chunk.decode("utf-8")
except socket.error as e:
except OSError as e:
raise DynamipsError("Communication timed out with {host}:{port} :{error}"
.format(host=self._host, port=self._port, error=e))

View File

@ -412,7 +412,7 @@ class HypervisorManager(object):
try:
with socket.create_connection((host, port), timeout):
pass
except socket.error as e:
except OSError as e:
last_exception = e
continue
connection_success = True

View File

@ -798,7 +798,7 @@ class IOUDevice(object):
with socket.socket(socket.AF_INET, socket_type) as s:
s.bind((host, port)) # the port is available if bind is a success
return port
except socket.error as e:
except OSError as e:
if e.errno == errno.EADDRINUSE: # socket already in use
continue
else:

View File

@ -61,7 +61,7 @@ class Server(object):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind(('127.0.0.1', 0))
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))
self._zmq_port = port + 1 # let's try this server port + 1
self._ipc = ipc
@ -137,10 +137,10 @@ class Server(object):
try:
print("Starting server on {}:{}".format(self._host, self._port))
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
logging.critical("socket in use for port {}".format(self._port))
raise SystemExit
logging.critical("socket in use for {}:{}".format(self._host, self._port))
self._cleanup()
ioloop = tornado.ioloop.IOLoop.instance()
stream = zmqstream.ZMQStream(router, ioloop)
@ -212,7 +212,7 @@ class Server(object):
# terminate all modules
for module in self._modules:
module.join(timeout=1)
#module.join(timeout=1)
if module.is_alive():
log.info("terminating {}".format(module.name))
module.terminate()