From fc2743a0ceb5823a4f32a02ee880892b93eef98d Mon Sep 17 00:00:00 2001 From: Massimiliano Date: Fri, 1 Mar 2024 17:13:35 +0100 Subject: [PATCH] Use pylxd mount disk (infra) (#1032) * Use pylxd api to mount disks * Apply suggestion from the review --- metabox/metabox/core/lxd_provider.py | 40 +++++++--------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/metabox/metabox/core/lxd_provider.py b/metabox/metabox/core/lxd_provider.py index a3bdd390e..3b062abc4 100644 --- a/metabox/metabox/core/lxd_provider.py +++ b/metabox/metabox/core/lxd_provider.py @@ -285,40 +285,18 @@ def _transfer_file_preserve_mode(self, machine, src, dest): def _mount_source(self, machine, path): logger.debug("Mounting dir {}", path) - output = subprocess.check_output( - [ - "lxc", - "config", - "device", - "add", - machine._container.name, - self.LXD_MOUNT_DEVICE, - "disk", - "source={}".format(path), - "path={}".format(self.LXD_SOURCE_MOUNT_POINT), - ], - stderr=subprocess.PIPE, - text=True, - ).strip() - if output: - logger.debug(output) + disk_config = { + "source": path, + "path": self.LXD_SOURCE_MOUNT_POINT, + "type": "disk", + } + machine._container.devices.update({self.LXD_MOUNT_DEVICE: disk_config}) + machine._container.save(wait=True) def _unmount_source(self, machine): logger.debug("Unmounting dir...") - output = subprocess.check_output( - [ - "lxc", - "config", - "device", - "remove", - machine._container.name, - self.LXD_MOUNT_DEVICE, - ], - stderr=subprocess.PIPE, - text=True, - ).strip() - if output: - logger.debug(output) + del machine._container.devices[self.LXD_MOUNT_DEVICE] + machine._container.save(wait=True) @contextmanager def _mounted_source(self, machine, path):