From a56b816c1af2b0edaa5d6f64f86ea7665be8abde Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 14 Aug 2020 17:57:24 +0930 Subject: [PATCH] Add explicit option to automatically create or not the config disk. Off by default. (cherry picked from commit 56aba96a5fb57f502b283a0bc543da415bb3943a) --- gns3server/compute/qemu/qemu_vm.py | 33 +++++++++++++++++++++++++---- gns3server/schemas/qemu.py | 13 ++++++++++++ gns3server/schemas/qemu_template.py | 5 +++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 2870ad29..3e7b0280 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -122,6 +122,7 @@ class QemuVM(BaseNode): self._kernel_command_line = "" self._legacy_networking = False self._replicate_network_connection_state = True + self._create_config_disk = False self._on_close = "power_off" self._cpu_throttling = 0 # means no CPU throttling self._process_priority = "low" @@ -139,9 +140,8 @@ class QemuVM(BaseNode): else: try: self.config_disk_image = self.manager.get_abs_image_path(self.config_disk_name) - except (NodeError, ImageMissingError) as e: - log.warning("Config disk: image '{}' missing" - .format(self.config_disk_name)) + except (NodeError, ImageMissingError): + log.warning("Config disk: image '{}' missing".format(self.config_disk_name)) self.config_disk_name = "" log.info('QEMU VM "{name}" [{id}] has been created'.format(name=self._name, id=self._id)) @@ -671,6 +671,30 @@ class QemuVM(BaseNode): log.info('QEMU VM "{name}" [{id}] has disabled network connection state replication'.format(name=self._name, id=self._id)) self._replicate_network_connection_state = replicate_network_connection_state + @property + def create_config_disk(self): + """ + Returns whether a config disk is automatically created on HDD disk interface (secondary slave) + + :returns: boolean + """ + + return self._create_config_disk + + @create_config_disk.setter + def create_config_disk(self, create_config_disk): + """ + Sets whether a config disk is automatically created on HDD disk interface (secondary slave) + + :param replicate_network_connection_state: boolean + """ + + if create_config_disk: + log.info('QEMU VM "{name}" [{id}] has enabled the config disk creation feature'.format(name=self._name, id=self._id)) + else: + log.info('QEMU VM "{name}" [{id}] has disabled the config disk creation feature'.format(name=self._name, id=self._id)) + self._create_config_disk = create_config_disk + @property def on_close(self): """ @@ -1818,7 +1842,7 @@ class QemuVM(BaseNode): # config disk disk_image = getattr(self, "config_disk_image") - if disk_image: + if disk_image and self._create_config_disk: if getattr(self, "_hdd_disk_image"): log.warning("Config disk: blocked by disk image 'hdd'") else: @@ -1837,6 +1861,7 @@ class QemuVM(BaseNode): log.warning("Could not create '{}' disk image: {}".format(disk_name, e)) if disk_exists: options.extend(self._disk_interface_options(disk, 3, interface, "raw")) + self.hdd_disk_image = disk return options diff --git a/gns3server/schemas/qemu.py b/gns3server/schemas/qemu.py index 567e5c3f..3ae444d4 100644 --- a/gns3server/schemas/qemu.py +++ b/gns3server/schemas/qemu.py @@ -190,6 +190,10 @@ QEMU_CREATE_SCHEMA = { "description": "Replicate the network connection state for links in Qemu", "type": ["boolean", "null"], }, + "create_config_disk": { + "description": "Automatically create a config disk on HDD disk interface (secondary slave)", + "type": ["boolean", "null"], + }, "on_close": { "description": "Action to execute on the VM is closed", "enum": ["power_off", "shutdown_signal", "save_vm_state"], @@ -380,6 +384,10 @@ QEMU_UPDATE_SCHEMA = { "description": "Replicate the network connection state for links in Qemu", "type": ["boolean", "null"], }, + "create_config_disk": { + "description": "Automatically create a config disk on HDD disk interface (secondary slave)", + "type": ["boolean", "null"], + }, "on_close": { "description": "Action to execute on the VM is closed", "enum": ["power_off", "shutdown_signal", "save_vm_state"], @@ -583,6 +591,10 @@ QEMU_OBJECT_SCHEMA = { "description": "Replicate the network connection state for links in Qemu", "type": "boolean", }, + "create_config_disk": { + "description": "Automatically create a config disk on HDD disk interface (secondary slave)", + "type": ["boolean", "null"], + }, "on_close": { "description": "Action to execute on the VM is closed", "enum": ["power_off", "shutdown_signal", "save_vm_state"], @@ -653,6 +665,7 @@ QEMU_OBJECT_SCHEMA = { "kernel_command_line", "legacy_networking", "replicate_network_connection_state", + "create_config_disk", "on_close", "cpu_throttling", "process_priority", diff --git a/gns3server/schemas/qemu_template.py b/gns3server/schemas/qemu_template.py index f98c81d7..6414066e 100644 --- a/gns3server/schemas/qemu_template.py +++ b/gns3server/schemas/qemu_template.py @@ -183,6 +183,11 @@ QEMU_TEMPLATE_PROPERTIES = { "type": "boolean", "default": True }, + "create_config_disk": { + "description": "Automatically create a config disk on HDD disk interface (secondary slave)", + "type": "boolean", + "default": True + }, "on_close": { "description": "Action to execute on the VM is closed", "enum": ["power_off", "shutdown_signal", "save_vm_state"],