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