From f20ee06181bf96b4c8605afbe3186515b3aa2c28 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 24 Jun 2015 19:09:17 -0600 Subject: [PATCH] VNC console support for Qemu VMs. --- gns3server/modules/qemu/qemu_vm.py | 45 ++++++++++++++++++++++++++++-- gns3server/schemas/qemu.py | 14 +++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index 9aa3a6b0..1fa39350 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -91,6 +91,7 @@ class QemuVM(BaseVM): self._hdd_disk_image = "" self._mac_address = "" self._options = "" + self._console_type = "telnet" self._ram = 256 self._ethernet_adapters = [] self._adapter_type = "e1000" @@ -513,6 +514,33 @@ class QemuVM(BaseVM): self._options = options.strip() + @property + def console_type(self): + """ + Returns the console type for this QEMU VM. + + :returns: console type (string) + """ + + return self._console_type + + @console_type.setter + def console_type(self, console_type): + """ + Sets the console type for this QEMU VM. + + :param console_type: console type (string) + """ + + log.info('QEMU VM "{name}" [{id}] has set the console type to {console_type}'.format(name=self._name, + id=self._id, + console_type=console_type)) + + if self.is_running() and console_type != self._console_type: + raise QemuError("Sorry, changing the console type on a running Qemu VM is not supported.") + + self._console_type = console_type + @property def initrd(self): """ @@ -1003,6 +1031,14 @@ class QemuVM(BaseVM): else: return [] + def _vnc_options(self): + + if self._console: + vnc_port = self._console - 5900 + return ["-vnc", "{}:{}".format(self._manager.port_manager.console_host, vnc_port)] + else: + return [] + def _monitor_options(self): if self._monitor: @@ -1199,14 +1235,19 @@ class QemuVM(BaseVM): disk_options = yield from self._disk_options() command.extend(disk_options) command.extend(self._linux_boot_options()) - command.extend(self._serial_options()) + if self._console_type == "telnet": + command.extend(self._serial_options()) + elif self._console_type == "vnc": + command.extend(self._vnc_options()) + else: + raise QemuError("Console type {} is unknown".format(self._console_type)) command.extend(self._monitor_options()) additional_options = self._options.strip() if additional_options: try: command.extend(shlex.split(additional_options)) except ValueError as e: - QemuError("Invalid additional options: {} error {}".format(additional_options, e)) + raise QemuError("Invalid additional options: {} error {}".format(additional_options, e)) command.extend(self._network_options()) command.extend(self._graphic()) return command diff --git a/gns3server/schemas/qemu.py b/gns3server/schemas/qemu.py index 90da25e9..ccf30436 100644 --- a/gns3server/schemas/qemu.py +++ b/gns3server/schemas/qemu.py @@ -53,6 +53,10 @@ QEMU_CREATE_SCHEMA = { "maximum": 65535, "type": ["integer", "null"] }, + "console_type": { + "description": "console type", + "enum": ["telnet", "vnc"] + }, "hda_disk_image": { "description": "QEMU hda disk image path", "type": "string", @@ -188,6 +192,10 @@ QEMU_UPDATE_SCHEMA = { "maximum": 65535, "type": ["integer", "null"] }, + "console_type": { + "description": "console type", + "enum": ["telnet", "vnc"] + }, "hda_disk_image": { "description": "QEMU hda disk image path", "type": "string", @@ -385,6 +393,10 @@ QEMU_OBJECT_SCHEMA = { "maximum": 65535, "type": "integer" }, + "console_type": { + "description": "console type", + "enum": ["telnet", "vnc"] + }, "initrd": { "description": "QEMU initrd path", "type": "string", @@ -438,7 +450,7 @@ QEMU_OBJECT_SCHEMA = { }, }, "additionalProperties": False, - "required": ["vm_id", "project_id", "name", "qemu_path", "platform", "hda_disk_image", "hdb_disk_image", + "required": ["vm_id", "project_id", "name", "qemu_path", "platform", "console_type", "hda_disk_image", "hdb_disk_image", "hdc_disk_image", "hdd_disk_image", "hda_disk_image_md5sum", "hdb_disk_image_md5sum", "hdc_disk_image_md5sum", "hdd_disk_image_md5sum", "ram", "adapters", "adapter_type", "mac_address", "console", "initrd", "kernel_image", "initrd_md5sum", "kernel_image_md5sum", "kernel_command_line",