From b8353bc0d583a4ae8473cebe9b3af3b8ea0c84af Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 23 Mar 2018 15:44:16 +0700 Subject: [PATCH] Support for none console type (Qemu & Docker only) --- gns3server/compute/base_node.py | 14 ++++++-------- gns3server/compute/qemu/qemu_vm.py | 4 ++-- gns3server/schemas/docker.py | 6 +++--- gns3server/schemas/node.py | 2 +- gns3server/schemas/qemu.py | 8 ++++---- gns3server/ubridge/ubridge_hypervisor.py | 2 +- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/gns3server/compute/base_node.py b/gns3server/compute/base_node.py index 9e3ef625..1d9830fd 100644 --- a/gns3server/compute/base_node.py +++ b/gns3server/compute/base_node.py @@ -76,9 +76,11 @@ class BaseNode: self._allocate_aux = allocate_aux self._wrap_console = wrap_console self._wrapper_telnet_server = None + self._internal_console_port = None if self._console is not None: if console_type == "vnc": + # VNC is a special case and the range must be 5900-6000 self._console = self._manager.port_manager.reserve_tcp_port(self._console, self._project, port_range_start=5900, port_range_end=6000) else: self._console = self._manager.port_manager.reserve_tcp_port(self._console, self._project) @@ -87,13 +89,6 @@ class BaseNode: if self._aux is not None: self._aux = self._manager.port_manager.reserve_tcp_port(self._aux, self._project) - if self._console is None: - if console_type == "vnc": - # VNC is a special case and the range must be 5900-6000 - self._console = self._manager.port_manager.get_free_tcp_port(self._project, port_range_start=5900, port_range_end=6000) - else: - self._console = self._manager.port_manager.get_free_tcp_port(self._project) - if self._wrap_console: self._internal_console_port = self._manager.port_manager.get_free_tcp_port(self._project) @@ -457,7 +452,10 @@ class BaseNode: if console_type != self._console_type: # get a new port if the console type change self._manager.port_manager.release_tcp_port(self._console, self._project) - if console_type == "vnc": + if console_type == "none": + # no need to allocate a port when the console type is none + self._console = None + elif console_type == "vnc": # VNC is a special case and the range must be 5900-6000 self._console = self._manager.port_manager.get_free_tcp_port(self._project, 5900, 6000) else: diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 13801fde..b05b8482 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -973,7 +973,7 @@ class QemuVM(BaseNode): try: yield from self.start_wrap_console() except OSError as e: - raise QemuError("Could not start QEMU console {}\n".format(e)) + raise QemuError("Could not start Telnet QEMU console {}\n".format(e)) @asyncio.coroutine def _termination_callback(self, returncode): @@ -1803,7 +1803,7 @@ class QemuVM(BaseNode): command.extend(self._vnc_options()) elif self._console_type == "spice": command.extend(self._spice_options()) - else: + elif self._console_type != "none": raise QemuError("Console type {} is unknown".format(self._console_type)) command.extend(self._monitor_options()) command.extend((yield from self._network_options())) diff --git a/gns3server/schemas/docker.py b/gns3server/schemas/docker.py index d9934d74..bbf247ab 100644 --- a/gns3server/schemas/docker.py +++ b/gns3server/schemas/docker.py @@ -41,7 +41,7 @@ DOCKER_CREATE_SCHEMA = { }, "console_type": { "description": "Console type", - "enum": ["telnet", "vnc", "http", "https"] + "enum": ["telnet", "vnc", "http", "https", "none"] }, "console_resolution": { "description": "Console resolution for VNC", @@ -126,7 +126,7 @@ DOCKER_OBJECT_SCHEMA = { "description": "Console TCP port", "minimum": 1, "maximum": 65535, - "type": "integer" + "type": ["integer", "null"] }, "console_resolution": { "description": "Console resolution for VNC", @@ -135,7 +135,7 @@ DOCKER_OBJECT_SCHEMA = { }, "console_type": { "description": "Console type", - "enum": ["telnet", "vnc", "http", "https"] + "enum": ["telnet", "vnc", "http", "https", "none"] }, "console_http_port": { "description": "Internal port in the container for the HTTP server", diff --git a/gns3server/schemas/node.py b/gns3server/schemas/node.py index d39ba747..ddb9a17b 100644 --- a/gns3server/schemas/node.py +++ b/gns3server/schemas/node.py @@ -144,7 +144,7 @@ NODE_OBJECT_SCHEMA = { }, "console_type": { "description": "Console type", - "enum": ["vnc", "telnet", "http", "https", "spice", None] + "enum": ["vnc", "telnet", "http", "https", "spice", "none"] }, "properties": { "description": "Properties specific to an emulator", diff --git a/gns3server/schemas/qemu.py b/gns3server/schemas/qemu.py index f67f808a..1b533270 100644 --- a/gns3server/schemas/qemu.py +++ b/gns3server/schemas/qemu.py @@ -63,7 +63,7 @@ QEMU_CREATE_SCHEMA = { }, "console_type": { "description": "Console type", - "enum": ["telnet", "vnc", "spice"] + "enum": ["telnet", "vnc", "spice", "none"] }, "hda_disk_image": { "description": "QEMU hda disk image path", @@ -244,7 +244,7 @@ QEMU_UPDATE_SCHEMA = { }, "console_type": { "description": "Console type", - "enum": ["telnet", "vnc", "spice"] + "enum": ["telnet", "vnc", "spice", "none"] }, "linked_clone": { "description": "Whether the VM is a linked clone or not", @@ -537,11 +537,11 @@ QEMU_OBJECT_SCHEMA = { "description": "Console TCP port", "minimum": 1, "maximum": 65535, - "type": "integer" + "type": ["integer", "null"] }, "console_type": { "description": "Console type", - "enum": ["telnet", "vnc", "spice"] + "enum": ["telnet", "vnc", "spice", "none"] }, "initrd": { "description": "QEMU initrd path", diff --git a/gns3server/ubridge/ubridge_hypervisor.py b/gns3server/ubridge/ubridge_hypervisor.py index 6f70151e..b9860919 100644 --- a/gns3server/ubridge/ubridge_hypervisor.py +++ b/gns3server/ubridge/ubridge_hypervisor.py @@ -81,7 +81,7 @@ class UBridgeHypervisor: if not connection_success: raise UbridgeError("Couldn't connect to hypervisor on {}:{} :{}".format(host, self._port, last_exception)) else: - log.info("Connected to uBridge hypervisor after {:.4f} seconds".format(time.time() - begin)) + log.info("Connected to uBridge hypervisor on {}:{} after {:.4f} seconds".format(host, self._port, time.time() - begin)) try: version = yield from self.send("hypervisor version")