mounts: introduce new mount manager class
Introduce a new specialized service manager class `MountManager` to manage mounts. It uses the newly introduced `DeviceManager` to look up devices and stores the reference to the mount point root path. See the commit that introduced the `DeviceManager` for more info.
This commit is contained in:
parent
2447172125
commit
5694743ca6
2 changed files with 35 additions and 13 deletions
|
|
@ -13,9 +13,10 @@ import json
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
from typing import Dict, Tuple
|
||||
from typing import Dict
|
||||
|
||||
from osbuild import host
|
||||
from osbuild.devices import DeviceManager
|
||||
|
||||
|
||||
class Mount:
|
||||
|
|
@ -39,23 +40,45 @@ class Mount:
|
|||
m.update(json.dumps(self.options, sort_keys=True).encode())
|
||||
return m.hexdigest()
|
||||
|
||||
def mount(self, mgr: host.ServiceManager, dev: str, root: str) -> Tuple[Dict]:
|
||||
|
||||
class MountManager:
|
||||
"""Manager for Mounts
|
||||
|
||||
Uses a `host.ServiceManager` to activate `Mount` instances.
|
||||
Takes a `DeviceManager` to access devices and a directory
|
||||
called `root`, which is the root of all the specified mount
|
||||
points.
|
||||
"""
|
||||
|
||||
def __init__(self, devices: DeviceManager, root: str) -> None:
|
||||
self.devices = devices
|
||||
self.root = root
|
||||
self.mounts = {}
|
||||
|
||||
def mount(self, mount: Mount) -> Dict:
|
||||
|
||||
source = self.devices.device_abspath(mount.device)
|
||||
|
||||
args = {
|
||||
"source": dev,
|
||||
"root": root,
|
||||
"target": self.target,
|
||||
"source": source,
|
||||
"root": self.root,
|
||||
"target": mount.target,
|
||||
|
||||
"options": self.options,
|
||||
"options": mount.options,
|
||||
}
|
||||
|
||||
client = mgr.start(f"mount/{self.name}", self.info.path)
|
||||
mgr = self.devices.service_manager
|
||||
|
||||
client = mgr.start(f"mount/{mount.name}", mount.info.path)
|
||||
path = client.call("mount", args)
|
||||
|
||||
if not path.startswith(root):
|
||||
if not path.startswith(self.root):
|
||||
raise RuntimeError(f"returned path '{path}' has wrong prefix")
|
||||
|
||||
path = os.path.relpath(path, root)
|
||||
path = os.path.relpath(path, self.root)
|
||||
|
||||
self.mounts[mount.name] = path
|
||||
|
||||
return {"path": path}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from . import objectstore
|
|||
from . import remoteloop
|
||||
from .devices import Device, DeviceManager
|
||||
from .inputs import Input
|
||||
from .mounts import Mount
|
||||
from .mounts import Mount, MountManager
|
||||
from .sources import Source
|
||||
from .util import osrelease
|
||||
|
||||
|
|
@ -168,10 +168,9 @@ class Stage:
|
|||
for name, dev in self.devices.items():
|
||||
devices[name] = devmgr.open(dev)
|
||||
|
||||
mntmgr = MountManager(devmgr, mounts_tmpdir)
|
||||
for key, mount in self.mounts.items():
|
||||
relpath = devices[mount.device.name]["path"]
|
||||
abspath = os.path.join(build_root.dev, relpath)
|
||||
data = mount.mount(mgr, abspath, mounts_tmpdir)
|
||||
data = mntmgr.mount(mount)
|
||||
mounts[key] = data
|
||||
|
||||
self.prepare_arguments(args, args_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue