Added library support for remote explorer execution.

The library is now copied to the remote side if any explorer will
executed. This allows to share code across multiple explorers.

While the library code is quite different for different use cases (e.g.
manifest, gencode, remote side), everything get copied. This may be a
waste and could be categorized better. It would result in only copy the
general and required folder to the remote.
This commit is contained in:
matze 2020-07-25 12:40:49 +02:00
parent 7f95bbd535
commit e779289e5d
6 changed files with 35 additions and 4 deletions

View file

@ -58,6 +58,7 @@ class CdistType:
raise InvalidTypeError(self.name, self.path, self.absolute_path)
self.manifest_path = os.path.join(self.name, "manifest")
self.explorer_path = os.path.join(self.name, "explorer")
self.library_path = os.path.join(self.name, "library")
self.gencode_local_path = os.path.join(self.name, "gencode-local")
self.gencode_remote_path = os.path.join(self.name, "gencode-remote")
self.manifest_path = os.path.join(self.name, "manifest")

View file

@ -109,7 +109,7 @@ class Code:
'__target_fqdn': self.target_host[2],
'__global': self.local.base_path,
'__files': self.local.files_path,
'__library': self.local.library_path,
'__library': self.local.global_library_path,
'__target_host_tags': self.local.target_host_tags,
'__cdist_log_level': util.log_level_env_var_val(local.log),
'__cdist_log_level_name': util.log_level_name_env_var_val(

View file

@ -36,6 +36,9 @@ common:
__explorer: full qualified path to other global explorers on
remote side
-> remote.global_explorer_path
__library: full qualified path to global library files on the
remote side
-> remote.global_library_path
a global explorer is:
- a script
@ -57,6 +60,7 @@ type explorer is:
__object_fq: full qualified object id, iow: $type.name + / + object_id
__type_explorer: full qualified path to the other type explorers on
remote side
__type_library: full qualified path to the type library files on remote
creates: nothing, returns output
@ -79,6 +83,7 @@ class Explorer:
'__target_hostname': self.target_host[1],
'__target_fqdn': self.target_host[2],
'__explorer': self.remote.global_explorer_path,
'__library': self.remote.global_library_path,
'__target_host_tags': self.local.target_host_tags,
'__cdist_log_level': util.log_level_env_var_val(self.log),
'__cdist_log_level_name': util.log_level_name_env_var_val(
@ -106,6 +111,7 @@ class Explorer:
"""
self.log.verbose("Running global explorers")
self.transfer_global_library()
self.transfer_global_explorers()
if self.jobs is None:
self._run_global_explorers_seq(out_path)
@ -164,6 +170,14 @@ class Explorer:
self.remote.run(["chmod", "0700",
"%s/*" % (self.remote.global_explorer_path)])
def transfer_global_library(self):
"""Transfer the global library files to the remote side."""
self.remote.transfer(self.local.global_library_path,
self.remote.global_library_path,
self.jobs)
self.remote.run(["chmod", "0700",
"%s/*" % (self.remote.global_library_path)])
def run_global_explorer(self, explorer):
"""Run the given global explorer and return it's output."""
script = os.path.join(self.remote.global_explorer_path, explorer)
@ -225,7 +239,9 @@ class Explorer:
'__object_name': cdist_object.name,
'__object_fq': cdist_object.path,
'__type_explorer': os.path.join(self.remote.type_path,
cdist_type.explorer_path)
cdist_type.explorer_path),
'__type_library': os.path.join(self.remote.type_path,
cdist_type.library_path),
})
script = os.path.join(self.remote.type_path, cdist_type.explorer_path,
explorer)
@ -239,6 +255,8 @@ class Explorer:
self.log.trace(("Skipping retransfer of type explorers "
"for: %s"), cdist_type)
else:
self.transfer_type_library(cdist_type)
source = os.path.join(self.local.type_path,
cdist_type.explorer_path)
destination = os.path.join(self.remote.type_path,
@ -247,6 +265,17 @@ class Explorer:
self.remote.run(["chmod", "0700", "%s/*" % (destination)])
self._type_explorers_transferred.append(cdist_type.name)
def transfer_type_library(self, cdist_type):
"""Transfer the type library for the given type to the
remote side."""
source = os.path.join(self.local.type_path,
cdist_type.library_path)
if os.path.exists(source) and os.listdir(source):
destination = os.path.join(self.remote.type_path,
cdist_type.library_path)
self.remote.transfer(source, destination)
self.remote.run(["chmod", "0700", "%s/*" % (destination)])
def transfer_object_parameters(self, cdist_object):
"""Transfer the parameters for the given object to the remote side."""
if cdist_object.parameters:

View file

@ -116,7 +116,7 @@ class Manifest:
'__target_hostname': self.target_host[1],
'__target_fqdn': self.target_host[2],
'__files': self.local.files_path,
'__library': self.local.library_path,
'__library': self.local.global_library_path,
'__target_host_tags': self.local.target_host_tags,
'__cdist_log_level': util.log_level_env_var_val(self.log),
'__cdist_log_level_name': util.log_level_name_env_var_val(

View file

@ -118,12 +118,12 @@ class Local:
# Depending on conf_path
self.files_path = os.path.join(self.conf_path, "files")
self.global_explorer_path = os.path.join(self.conf_path, "explorer")
self.global_library_path = os.path.join(self.conf_path, "library")
self.manifest_path = os.path.join(self.conf_path, "manifest")
self.initial_manifest = (self.custom_initial_manifest or
os.path.join(self.manifest_path, "init"))
self.type_path = os.path.join(self.conf_path, "type")
self.library_path = os.path.join(self.conf_path, "library")
def _init_object_marker(self):
self.object_marker_file = os.path.join(self.base_path, "object_marker")

View file

@ -91,6 +91,7 @@ class Remote:
self.type_path = os.path.join(self.conf_path, "type")
self.global_explorer_path = os.path.join(self.conf_path, "explorer")
self.global_library_path = os.path.join(self.conf_path, "library")
self._open_logger()