From 7eb418c3ab6db117db2de036226d05da3033b1cd Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 10 Sep 2011 00:40:45 +0200 Subject: [PATCH] correct env for the various stages Signed-off-by: Nico Schottelius --- bin/cdist | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/bin/cdist b/bin/cdist index 505bb012..af19a676 100755 --- a/bin/cdist +++ b/bin/cdist @@ -246,6 +246,10 @@ class Cdist: """Returns the first part (i.e. type) of an object""" return cdist_object.split(os.sep)[0] + def get_object_id_from_object(self, cdist_object): + """Returns everything but the first part (i.e. object_id) of an object""" + return os.sep.join(cdist_object.split(os.sep)[1:]) + def object_dir(self, cdist_object): """Returns the full path to the object (including .cdist)""" return os.path.join(self.object_base_dir, cdist_object, DOT_CDIST) @@ -281,6 +285,10 @@ class Cdist: """Return directory that holds the explorers of a type""" return os.path.join(TYPE_DIR, type, "explorer") + def type_manifest_path(self, type): + """Return path to manifest of type""" + return os.path.join(TYPE_DIR, type, "manifest") + def remote_type_explorer_dir(self, type): """Return remote directory that holds the explorers of a type""" return os.path.join(REMOTE_TYPE_DIR, type, "explorer") @@ -352,6 +360,7 @@ class Cdist: self.transfer_type_explorers(type) cmd = [] + # FIXME: __global::__object_id::__self:: cmd.append("__explorer=" + REMOTE_GLOBAL_EXPLORER_DIR) cmd.append("__type_explorer=" + self.remote_type_explorer_dir(type)) @@ -381,15 +390,27 @@ class Cdist: def run_initial_manifest(self): """Run the initial manifest""" - self.run_manifest(self.initial_manifest) + # FIXME: add support for __manifest:: + env = { "__manifest" : MANIFEST_DIR } + self.run_manifest(self.initial_manifest, extra_env=env) def run_type_manifest(self, cdist_object): """Run manifest for a specific object""" - self.run_manifest(self.initial_manifest) + type = self.get_type_from_object(cdist_object) + manifest = self.type_manifest_path(type) + + # FIXME: add more sensible checks for manifest + if os.path.exists(manifest): + env = { "__object" : self.object_dir(cdist_object), + "__object_id": self.get_object_id_from_object(cdist_object), + "__object_fq": cdist_object, + "__type": type + } + self.run_manifest(self.initial_manifest, extra_env=env) def run_manifest(self, manifest, extra_env=None): """Run a manifest""" - log.info("Running the initial manifest") + log.info("Running manifest %s", manifest) env = os.environ.copy() env['PATH'] = self.bin_dir + ":" + env['PATH'] @@ -420,8 +441,10 @@ class Cdist: objects = self.list_objects() # Continue process until no new objects are created anymore - while not old_objects == objects: - old_objects = objects.copy() + while old_objects != objects: + log.debug("Prepare stage") + old_objects = list(objects) + # FIXME: do not rerun existing objects! for cdist_object in objects: self.run_type_explorer(cdist_object) self.run_type_manifest(cdist_object)