diff --git a/gns3server/compute/base_node.py b/gns3server/compute/base_node.py index 275f37fe..ab4e5073 100644 --- a/gns3server/compute/base_node.py +++ b/gns3server/compute/base_node.py @@ -50,14 +50,16 @@ class BaseNode: :param node_id: Node instance identifier :param project: Project instance :param manager: parent node manager - :param console: TCP console port - :param aux: TCP aux console port - :param allocate_aux: Boolean if true will allocate an aux console port + :param console: console TCP port + :param console_type: console type + :param aux: auxiliary console TCP port + :param aux_type: auxiliary console type :param linked_clone: The node base image is duplicate/overlay (Each node data are independent) :param wrap_console: The console is wrapped using AsyncioTelnetServer + :param wrap_aux: The auxiliary console is wrapped using AsyncioTelnetServer """ - def __init__(self, name, node_id, project, manager, console=None, console_type="telnet", aux=None, allocate_aux=False, linked_clone=True, wrap_console=False): + def __init__(self, name, node_id, project, manager, console=None, console_type="telnet", aux=None, aux_type="none", linked_clone=True, wrap_console=False, wrap_aux=False): self._name = name self._usage = "" @@ -68,20 +70,23 @@ class BaseNode: self._console = console self._aux = aux self._console_type = console_type + self._aux_type = aux_type self._temporary_directory = None self._hw_virtualization = False self._ubridge_hypervisor = None self._closed = False self._node_status = "stopped" self._command_line = "" - self._allocate_aux = allocate_aux self._wrap_console = wrap_console - self._wrapper_telnet_server = None + self._wrap_aux = wrap_aux + self._wrapper_telnet_servers = [] self._internal_console_port = None + self._internal_aux_port = None self._custom_adapters = [] self._ubridge_require_privileged_access = False if self._console is not None: + # use a previously allocated console port 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) @@ -90,22 +95,37 @@ class BaseNode: else: self._console = self._manager.port_manager.reserve_tcp_port(self._console, self._project) - # We need to allocate aux before giving a random console port if self._aux is not None: - self._aux = self._manager.port_manager.reserve_tcp_port(self._aux, self._project) + # use a previously allocated auxiliary console port + if aux_type == "vnc": + # VNC is a special case and the range must be 5900-6000 + self._aux = self._manager.port_manager.reserve_tcp_port(self._aux, self._project, port_range_start=5900, port_range_end=6000) + elif aux_type == "none": + self._aux = None + else: + self._aux = self._manager.port_manager.reserve_tcp_port(self._aux, self._project) if self._console is None: + # allocate a new console 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) elif console_type != "none": self._console = self._manager.port_manager.get_free_tcp_port(self._project) + if self._aux is None: + # allocate a new auxiliary console + if aux_type == "vnc": + # VNC is a special case and the range must be 5900-6000 + self._aux = self._manager.port_manager.get_free_tcp_port(self._project, port_range_start=5900, port_range_end=6000) + elif aux_type != "none": + self._aux = 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) - if self._aux is None and allocate_aux: - self._aux = self._manager.port_manager.get_free_tcp_port(self._project) + if self._wrap_aux: + self._internal_aux_port = self._manager.port_manager.get_free_tcp_port(self._project) log.debug("{module}: {name} [{id}] initialized. Console port {console}".format(module=self.manager.module_name, name=self.name, @@ -334,22 +354,19 @@ class BaseNode: if self._aux: self._manager.port_manager.release_tcp_port(self._aux, self._project) self._aux = None + if self._wrap_aux: + self._manager.port_manager.release_tcp_port(self._internal_aux_port, self._project) + self._internal_aux_port = None self._closed = True return True - async def start_wrap_console(self): - """ - Start a telnet proxy for the console allowing multiple telnet clients - to be connected at the same time - """ + async def _wrap_telnet_proxy(self, internal_port, external_port): - if not self._wrap_console or self._console_type != "telnet": - return remaining_trial = 60 while True: try: - (reader, writer) = await asyncio.open_connection(host="127.0.0.1", port=self._internal_console_port) + (reader, writer) = await asyncio.open_connection(host="127.0.0.1", port=internal_port) break except (OSError, ConnectionRefusedError) as e: if remaining_trial <= 0: @@ -359,16 +376,34 @@ class BaseNode: await AsyncioTelnetServer.write_client_intro(writer, echo=True) server = AsyncioTelnetServer(reader=reader, writer=writer, binary=True, echo=True) # warning: this will raise OSError exception if there is a problem... - self._wrapper_telnet_server = await asyncio.start_server(server.run, self._manager.port_manager.console_host, self.console) + telnet_server = await asyncio.start_server(server.run, self._manager.port_manager.console_host, external_port) + self._wrapper_telnet_servers.append(telnet_server) + + async def start_wrap_console(self): + """ + Start a Telnet proxy servers for the console and auxiliary console allowing multiple telnet clients + to be connected at the same time + """ + + if self._wrap_console and self._console_type == "telnet": + await self._wrap_telnet_proxy(self._internal_console_port, self.console) + log.info("New Telnet proxy server for console started (internal port = {}, external port = {})".format(self._internal_console_port, + self.console)) + + if self._wrap_aux and self._aux_type == "telnet": + await self._wrap_telnet_proxy(self._internal_aux_port, self.aux) + log.info("New Telnet proxy server for auxiliary console started (internal port = {}, external port = {})".format(self._internal_aux_port, + self.aux)) async def stop_wrap_console(self): """ - Stops the telnet proxy. + Stops the telnet proxy servers. """ - if self._wrapper_telnet_server: - self._wrapper_telnet_server.close() - await self._wrapper_telnet_server.wait_closed() + for telnet_proxy_server in self._wrapper_telnet_servers: + telnet_proxy_server.close() + await telnet_proxy_server.wait_closed() + self._wrapper_telnet_servers = [] async def reset_console(self): """ @@ -434,22 +469,6 @@ class BaseNode: return ws - @property - def allocate_aux(self): - """ - :returns: Boolean allocate or not an aux console - """ - - return self._allocate_aux - - @allocate_aux.setter - def allocate_aux(self, allocate_aux): - """ - :returns: Boolean allocate or not an aux console - """ - - self._allocate_aux = allocate_aux - @property def aux(self): """ @@ -468,18 +487,25 @@ class BaseNode: :params aux: Console port (integer) or None to free the port """ - if aux == self._aux: + if aux == self._aux or self._aux_type == "none": return + if self._aux_type == "vnc" and aux is not None and aux < 5900: + raise NodeError("VNC auxiliary console require a port superior or equal to 5900, current port is {}".format(aux)) + if self._aux: self._manager.port_manager.release_tcp_port(self._aux, self._project) self._aux = None if aux is not None: - self._aux = self._manager.port_manager.reserve_tcp_port(aux, self._project) - log.info("{module}: '{name}' [{id}]: aux port set to {port}".format(module=self.manager.module_name, - name=self.name, - id=self.id, - port=aux)) + if self.aux_type == "vnc": + self._aux = self._manager.port_manager.reserve_tcp_port(aux, self._project, port_range_start=5900, port_range_end=6000) + else: + self._aux = self._manager.port_manager.reserve_tcp_port(aux, self._project) + + log.info("{module}: '{name}' [{id}]: auxiliary console port set to {port}".format(module=self.manager.module_name, + name=self.name, + id=self.id, + port=aux)) @property def console(self): @@ -557,6 +583,44 @@ class BaseNode: console_type=console_type, console=self.console)) + @property + def aux_type(self): + """ + Returns the auxiliary console type for this node. + + :returns: aux type (string) + """ + + return self._aux_type + + @aux_type.setter + def aux_type(self, aux_type): + """ + Sets the auxiliary console type for this node. + + :param aux_type: console type (string) + """ + + if aux_type != self._aux_type: + # get a new port if the aux type change + if self._aux: + self._manager.port_manager.release_tcp_port(self._aux, self._project) + if aux_type == "none": + # no need to allocate a port when the auxiliary console type is none + self._aux = None + elif aux_type == "vnc": + # VNC is a special case and the range must be 5900-6000 + self._aux = self._manager.port_manager.get_free_tcp_port(self._project, 5900, 6000) + else: + self._aux = self._manager.port_manager.get_free_tcp_port(self._project) + + self._aux_type = aux_type + log.info("{module}: '{name}' [{id}]: console type set to {aux_type} (auxiliary console port is {aux})".format(module=self.manager.module_name, + name=self.name, + id=self.id, + aux_type=aux_type, + aux=self.aux)) + @property def ubridge(self): """ diff --git a/gns3server/compute/docker/docker_vm.py b/gns3server/compute/docker/docker_vm.py index 0704cccd..abf64b84 100644 --- a/gns3server/compute/docker/docker_vm.py +++ b/gns3server/compute/docker/docker_vm.py @@ -60,8 +60,9 @@ class DockerVM(BaseNode): :param manager: Manager instance :param image: Docker image :param console: TCP console port - :param console_type: Console type + :param console_type: console type :param aux: TCP aux console port + :param aux_type: auxiliary console type :param console_resolution: Resolution of the VNC display :param console_http_port: Port to redirect HTTP queries :param console_http_path: Url part with the path of the web interface @@ -70,10 +71,10 @@ class DockerVM(BaseNode): """ def __init__(self, name, node_id, project, manager, image, console=None, aux=None, start_command=None, - adapters=None, environment=None, console_type="telnet", console_resolution="1024x768", + adapters=None, environment=None, console_type="telnet", aux_type="none", console_resolution="1024x768", console_http_port=80, console_http_path="/", extra_hosts=None, extra_volumes=[], memory=0, cpus=0): - super().__init__(name, node_id, project, manager, console=console, aux=aux, allocate_aux=True, console_type=console_type) + super().__init__(name, node_id, project, manager, console=console, console_type=console_type, aux=aux, aux_type=aux_type) # force the latest image if no version is specified if ":" not in image: @@ -128,6 +129,7 @@ class DockerVM(BaseNode): "console_http_port": self.console_http_port, "console_http_path": self.console_http_path, "aux": self.aux, + "aux_type": self.aux_type, "start_command": self.start_command, "status": self.status, "environment": self.environment, @@ -517,7 +519,7 @@ class DockerVM(BaseNode): elif self.console_type == "http" or self.console_type == "https": await self._start_http() - if self.allocate_aux: + if self.aux_type != "none": await self._start_aux() self._permissions_fixed = False diff --git a/gns3server/compute/dynamips/nodes/c1700.py b/gns3server/compute/dynamips/nodes/c1700.py index cb4b8537..cdc0f343 100644 --- a/gns3server/compute/dynamips/nodes/c1700.py +++ b/gns3server/compute/dynamips/nodes/c1700.py @@ -40,15 +40,17 @@ class C1700(Router): :param manager: Parent VM Manager :param dynamips_id: ID to use with Dynamips :param console: console port + :param console_type: console type :param aux: auxiliary console port + :param aux_type: auxiliary console type :param chassis: chassis for this router: 1720, 1721, 1750, 1751 or 1760 (default = 1720). 1710 is not supported. """ - def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, chassis="1720"): + def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis="1720"): - super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, platform="c1700") + super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c1700") # Set default values for this platform (must be the same as Dynamips) self._ram = 64 diff --git a/gns3server/compute/dynamips/nodes/c2600.py b/gns3server/compute/dynamips/nodes/c2600.py index b065607b..e2c3ea13 100644 --- a/gns3server/compute/dynamips/nodes/c2600.py +++ b/gns3server/compute/dynamips/nodes/c2600.py @@ -42,7 +42,9 @@ class C2600(Router): :param manager: Parent VM Manager :param dynamips_id: ID to use with Dynamips :param console: console port + :param console_type: console type :param aux: auxiliary console port + :param aux_type: auxiliary console type :param chassis: chassis for this router: 2610, 2611, 2620, 2621, 2610XM, 2611XM 2620XM, 2621XM, 2650XM or 2651XM (default = 2610). @@ -61,9 +63,9 @@ class C2600(Router): "2650XM": C2600_MB_1FE, "2651XM": C2600_MB_2FE} - def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, chassis="2610"): + def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis="2610"): - super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, platform="c2600") + super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c2600") # Set default values for this platform (must be the same as Dynamips) self._ram = 64 diff --git a/gns3server/compute/dynamips/nodes/c2691.py b/gns3server/compute/dynamips/nodes/c2691.py index 8441881f..c946b391 100644 --- a/gns3server/compute/dynamips/nodes/c2691.py +++ b/gns3server/compute/dynamips/nodes/c2691.py @@ -40,12 +40,14 @@ class C2691(Router): :param manager: Parent VM Manager :param dynamips_id: ID to use with Dynamips :param console: console port + :param console_type: console type :param aux: auxiliary console port + :param aux_type: auxiliary console type """ - def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, chassis=None): + def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis=None): - super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, platform="c2691") + super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c2691") # Set default values for this platform (must be the same as Dynamips) self._ram = 128 diff --git a/gns3server/compute/dynamips/nodes/c3600.py b/gns3server/compute/dynamips/nodes/c3600.py index 984a5621..a5341f6e 100644 --- a/gns3server/compute/dynamips/nodes/c3600.py +++ b/gns3server/compute/dynamips/nodes/c3600.py @@ -39,14 +39,16 @@ class C3600(Router): :param manager: Parent VM Manager :param dynamips_id: ID to use with Dynamips :param console: console port + :param console_type: console type :param aux: auxiliary console port + :param aux_type: auxiliary console type :param chassis: chassis for this router: 3620, 3640 or 3660 (default = 3640). """ - def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, chassis="3640"): + def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis="3640"): - super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, platform="c3600") + super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3600") # Set default values for this platform (must be the same as Dynamips) self._ram = 128 diff --git a/gns3server/compute/dynamips/nodes/c3725.py b/gns3server/compute/dynamips/nodes/c3725.py index be194cf5..5ba52e47 100644 --- a/gns3server/compute/dynamips/nodes/c3725.py +++ b/gns3server/compute/dynamips/nodes/c3725.py @@ -40,12 +40,14 @@ class C3725(Router): :param manager: Parent VM Manager :param dynamips_id: ID to use with Dynamips :param console: console port + :param console_type: console type :param aux: auxiliary console port + :param aux_type: auxiliary console type """ - def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, chassis=None): + def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis=None): - super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, platform="c3725") + super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3725") # Set default values for this platform (must be the same as Dynamips) self._ram = 128 diff --git a/gns3server/compute/dynamips/nodes/c3745.py b/gns3server/compute/dynamips/nodes/c3745.py index 9087a98f..cdbc6b49 100644 --- a/gns3server/compute/dynamips/nodes/c3745.py +++ b/gns3server/compute/dynamips/nodes/c3745.py @@ -40,12 +40,14 @@ class C3745(Router): :param manager: Parent VM Manager :param dynamips_id: ID to use with Dynamips :param console: console port + :param console_type: console type :param aux: auxiliary console port + :param aux_type: auxiliary console type """ - def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, chassis=None): + def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", chassis=None): - super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, platform="c3745") + super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c3745") # Set default values for this platform (must be the same as Dynamips) self._ram = 128 diff --git a/gns3server/compute/dynamips/nodes/c7200.py b/gns3server/compute/dynamips/nodes/c7200.py index 155bc385..6ebf9abb 100644 --- a/gns3server/compute/dynamips/nodes/c7200.py +++ b/gns3server/compute/dynamips/nodes/c7200.py @@ -42,13 +42,15 @@ class C7200(Router): :param manager: Parent VM Manager :param dynamips_id: ID to use with Dynamips :param console: console port + :param console_type: console type :param aux: auxiliary console port + :param aux_type: auxiliary console type :param npe: Default NPE """ - def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, npe="npe-400", chassis=None): + def __init__(self, name, node_id, project, manager, dynamips_id, console=None, console_type="telnet", aux=None, aux_type="none", npe="npe-400", chassis=None): - super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, platform="c7200") + super().__init__(name, node_id, project, manager, dynamips_id, console, console_type, aux, aux_type, platform="c7200") # Set default values for this platform (must be the same as Dynamips) self._ram = 256 diff --git a/gns3server/compute/dynamips/nodes/router.py b/gns3server/compute/dynamips/nodes/router.py index 253ee474..b5553318 100644 --- a/gns3server/compute/dynamips/nodes/router.py +++ b/gns3server/compute/dynamips/nodes/router.py @@ -52,7 +52,9 @@ class Router(BaseNode): :param manager: Parent VM Manager :param dynamips_id: ID to use with Dynamips :param console: console port + :param console_type: console type :param aux: auxiliary console port + :param aux_type: auxiliary console type :param platform: Platform of this router """ @@ -61,9 +63,9 @@ class Router(BaseNode): 2: "running", 3: "suspended"} - def __init__(self, name, node_id, project, manager, dynamips_id=None, console=None, console_type="telnet", aux=None, platform="c7200", hypervisor=None, ghost_flag=False): + def __init__(self, name, node_id, project, manager, dynamips_id=None, console=None, console_type="telnet", aux=None, aux_type="none", platform="c7200", hypervisor=None, ghost_flag=False): - super().__init__(name, node_id, project, manager, console=console, console_type=console_type, aux=aux, allocate_aux=True) + super().__init__(name, node_id, project, manager, console=console, console_type=console_type, aux=aux, aux_type=aux_type) self._working_directory = os.path.join(self.project.module_working_directory(self.manager.module_name.lower()), self.id) try: @@ -166,6 +168,7 @@ class Router(BaseNode): "console": self.console, "console_type": self.console_type, "aux": self.aux, + "aux_type": self.aux_type, "mac_addr": self._mac_addr, "system_id": self._system_id} @@ -223,15 +226,14 @@ class Router(BaseNode): platform=self._platform, id=self._id)) - if self._console: + if self._console is not None: await self._hypervisor.send('vm set_con_tcp_port "{name}" {console}'.format(name=self._name, console=self._console)) if self.aux is not None: await self._hypervisor.send('vm set_aux_tcp_port "{name}" {aux}'.format(name=self._name, aux=self.aux)) # get the default base MAC address - mac_addr = await self._hypervisor.send('{platform} get_mac_addr "{name}"'.format(platform=self._platform, - name=self._name)) + mac_addr = await self._hypervisor.send('{platform} get_mac_addr "{name}"'.format(platform=self._platform, name=self._name)) self._mac_addr = mac_addr[0] self._hypervisor.devices.append(self) diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 76db4bd8..287ee188 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -67,9 +67,9 @@ class QemuVM(BaseNode): :param platform: Platform to emulate """ - def __init__(self, name, node_id, project, manager, linked_clone=True, qemu_path=None, console=None, console_type="telnet", platform=None): + def __init__(self, name, node_id, project, manager, linked_clone=True, qemu_path=None, console=None, console_type="telnet", aux=None, aux_type="none", platform=None): - super().__init__(name, node_id, project, manager, console=console, console_type=console_type, linked_clone=linked_clone, wrap_console=True) + super().__init__(name, node_id, project, manager, console=console, console_type=console_type, linked_clone=linked_clone, aux=aux, aux_type=aux_type, wrap_console=True, wrap_aux=True) server_config = manager.config.get_section_config("Server") self._host = server_config.get("host", "127.0.0.1") self._monitor_host = server_config.get("monitor_host", "127.0.0.1") @@ -1543,24 +1543,24 @@ class QemuVM(BaseNode): super(QemuVM, QemuVM).console_type.__set__(self, new_console_type) - def _serial_options(self): + def _serial_options(self, internal_console_port, external_console_port): - if self._console: - return ["-serial", "telnet:127.0.0.1:{},server,nowait".format(self._internal_console_port)] + if external_console_port: + return ["-serial", "telnet:127.0.0.1:{},server,nowait".format(internal_console_port)] else: return [] - def _vnc_options(self): + def _vnc_options(self, port): - if self._console: - vnc_port = self._console - 5900 # subtract by 5900 to get the display number + if port: + vnc_port = port - 5900 # subtract by 5900 to get the display number return ["-vnc", "{}:{}".format(self._manager.port_manager.console_host, vnc_port)] else: return [] - def _spice_options(self): + def _spice_options(self, port): - if self._console: + if port: console_host = self._manager.port_manager.console_host if console_host == "0.0.0.0": if socket.has_ipv6: @@ -1571,15 +1571,15 @@ class QemuVM(BaseNode): else: raise QemuError("IPv6 must be enabled in order to use the SPICE console") return ["-spice", - "addr={},port={},disable-ticketing".format(console_host, self._console), + "addr={},port={},disable-ticketing".format(console_host, port), "-vga", "qxl"] else: return [] - def _spice_with_agent_options(self): + def _spice_with_agent_options(self, port): - spice_options = self._spice_options() - if self._console: + spice_options = self._spice_options(port) + if spice_options: # agent options (mouse/screen) agent_options = ["-device", "virtio-serial", "-chardev", "spicevmc,id=vdagent,debug=0,name=vdagent", @@ -1591,6 +1591,36 @@ class QemuVM(BaseNode): spice_options.extend(folder_sharing_options) return spice_options + def _console_options(self): + + if self._console_type == "telnet" and self._wrap_console: + return self._serial_options(self._internal_console_port, self.console) + elif self._console_type == "vnc": + return self._vnc_options(self.console) + elif self._console_type == "spice": + return self._spice_options(self.console) + elif self._console_type == "spice+agent": + return self._spice_with_agent_options(self.console) + elif self._console_type != "none": + raise QemuError("Console type {} is unknown".format(self._console_type)) + + def _aux_options(self): + + if self._aux_type != "none" and self._aux_type == self._console_type: + raise QemuError("Auxiliary console type {} cannot be the same as console type".format(self._aux_type)) + + if self._aux_type == "telnet" and self._wrap_aux: + return self._serial_options(self._internal_aux_port, self.aux) + elif self._aux_type == "vnc": + return self._vnc_options(self.aux) + elif self._aux_type == "spice": + return self._spice_options(self.aux) + elif self._aux_type == "spice+agent": + return self._spice_with_agent_options(self.aux) + elif self._aux_type != "none": + raise QemuError("Auxiliary console type {} is unknown".format(self._aux_type)) + return [] + def _monitor_options(self): if self._monitor: @@ -2057,16 +2087,8 @@ class QemuVM(BaseNode): command.extend(self._linux_boot_options()) if "-uuid" not in additional_options: command.extend(["-uuid", self._id]) - if self._console_type == "telnet": - command.extend(self._serial_options()) - elif self._console_type == "vnc": - command.extend(self._vnc_options()) - elif self._console_type == "spice": - command.extend(self._spice_options()) - elif self._console_type == "spice+agent": - command.extend(self._spice_with_agent_options()) - elif self._console_type != "none": - raise QemuError("Console type {} is unknown".format(self._console_type)) + command.extend(self._console_options()) + command.extend(self._aux_options()) command.extend(self._monitor_options()) command.extend((await self._network_options())) if self.on_close != "save_vm_state": diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index aa4479d5..4f4a718e 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -66,6 +66,8 @@ class Node: self.name = name self._console = None self._console_type = None + self._aux = None + self._aux_type = None self._properties = None self._command_line = None self._node_directory = None @@ -159,6 +161,14 @@ class Node: def console(self, val): self._console = val + @property + def aux(self): + return self._aux + + @aux.setter + def aux(self, val): + self._aux = val + @property def console_type(self): return self._console_type @@ -167,6 +177,14 @@ class Node: def console_type(self, val): self._console_type = val + @property + def aux_type(self): + return self._aux_type + + @aux_type.setter + def aux_type(self, val): + self._aux_type = val + @property def console_auto_start(self): return self._console_auto_start @@ -426,6 +444,8 @@ class Node: for key, value in response.items(): if key == "console": self._console = value + elif key == "aux": + self._aux = value elif key == "node_directory": self._node_directory = value elif key == "command_line": @@ -434,6 +454,8 @@ class Node: self._status = value elif key == "console_type": self._console_type = value + elif key == "aux_type": + self._aux_type = value elif key == "name": self.name = value elif key in ["node_id", "project_id", "console_host", @@ -476,6 +498,12 @@ class Node: if self._console_type and self._node_type not in ("cloud", "nat", "ethernet_hub", "frame_relay_switch", "atm_switch"): # console_type is not supported by all builtin nodes excepting Ethernet switch data["console_type"] = self._console_type + if self._aux: + # aux is optional for builtin nodes + data["aux"] = self._aux + if self._aux_type and self._node_type not in ("cloud", "nat", "ethernet_switch", "ethernet_hub", "frame_relay_switch", "atm_switch"): + # aux_type is not supported by all builtin nodes + data["aux_type"] = self._aux_type if self.custom_adapters: data["custom_adapters"] = self.custom_adapters @@ -699,6 +727,8 @@ class Node: "console": self._console, "console_type": self._console_type, "console_auto_start": self._console_auto_start, + "aux": self._aux, + "aux_type": self._aux_type, "properties": self._properties, "label": self._label, "x": self._x, @@ -724,6 +754,8 @@ class Node: "console": self._console, "console_host": str(self._compute.console_host), "console_type": self._console_type, + "aux": self._aux, + "aux_type": self._aux_type, "console_auto_start": self._console_auto_start, "command_line": self._command_line, "properties": self._properties, diff --git a/gns3server/handlers/api/compute/docker_handler.py b/gns3server/handlers/api/compute/docker_handler.py index a56922cd..cbb7be10 100644 --- a/gns3server/handlers/api/compute/docker_handler.py +++ b/gns3server/handlers/api/compute/docker_handler.py @@ -61,6 +61,7 @@ class DockerHandler: console_http_port=request.json.get("console_http_port", 80), console_http_path=request.json.get("console_http_path", "/"), aux=request.json.get("aux"), + aux_type=request.json.pop("aux_type", "none"), extra_hosts=request.json.get("extra_hosts"), extra_volumes=request.json.get("extra_volumes"), memory=request.json.get("memory", 0), @@ -317,7 +318,7 @@ class DockerHandler: container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"]) props = [ - "name", "console", "aux", "console_type", "console_resolution", + "name", "console", "console_type", "aux", "aux_type", "console_resolution", "console_http_port", "console_http_path", "start_command", "environment", "adapters", "extra_hosts", "extra_volumes", "memory", "cpus" diff --git a/gns3server/handlers/api/compute/dynamips_vm_handler.py b/gns3server/handlers/api/compute/dynamips_vm_handler.py index f89f8a0d..b7eca221 100644 --- a/gns3server/handlers/api/compute/dynamips_vm_handler.py +++ b/gns3server/handlers/api/compute/dynamips_vm_handler.py @@ -77,6 +77,7 @@ class DynamipsVMHandler: console=request.json.get("console"), console_type=request.json.get("console_type", "telnet"), aux=request.json.get("aux"), + aux_type=request.json.pop("aux_type", "none"), chassis=request.json.pop("chassis", default_chassis), node_type="dynamips") await dynamips_manager.update_vm_settings(vm, request.json) diff --git a/gns3server/handlers/api/compute/qemu_handler.py b/gns3server/handlers/api/compute/qemu_handler.py index eff1b3e6..59fdae34 100644 --- a/gns3server/handlers/api/compute/qemu_handler.py +++ b/gns3server/handlers/api/compute/qemu_handler.py @@ -67,13 +67,15 @@ class QEMUHandler: qemu = Qemu.instance() vm = await qemu.create_node(request.json.pop("name"), - request.match_info["project_id"], - request.json.pop("node_id", None), - linked_clone=request.json.get("linked_clone", True), - qemu_path=request.json.pop("qemu_path", None), - console=request.json.pop("console", None), - console_type=request.json.pop("console_type", "telnet"), - platform=request.json.pop("platform", None)) + request.match_info["project_id"], + request.json.pop("node_id", None), + linked_clone=request.json.get("linked_clone", True), + qemu_path=request.json.pop("qemu_path", None), + console=request.json.pop("console", None), + console_type=request.json.pop("console_type", "telnet"), + aux=request.json.get("aux"), + aux_type=request.json.pop("aux_type", "none"), + platform=request.json.pop("platform", None)) for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: diff --git a/gns3server/schemas/docker.py b/gns3server/schemas/docker.py index db56a61a..0fba7724 100644 --- a/gns3server/schemas/docker.py +++ b/gns3server/schemas/docker.py @@ -65,6 +65,10 @@ DOCKER_CREATE_SCHEMA = { "maximum": 65535, "type": ["integer", "null"] }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "none"] + }, "usage": { "description": "How to use the Docker container", "type": "string", @@ -145,7 +149,7 @@ DOCKER_OBJECT_SCHEMA = { "description": "Auxiliary TCP port", "minimum": 1, "maximum": 65535, - "type": "integer" + "type": ["integer", "null"] }, "console": { "description": "Console TCP port", @@ -162,6 +166,10 @@ DOCKER_OBJECT_SCHEMA = { "description": "Console type", "enum": ["telnet", "vnc", "http", "https", "none"] }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "none"] + }, "console_http_port": { "description": "Internal port in the container for the HTTP server", "type": "integer", diff --git a/gns3server/schemas/docker_template.py b/gns3server/schemas/docker_template.py index 40735cb2..5f25d17f 100644 --- a/gns3server/schemas/docker_template.py +++ b/gns3server/schemas/docker_template.py @@ -48,6 +48,11 @@ DOCKER_TEMPLATE_PROPERTIES = { "enum": ["telnet", "vnc", "http", "https", "none"], "default": "telnet" }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "none"], + "default": "none" + }, "console_auto_start": { "description": "Automatically start the console when the node has started", "type": "boolean", diff --git a/gns3server/schemas/dynamips_template.py b/gns3server/schemas/dynamips_template.py index 244bca4e..19f8dc19 100644 --- a/gns3server/schemas/dynamips_template.py +++ b/gns3server/schemas/dynamips_template.py @@ -115,6 +115,11 @@ DYNAMIPS_TEMPLATE_PROPERTIES = { "description": "Automatically start the console when the node has started", "type": "boolean", "default": False + }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "none"], + "default": "none" } } diff --git a/gns3server/schemas/dynamips_vm.py b/gns3server/schemas/dynamips_vm.py index 1fc939a6..2e0b32f9 100644 --- a/gns3server/schemas/dynamips_vm.py +++ b/gns3server/schemas/dynamips_vm.py @@ -178,6 +178,10 @@ VM_CREATE_SCHEMA = { "minimum": 1, "maximum": 65535 }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "none"] + }, "mac_addr": { "description": "Base MAC address", "type": ["null", "string"], @@ -400,6 +404,10 @@ VM_UPDATE_SCHEMA = { "minimum": 1, "maximum": 65535 }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "none"] + }, "mac_addr": { "description": "Base MAC address", "type": ["null", "string"], @@ -644,6 +652,10 @@ VM_OBJECT_SCHEMA = { "minimum": 1, "maximum": 65535 }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "none"] + }, "mac_addr": { "description": "Base MAC address", "type": ["null", "string"] diff --git a/gns3server/schemas/node.py b/gns3server/schemas/node.py index 5d3cc11a..d7d92583 100644 --- a/gns3server/schemas/node.py +++ b/gns3server/schemas/node.py @@ -159,6 +159,16 @@ NODE_OBJECT_SCHEMA = { "description": "Automatically start the console when the node has started", "type": "boolean" }, + "aux": { + "description": "Auxiliary console TCP port", + "minimum": 1, + "maximum": 65535, + "type": ["integer", "null"] + }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["vnc", "telnet", "http", "https", "spice", "spice+agent", "none", None] + }, "properties": { "description": "Properties specific to an emulator", "type": "object" diff --git a/gns3server/schemas/qemu.py b/gns3server/schemas/qemu.py index b4a9bcf3..a029e40c 100644 --- a/gns3server/schemas/qemu.py +++ b/gns3server/schemas/qemu.py @@ -67,6 +67,16 @@ QEMU_CREATE_SCHEMA = { "description": "Console type", "enum": ["telnet", "vnc", "spice", "spice+agent", "none"] }, + "aux": { + "description": "Auxiliary TCP port", + "minimum": 1, + "maximum": 65535, + "type": ["integer", "null"] + }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "vnc", "spice", "spice+agent", "none"] + }, "hda_disk_image": { "description": "QEMU hda disk image path", "type": "string", @@ -259,6 +269,16 @@ QEMU_UPDATE_SCHEMA = { "description": "Console type", "enum": ["telnet", "vnc", "spice", "spice+agent", "none"] }, + "aux": { + "description": "Auxiliary TCP port", + "minimum": 1, + "maximum": 65535, + "type": ["integer", "null"] + }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "vnc", "spice", "spice+agent", "none"] + }, "linked_clone": { "description": "Whether the VM is a linked clone or not", "type": "boolean" @@ -573,6 +593,16 @@ QEMU_OBJECT_SCHEMA = { "description": "Console type", "enum": ["telnet", "vnc", "spice","spice+agent", "none"] }, + "aux": { + "description": "Auxiliary TCP port", + "minimum": 1, + "maximum": 65535, + "type": ["integer", "null"] + }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "vnc", "spice", "spice+agent", "none"] + }, "initrd": { "description": "QEMU initrd path", "type": "string", @@ -641,6 +671,7 @@ QEMU_OBJECT_SCHEMA = { "qemu_path", "platform", "console_type", + "aux_type", "hda_disk_image", "hdb_disk_image", "hdc_disk_image", @@ -665,6 +696,7 @@ QEMU_OBJECT_SCHEMA = { "adapter_type", "mac_address", "console", + "aux", "initrd", "kernel_image", "initrd_md5sum", diff --git a/gns3server/schemas/qemu_template.py b/gns3server/schemas/qemu_template.py index ae3a5ffe..eb3c2235 100644 --- a/gns3server/schemas/qemu_template.py +++ b/gns3server/schemas/qemu_template.py @@ -105,6 +105,11 @@ QEMU_TEMPLATE_PROPERTIES = { "type": "boolean", "default": False }, + "aux_type": { + "description": "Auxiliary console type", + "enum": ["telnet", "vnc", "spice", "spice+agent", "none"], + "default": "none" + }, "boot_priority": { "description": "QEMU boot priority", "enum": ["c", "d", "n", "cn", "cd", "dn", "dc", "nc", "nd"], diff --git a/tests/compute/docker/test_docker_vm.py b/tests/compute/docker/test_docker_vm.py index 1f639fb3..d01abceb 100644 --- a/tests/compute/docker/test_docker_vm.py +++ b/tests/compute/docker/test_docker_vm.py @@ -44,9 +44,8 @@ async def manager(loop, port_manager): @pytest.fixture(scope="function") async def vm(loop, compute_project, manager): - vm = DockerVM("test", str(uuid.uuid4()), compute_project, manager, "ubuntu:latest") + vm = DockerVM("test", str(uuid.uuid4()), compute_project, manager, "ubuntu:latest", aux_type="none") vm._cid = "e90e34656842" - vm.allocate_aux = False return vm @@ -61,6 +60,7 @@ def test_json(vm, compute_project): 'adapters': 1, 'console': vm.console, 'console_type': 'telnet', + 'aux_type': 'none', 'console_resolution': '1024x768', 'console_http_port': 80, 'console_http_path': '/', @@ -885,7 +885,7 @@ async def test_start(vm, manager, free_console_port): assert vm.status != "started" vm.adapters = 1 - vm.allocate_aux = True + vm.aux_type = "telnet" vm._start_aux = AsyncioMagicMock() vm._get_container_state = AsyncioMagicMock(return_value="stopped") diff --git a/tests/compute/test_base_node.py b/tests/compute/test_base_node.py index 9052a818..7e8924df 100644 --- a/tests/compute/test_base_node.py +++ b/tests/compute/test_base_node.py @@ -103,7 +103,7 @@ def test_aux(compute_project, manager, port_manager): aux = port_manager.get_free_tcp_port(compute_project) port_manager.release_tcp_port(aux, compute_project) - node = DockerVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, "ubuntu", aux=aux) + node = DockerVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, "ubuntu", aux=aux, aux_type="telnet") assert node.aux == aux node.aux = None assert node.aux is None @@ -115,12 +115,13 @@ def test_allocate_aux(compute_project, manager): assert node.aux is None # Docker has an aux port by default - node = DockerVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, "ubuntu") + node = DockerVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, "ubuntu", aux_type="telnet") assert node.aux is not None -def test_change_aux_port(node, port_manager): +def test_change_aux_port(compute_project, manager, port_manager): + node = DockerVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, "ubuntu", aux_type="telnet") port1 = port_manager.get_free_tcp_port(node.project) port2 = port_manager.get_free_tcp_port(node.project) port_manager.release_tcp_port(port1, node.project) diff --git a/tests/controller/test_node.py b/tests/controller/test_node.py index 11749289..1269fa8e 100644 --- a/tests/controller/test_node.py +++ b/tests/controller/test_node.py @@ -121,6 +121,8 @@ def test_json(node, compute): "console": node.console, "console_type": node.console_type, "console_host": str(compute.console_host), + "aux": node.aux, + "aux_type": node.aux_type, "command_line": None, "node_directory": None, "properties": node.properties, @@ -158,6 +160,8 @@ def test_json(node, compute): "name": "demo", "console": node.console, "console_type": node.console_type, + "aux": node.aux, + "aux_type": node.aux_type, "properties": node.properties, "x": node.x, "y": node.y,