From 5ef27191fca6b60f6a02664cb7799e45de052674 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 20 Mar 2014 13:52:12 +0100 Subject: [PATCH] implementing the $__object and $__object_id on the local and remote execution call, to allow read access to parameter files --- cdist/core/code.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cdist/core/code.py b/cdist/core/code.py index f128697f..6abfb393 100644 --- a/cdist/core/code.py +++ b/cdist/core/code.py @@ -123,15 +123,27 @@ class Code(object): self.remote.mkdir(destination) self.remote.transfer(source, destination) - def _run_code(self, cdist_object, which): + def _run_code(self, cdist_object, which, env=None): which_exec = getattr(self, which) script = os.path.join(which_exec.object_path, getattr(cdist_object, 'code_%s_path' % which)) - return which_exec.run_script(script) + return which_exec.run_script(script, env=env) def run_code_local(self, cdist_object): """Run the code-local script for the given cdist object.""" - return self._run_code(cdist_object, 'local') + # Put some env vars, to allow read only access to the parameters over $__object + env = os.environ.copy() + env.update(self.env) + env.update({ + '__object': cdist_object.absolute_path, + '__object_id': cdist_object.object_id, + }) + return self._run_code(cdist_object, 'local', env=env) def run_code_remote(self, cdist_object): """Run the code-remote script for the given cdist object on the remote side.""" - return self._run_code(cdist_object, 'remote') + # Put some env vars, to allow read only access to the parameters over $__object which is already on the remote side + env = { + '__object': os.path.join(self.remote.object_path, cdist_object.path), + '__object_id': cdist_object.object_id, + } + return self._run_code(cdist_object, 'remote', env=env)