Skip to content

Commit

Permalink
Use pylxd mount disk (infra) (#1032)
Browse files Browse the repository at this point in the history
* Use pylxd api to mount disks

* Apply suggestion from the review
  • Loading branch information
Hook25 authored Mar 1, 2024
1 parent f00961c commit fc2743a
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions metabox/metabox/core/lxd_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit fc2743a

Please sign in to comment.