pipeline,api: write metadata directly
Instead of transmitting stage metadata over a socket and then writing it via `Object.meta.write`, use the latter and bind mount the corresponding file into the stage so it can directly be written to from the stage. Change `api.metadata` to do so, which means that this change is transparent for the stages.
This commit is contained in:
parent
8b638562d1
commit
809c9e7828
3 changed files with 19 additions and 39 deletions
|
|
@ -142,15 +142,8 @@ class API(BaseAPI):
|
|||
|
||||
def __init__(self, *, socket_address=None):
|
||||
super().__init__(socket_address)
|
||||
self.metadata = {}
|
||||
self.error = None
|
||||
|
||||
def _set_metadata(self, message, fds):
|
||||
fd = message["metadata"]
|
||||
with os.fdopen(fds.steal(fd), encoding="utf8") as f:
|
||||
data = json.load(f)
|
||||
self.metadata.update(data)
|
||||
|
||||
def _get_exception(self, message):
|
||||
self.error = {
|
||||
"type": "exception",
|
||||
|
|
@ -158,9 +151,7 @@ class API(BaseAPI):
|
|||
}
|
||||
|
||||
def _message(self, msg, fds, sock):
|
||||
if msg["method"] == 'add-metadata':
|
||||
self._set_metadata(msg, fds)
|
||||
elif msg["method"] == 'exception':
|
||||
if msg["method"] == 'exception':
|
||||
self._get_exception(msg)
|
||||
|
||||
|
||||
|
|
@ -200,18 +191,8 @@ def arguments(path="/run/osbuild/api/arguments"):
|
|||
return data
|
||||
|
||||
|
||||
def metadata(data: Dict, path="/run/osbuild/api/osbuild"):
|
||||
def metadata(data: Dict, path="/run/osbuild/meta"):
|
||||
"""Update metadata for the current module"""
|
||||
|
||||
def data_to_file():
|
||||
with tempfile.TemporaryFile() as f:
|
||||
f.write(json.dumps(data).encode('utf8'))
|
||||
# re-open the file to get a read-only file descriptor
|
||||
return open(f"/proc/self/fd/{f.fileno()}", "r", encoding="utf8")
|
||||
|
||||
with jsoncomm.Socket.new_client(path) as client, data_to_file() as f:
|
||||
msg = {
|
||||
"method": "add-metadata",
|
||||
"metadata": 0
|
||||
}
|
||||
client.send(msg, fds=[f.fileno()])
|
||||
with open(path, "w", encoding="utf8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue