mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 16:28:11 +00:00
Fix console port restoration for IOU and VPCS (when loading a project).
This commit is contained in:
parent
566c48ffed
commit
b42d751e89
@ -48,8 +48,8 @@ def locale_check():
|
||||
or there: http://robjwells.com/post/61198832297/get-your-us-ascii-out-of-my-face
|
||||
"""
|
||||
|
||||
# no need to check on Windows
|
||||
if sys.platform.startswith("win"):
|
||||
# no need to check on Windows or when frozen
|
||||
if sys.platform.startswith("win") or hasattr(sys, "frozen"):
|
||||
return
|
||||
|
||||
language = encoding = None
|
||||
|
@ -301,6 +301,7 @@ class IOU(IModule):
|
||||
|
||||
Optional request parameters:
|
||||
- name (IOU name)
|
||||
- console (IOU console port)
|
||||
|
||||
Response parameters:
|
||||
- id (IOU instance identifier)
|
||||
@ -314,9 +315,8 @@ class IOU(IModule):
|
||||
if not self.validate_request(request, IOU_CREATE_SCHEMA):
|
||||
return
|
||||
|
||||
name = None
|
||||
if "name" in request:
|
||||
name = request["name"]
|
||||
name = request.get("name")
|
||||
console = request.get("console")
|
||||
iou_path = request["path"]
|
||||
|
||||
try:
|
||||
@ -331,6 +331,7 @@ class IOU(IModule):
|
||||
self._working_dir,
|
||||
self._host,
|
||||
name,
|
||||
console,
|
||||
self._console_start_port_range,
|
||||
self._console_end_port_range)
|
||||
|
||||
|
@ -50,6 +50,7 @@ class IOUDevice(object):
|
||||
:param working_dir: path to a working directory
|
||||
:param host: host/address to bind for console and UDP connections
|
||||
:param name: name of this IOU device
|
||||
:param console: TCP console port
|
||||
:param console_start_port_range: TCP console port range start
|
||||
:param console_end_port_range: TCP console port range end
|
||||
"""
|
||||
@ -61,6 +62,7 @@ class IOUDevice(object):
|
||||
working_dir,
|
||||
host="127.0.0.1",
|
||||
name=None,
|
||||
console=None,
|
||||
console_start_port_range=4001,
|
||||
console_end_port_range=4512):
|
||||
|
||||
@ -82,7 +84,7 @@ class IOUDevice(object):
|
||||
self._path = path
|
||||
self._iourc = ""
|
||||
self._iouyap = ""
|
||||
self._console = None
|
||||
self._console = console
|
||||
self._working_dir = None
|
||||
self._command = []
|
||||
self._process = None
|
||||
@ -109,16 +111,20 @@ class IOUDevice(object):
|
||||
# update the working directory
|
||||
self.working_dir = working_dir
|
||||
|
||||
# allocate a console port
|
||||
try:
|
||||
self._console = find_unused_port(self._console_start_port_range,
|
||||
self._console_end_port_range,
|
||||
self._host,
|
||||
ignore_ports=self._allocated_console_ports)
|
||||
except Exception as e:
|
||||
raise IOUError(e)
|
||||
if not self._console:
|
||||
# allocate a console port
|
||||
try:
|
||||
self._console = find_unused_port(self._console_start_port_range,
|
||||
self._console_end_port_range,
|
||||
self._host,
|
||||
ignore_ports=self._allocated_console_ports)
|
||||
except Exception as e:
|
||||
raise IOUError(e)
|
||||
|
||||
if self._console in self._allocated_console_ports:
|
||||
raise IOUError("Console port {} is already in used another IOU device".format(console))
|
||||
self._allocated_console_ports.append(self._console)
|
||||
|
||||
log.info("IOU device {name} [id={id}] has been created".format(name=self._name,
|
||||
id=self._id))
|
||||
|
||||
@ -317,7 +323,7 @@ class IOUDevice(object):
|
||||
"""
|
||||
|
||||
if console in self._allocated_console_ports:
|
||||
raise IOUError("Console port {} is already in used by another IOU device".format(console))
|
||||
raise IOUError("Console port {} is already used by another IOU device".format(console))
|
||||
|
||||
self._allocated_console_ports.remove(self._console)
|
||||
self._console = console
|
||||
|
@ -393,14 +393,12 @@ class IOU(Router):
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except Exception as e:
|
||||
raise NetioError("Couldn't unlink socket {}: {}"
|
||||
.format(self.ttyC, e))
|
||||
raise NetioError("Couldn't unlink socket {}: {}".format(self.ttyC, e))
|
||||
|
||||
try:
|
||||
self.fd.bind(self.ttyC)
|
||||
except Exception as e:
|
||||
raise NetioError("Couldn't create socket {}: {}"
|
||||
.format(self.ttyC, e))
|
||||
raise NetioError("Couldn't create socket {}: {}".format(self.ttyC, e))
|
||||
|
||||
def _connect(self):
|
||||
# Keep trying until we connect or die trying
|
||||
@ -411,8 +409,7 @@ class IOU(Router):
|
||||
log.debug("Waiting to connect to {}".format(self.ttyS))
|
||||
time.sleep(RETRY_DELAY)
|
||||
except Exception as e:
|
||||
raise NetioError("Couldn't connect to socket {}: {}"
|
||||
.format(self.ttyS, e))
|
||||
raise NetioError("Couldn't connect to socket {}: {}".format(self.ttyS, e))
|
||||
else:
|
||||
break
|
||||
|
||||
@ -465,8 +462,7 @@ def mkdir_netio(netio_dir):
|
||||
except FileExistsError:
|
||||
pass
|
||||
except Exception as e:
|
||||
raise NetioError("Couldn't create directory {}: {}"
|
||||
.format(netio_dir, e))
|
||||
raise NetioError("Couldn't create directory {}: {}".format(netio_dir, e))
|
||||
|
||||
|
||||
def send_recv_loop(console, router, esc_char, stop_event):
|
||||
@ -631,7 +627,7 @@ def start_ioucon(cmdline_args, stop_event):
|
||||
if args.debug:
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
else:
|
||||
print(e, file=sys.stderr)
|
||||
log.error("ioucon: {}".format(e))
|
||||
sys.exit(EXIT_FAILURE)
|
||||
|
||||
log.info("exiting...")
|
||||
|
@ -26,13 +26,19 @@ IOU_CREATE_SCHEMA = {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
},
|
||||
"console": {
|
||||
"description": "console TCP port",
|
||||
"minimum": 1,
|
||||
"maximum": 65535,
|
||||
"type": "integer"
|
||||
},
|
||||
"path": {
|
||||
"description": "path to the IOU executable",
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
}
|
||||
},
|
||||
"required": ["path"]
|
||||
"required": ["path"],
|
||||
}
|
||||
|
||||
IOU_DELETE_SCHEMA = {
|
||||
|
@ -213,6 +213,7 @@ class VPCS(IModule):
|
||||
|
||||
Optional request parameters:
|
||||
- name (VPCS name)
|
||||
- console (VPCS console port)
|
||||
|
||||
Response parameters:
|
||||
- id (VPCS instance identifier)
|
||||
@ -226,9 +227,10 @@ class VPCS(IModule):
|
||||
if request and not self.validate_request(request, VPCS_CREATE_SCHEMA):
|
||||
return
|
||||
|
||||
name = None
|
||||
if request and "name" in request:
|
||||
name = request["name"]
|
||||
name = console = None
|
||||
if request:
|
||||
name = request.get("name")
|
||||
console = request.get("console")
|
||||
|
||||
try:
|
||||
try:
|
||||
@ -245,6 +247,7 @@ class VPCS(IModule):
|
||||
self._working_dir,
|
||||
self._host,
|
||||
name,
|
||||
console,
|
||||
self._console_start_port_range,
|
||||
self._console_end_port_range)
|
||||
|
||||
|
@ -26,6 +26,12 @@ VPCS_CREATE_SCHEMA = {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
},
|
||||
"console": {
|
||||
"description": "console TCP port",
|
||||
"minimum": 1,
|
||||
"maximum": 65535,
|
||||
"type": "integer"
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ class VPCSDevice(object):
|
||||
:param working_dir: path to a working directory
|
||||
:param host: host/address to bind for console and UDP connections
|
||||
:param name: name of this VPCS device
|
||||
:param console: TCP console port
|
||||
:param console_start_port_range: TCP console port range start
|
||||
:param console_end_port_range: TCP console port range end
|
||||
"""
|
||||
@ -55,6 +56,7 @@ class VPCSDevice(object):
|
||||
working_dir,
|
||||
host="127.0.0.1",
|
||||
name=None,
|
||||
console=None,
|
||||
console_start_port_range=4512,
|
||||
console_end_port_range=5000):
|
||||
|
||||
@ -77,7 +79,7 @@ class VPCSDevice(object):
|
||||
self._name = "VPCS{}".format(self._id)
|
||||
|
||||
self._path = path
|
||||
self._console = None
|
||||
self._console = console
|
||||
self._working_dir = None
|
||||
self._command = []
|
||||
self._process = None
|
||||
@ -94,15 +96,18 @@ class VPCSDevice(object):
|
||||
# update the working directory
|
||||
self.working_dir = working_dir
|
||||
|
||||
# allocate a console port
|
||||
try:
|
||||
self._console = find_unused_port(self._console_start_port_range,
|
||||
self._console_end_port_range,
|
||||
self._host,
|
||||
ignore_ports=self._allocated_console_ports)
|
||||
except Exception as e:
|
||||
raise VPCSError(e)
|
||||
if not self._console:
|
||||
# allocate a console port
|
||||
try:
|
||||
self._console = find_unused_port(self._console_start_port_range,
|
||||
self._console_end_port_range,
|
||||
self._host,
|
||||
ignore_ports=self._allocated_console_ports)
|
||||
except Exception as e:
|
||||
raise VPCSError(e)
|
||||
|
||||
if self._console in self._allocated_console_ports:
|
||||
raise VPCSError("Console port {} is already used by another VPCS device".format(console))
|
||||
self._allocated_console_ports.append(self._console)
|
||||
|
||||
log.info("VPCS device {name} [id={id}] has been created".format(name=self._name,
|
||||
@ -250,7 +255,7 @@ class VPCSDevice(object):
|
||||
"""
|
||||
|
||||
if console in self._allocated_console_ports:
|
||||
raise VPCSError("Console port {} is already in used by another VPCS device".format(console))
|
||||
raise VPCSError("Console port {} is already used by another VPCS device".format(console))
|
||||
|
||||
self._allocated_console_ports.remove(self._console)
|
||||
self._console = console
|
||||
|
Loading…
Reference in New Issue
Block a user