From 2e0fba925bdd796ddd5eea0a4c9e4dcebed861ab Mon Sep 17 00:00:00 2001 From: Bernhard Ehlers Date: Thu, 16 Apr 2020 11:07:56 +0200 Subject: [PATCH] QEMU config disk - add missing config disk to image directory --- gns3server/compute/qemu/qemu_vm.py | 27 +++++++++++++----- .../compute/qemu/resources/config.img.zip | Bin 0 -> 1368 bytes 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 gns3server/compute/qemu/resources/config.img.zip diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 61b5f0e8..f8ca6902 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -46,6 +46,7 @@ from ..nios.nio_tap import NIOTAP from ..base_node import BaseNode from ...schemas.qemu import QEMU_OBJECT_SCHEMA, QEMU_PLATFORMS from ...utils.asyncio import monitor_process +from ...utils.get_resource import get_resource from ...utils.images import md5sum from ...utils import macaddress_to_int, int_to_macaddress @@ -129,19 +130,31 @@ class QemuVM(BaseNode): self.adapters = 1 # creates 1 adapter by default # config disk - self.config_disk_name = "config.img" + config_disk_name = "config.img" + self.config_disk_name = "" + self.config_disk_image = "" if not shutil.which("mcopy"): log.warning("Config disk: 'mtools' are not installed.") - self.config_disk_name = "" - self.config_disk_image = "" else: try: self.config_disk_image = self.manager.get_abs_image_path( - self.config_disk_name, self.project.path) + config_disk_name, self.project.path) + self.config_disk_name = config_disk_name except (NodeError, ImageMissingError) as e: - log.warning("Config disk: {}".format(e)) - self.config_disk_name = "" - self.config_disk_image = "" + config_disk_zip = get_resource("compute/qemu/resources/{}.zip" + .format(config_disk_name)) + if config_disk_zip and os.path.exists(config_disk_zip): + directory = self.manager.get_images_directory() + try: + unpack_zip(config_disk_zip, directory) + self.config_disk_image = os.path.join(directory, + config_disk_name) + self.config_disk_name = config_disk_name + except OSError as e: + log.warning("Config disk creation: {}".format(e)) + else: + log.warning("Config disk: image '{}' missing" + .format(config_disk_name)) log.info('QEMU VM "{name}" [{id}] has been created'.format(name=self._name, id=self._id)) diff --git a/gns3server/compute/qemu/resources/config.img.zip b/gns3server/compute/qemu/resources/config.img.zip new file mode 100644 index 0000000000000000000000000000000000000000..7ba43f9e0db1535a2d465dad484dbb05046d0575 GIT binary patch literal 1368 zcmWIWW@Zs#U|`^2;D~Dru#K9RvW^AFWe{NCVvu1-&d*EBOxMfIO%Dy>WMF>qt1IsH zrM|e*3T_5QmKV$n3}E8zbwxksKmmpeKW95!pUTp@`shWc00pfBTeG9qHMp<8A#4)E zbXhoHmV>Q` L1Az1=aQO)Uu