objectstore: add HostTree class to access host fs
Simple new object that should expose the root file system with the same API as `objectstore.Object` but as read-only. This means that the `read` call works exactly as for `Object` but `write` raises an exception. Add tests to specifically check the read-only properties.
This commit is contained in:
parent
01efa9f817
commit
457f21a336
2 changed files with 42 additions and 0 deletions
|
|
@ -203,6 +203,33 @@ class Object:
|
|||
return exc_type is None
|
||||
|
||||
|
||||
class HostTree:
|
||||
"""Read-only access to the host file system
|
||||
|
||||
An object that provides the same interface as
|
||||
`objectstore.Object` that can be used to read
|
||||
the host file-system.
|
||||
"""
|
||||
def __init__(self, store):
|
||||
self.store = store
|
||||
|
||||
@staticmethod
|
||||
def write():
|
||||
raise ValueError("Cannot write to host")
|
||||
|
||||
@contextlib.contextmanager
|
||||
def read(self):
|
||||
with self.store.tempdir() as tmp:
|
||||
mount("/", tmp)
|
||||
try:
|
||||
yield tmp
|
||||
finally:
|
||||
umount(tmp)
|
||||
|
||||
def cleanup(self):
|
||||
pass # noop for the host
|
||||
|
||||
|
||||
class ObjectStore:
|
||||
def __init__(self, store):
|
||||
self.store = store
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue