From 60c4e21981390676deec431b3884332a7c7e39b9 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Thu, 20 Oct 2011 11:05:50 +0200 Subject: [PATCH] implement Explorer run_global_explorers and run_type_explorers Signed-off-by: Steven Armstrong --- lib/cdist/core/explorer.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/cdist/core/explorer.py b/lib/cdist/core/explorer.py index 2e13cc78..0a8c6986 100644 --- a/lib/cdist/core/explorer.py +++ b/lib/cdist/core/explorer.py @@ -83,6 +83,19 @@ class Explorer(object): """Return a list of global explorer names.""" return os.listdir(self.local.global_explorer_path) + def run_global_explorers(self, out_path): + """Run global explorers and save output to files in the given + out_path directory. + + """ + self.log.info("Running global explorers") + self.transfer_global_explorers() + for explorer in self.list_global_explorer_names(): + output = self.run_global_explorer(explorer) + path = os.path.join(out_path, explorer) + with open(path, 'w') as fd: + fd.write(output) + def transfer_global_explorers(self): """Transfer the global explorers to the remote side.""" self.remote.mkdir(self.remote.global_explorer_path) @@ -103,6 +116,20 @@ class Explorer(object): except EnvironmentError: return [] + def run_type_explorers(self, cdist_object): + """Run the type explorers for the given object and save their output + in the object. + + """ + self.log.debug("Transfering type explorers for type: %s", cdist_object.type) + self.transfer_type_explorers(cdist_object.type) + self.log.debug("Transfering object parameters for object: %s", cdist_object.name) + self.transfer_object_parameters(cdist_object) + for explorer in self.list_type_explorer_names(cdist_object.type): + output = self.run_type_explorer(explorer, cdist_object) + self.log.debug("Running type explorer '%s' for object '%s'", explorer, cdist_object.name) + cdist_object.explorers[explorer] = output + def transfer_type_explorers(self, cdist_type): """Transfer the type explorers for the given type to the remote side.""" if cdist_type.explorers: