more s/_dir/_path/g
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
e1f0d60e8b
commit
7169d6ac42
2 changed files with 46 additions and 45 deletions
|
@ -37,7 +37,7 @@ class ConfigInstall:
|
|||
"""Cdist main class to hold arbitrary data"""
|
||||
|
||||
def __init__(self, target_host, initial_manifest=False,
|
||||
base_dir=False,
|
||||
base_path=False,
|
||||
exec_path=sys.argv[0],
|
||||
debug=False):
|
||||
|
||||
|
@ -48,7 +48,7 @@ class ConfigInstall:
|
|||
self.exec_path = exec_path
|
||||
|
||||
self.context = cdist.context.Context(self.target_host,
|
||||
initial_manifest=initial_manifest, base_dir=base_dir,
|
||||
initial_manifest=initial_manifest, base_path=base_path,
|
||||
debug=debug)
|
||||
|
||||
def cleanup(self):
|
||||
|
@ -60,17 +60,18 @@ class ConfigInstall:
|
|||
def run_initial_manifest(self):
|
||||
"""Run the initial manifest"""
|
||||
log.info("Running initial manifest %s", self.context.initial_manifest)
|
||||
env = { "__manifest" : self.context.manifest_dir }
|
||||
env = { "__manifest" : self.context.manifest_path }
|
||||
self.run_manifest(self.context.initial_manifest, extra_env=env)
|
||||
|
||||
def run_type_manifest(self, cdist_object):
|
||||
"""Run manifest for a specific object"""
|
||||
type = cdist_object.type
|
||||
manifest = type.manifest_path
|
||||
manifest_path = os.path.join(self.context.type_base_path,
|
||||
type.manifest_path)
|
||||
|
||||
log.debug("%s: Running %s", cdist_object.name, manifest)
|
||||
if os.path.exists(manifest):
|
||||
env = { "__object" : cdist_object.path,
|
||||
env = { "__object" : os.path.join(self.context.cdist_object.path,
|
||||
"__object_id": cdist_object.object_id,
|
||||
"__object_fq": cdist_object.name,
|
||||
"__type": type.path,
|
||||
|
@ -81,13 +82,13 @@ class ConfigInstall:
|
|||
"""Run a manifest"""
|
||||
log.debug("Running manifest %s, env=%s", manifest, extra_env)
|
||||
env = os.environ.copy()
|
||||
env['PATH'] = self.context.bin_dir + ":" + env['PATH']
|
||||
env['PATH'] = self.context.bin_path + ":" + env['PATH']
|
||||
|
||||
# Information required in every manifest
|
||||
env['__target_host'] = self.target_host
|
||||
|
||||
# FIXME: __global == __cdist_out_dir - duplication
|
||||
env['__global'] = self.context.out_dir
|
||||
# FIXME: __global == __cdist_out_path - duplication
|
||||
env['__global'] = self.context.out_path
|
||||
|
||||
# Submit debug flag to manifest, can be used by emulator and types
|
||||
if self.debug:
|
||||
|
@ -97,7 +98,7 @@ class ConfigInstall:
|
|||
env['__cdist_manifest'] = manifest
|
||||
|
||||
# Required to find types
|
||||
env['__cdist_type_base_dir'] = type.path
|
||||
env['__cdist_type_base_path'] = type.path
|
||||
|
||||
# Other environment stuff
|
||||
if extra_env:
|
||||
|
@ -124,7 +125,7 @@ class ConfigInstall:
|
|||
#
|
||||
env = os.environ.copy()
|
||||
env['__target_host'] = self.target_host
|
||||
env['__global'] = self.context.out_dir
|
||||
env['__global'] = self.context.out_path
|
||||
env["__object"] = cdist_object.path
|
||||
env["__object_id"] = cdist_object.object_id
|
||||
env["__object_fq"] = cdist_object.name
|
||||
|
@ -179,8 +180,8 @@ class ConfigInstall:
|
|||
self.path.transfer_type_explorers(type)
|
||||
|
||||
cmd = []
|
||||
cmd.append("__explorer=" + self.context.remote_global_explorer_dir)
|
||||
cmd.append("__type_explorer=" + type.explorer_remote_dir)
|
||||
cmd.append("__explorer=" + self.context.remote_global_explorer_path)
|
||||
cmd.append("__type_explorer=" + type.explorer_remote_path)
|
||||
cmd.append("__object=" + object.path_remote)
|
||||
cmd.append("__object_id=" + object.object_id)
|
||||
cmd.append("__object_fq=" + cdist_object)
|
||||
|
@ -190,8 +191,8 @@ class ConfigInstall:
|
|||
|
||||
explorers = self.path.list_type_explorers(type)
|
||||
for explorer in explorers:
|
||||
remote_cmd = cmd + [os.path.join(type.explorer_remote_dir, explorer)]
|
||||
output = os.path.join(cdist_object.explorer_output_dir(), explorer)
|
||||
remote_cmd = cmd + [os.path.join(type.explorer_remote_path, explorer)]
|
||||
output = os.path.join(cdist_object.explorer_output_path(), explorer)
|
||||
output_fd = open(output, mode='w')
|
||||
log.debug("%s exploring %s using %s storing to %s",
|
||||
cdist_object, explorer, remote_cmd, output)
|
||||
|
@ -204,7 +205,7 @@ class ConfigInstall:
|
|||
"""Link emulator to types"""
|
||||
src = os.path.abspath(self.exec_path)
|
||||
for type in cdist.core.Type.list_types():
|
||||
dst = os.path.join(self.context.bin_dir, type.name)
|
||||
dst = os.path.join(self.context.bin_path, type.name)
|
||||
log.debug("Linking emulator: %s to %s", src, dst)
|
||||
|
||||
# FIXME: handle exception / make it more beautiful
|
||||
|
@ -214,15 +215,15 @@ class ConfigInstall:
|
|||
"""Run global explorers"""
|
||||
log.info("Running global explorers")
|
||||
|
||||
src = cdist.core.GlobalExplorer.base_dir
|
||||
dst = cdist.core.GlobalExplorer.remote_base_dir
|
||||
src = cdist.core.GlobalExplorer.base_path
|
||||
dst = cdist.core.GlobalExplorer.remote_base_path
|
||||
|
||||
self.context.transfer_dir(src, dst)
|
||||
self.context.transfer_path(src, dst)
|
||||
|
||||
for explorer in cdist.core.GlobalExplorer.list_explorers():
|
||||
output_fd = open(explorer.out_path, mode='w')
|
||||
cmd = []
|
||||
cmd.append("__explorer=" + cdist.core.GlobalExplorer.remote_base_dir)
|
||||
cmd.append("__explorer=" + cdist.core.GlobalExplorer.remote_base_path)
|
||||
cmd.append(explorer.remote_path)
|
||||
|
||||
cdist.exec.run_or_fail(cmd, stdout=output_fd, remote_prefix=True)
|
||||
|
@ -251,8 +252,8 @@ class ConfigInstall:
|
|||
"""Ensure the base directories are cleaned up"""
|
||||
log.debug("Creating clean directory structure")
|
||||
|
||||
self.context.remove_remote_dir(self.context.remote_base_dir)
|
||||
self.context.remote_mkdir(self.context.remote_base_dir)
|
||||
self.context.remove_remote_path(self.context.remote_base_path)
|
||||
self.context.remote_mkdir(self.context.remote_base_path)
|
||||
self.link_emulator()
|
||||
|
||||
def stage_prepare(self):
|
||||
|
@ -263,7 +264,7 @@ class ConfigInstall:
|
|||
|
||||
log.info("Running object manifests and type explorers")
|
||||
|
||||
log.debug("Searching for objects in " + cdist.core.Object.base_dir())
|
||||
log.debug("Searching for objects in " + cdist.core.Object.base_path())
|
||||
|
||||
# Continue process until no new objects are created anymore
|
||||
new_objects_created = True
|
||||
|
@ -284,17 +285,17 @@ class ConfigInstall:
|
|||
def transfer_object_parameter(self, cdist_object):
|
||||
"""Transfer the object parameter to the remote destination"""
|
||||
# Create base path before using mkdir -p
|
||||
self.remote_mkdir(self.remote_object_parameter_dir(cdist_object))
|
||||
self.remote_mkdir(self.remote_object_parameter_path(cdist_object))
|
||||
|
||||
# Synchronise parameter dir afterwards
|
||||
self.transfer_dir(self.object_parameter_dir(cdist_object),
|
||||
self.remote_object_parameter_dir(cdist_object))
|
||||
self.transfer_path(self.object_parameter_path(cdist_object),
|
||||
self.remote_object_parameter_path(cdist_object))
|
||||
|
||||
# FIXME Move into configinstall
|
||||
def transfer_global_explorers(self):
|
||||
"""Transfer the global explorers"""
|
||||
self.remote_mkdir(REMOTE_GLOBAL_EXPLORER_DIR)
|
||||
self.transfer_dir(self.global_explorer_dir, REMOTE_GLOBAL_EXPLORER_DIR)
|
||||
self.transfer_path(self.global_explorer_path, REMOTE_GLOBAL_EXPLORER_DIR)
|
||||
|
||||
# FIXME Move into configinstall
|
||||
def transfer_type_explorers(self, type):
|
||||
|
@ -306,7 +307,7 @@ class ConfigInstall:
|
|||
# Do not retransfer
|
||||
type.transferred_explorers = True
|
||||
|
||||
# FIXME: Can be explorer_path or explorer_dir, I don't care.
|
||||
# FIXME: Can be explorer_path or explorer_path, I don't care.
|
||||
src = type.explorer_path()
|
||||
dst = type.remote_explorer_path()
|
||||
|
||||
|
@ -314,4 +315,4 @@ class ConfigInstall:
|
|||
if len(type.explorers) > 0:
|
||||
# Ensure that the path exists
|
||||
self.remote_mkdir(dst)
|
||||
self.transfer_dir(src, dst)
|
||||
self.transfer_path(src, dst)
|
||||
|
|
|
@ -38,6 +38,7 @@ class Context:
|
|||
initial_manifest=False,
|
||||
base_path=False,
|
||||
out_path=False,
|
||||
remote_base_path=False,
|
||||
debug=False):
|
||||
|
||||
self.target_host = target_host
|
||||
|
@ -53,7 +54,7 @@ class Context:
|
|||
os.pardir))
|
||||
|
||||
|
||||
# Input directories
|
||||
# Local input directories
|
||||
self.cache_path = os.path.join(self.base_path, "cache", target_host)
|
||||
self.conf_path = os.path.join(self.base_path, "conf")
|
||||
|
||||
|
@ -62,35 +63,34 @@ class Context:
|
|||
self.type_base_path = os.path.join(self.conf_path, "type")
|
||||
self.lib_path = os.path.join(self.base_path, "lib")
|
||||
|
||||
# Mostly static, but can be overwritten on user demand
|
||||
if initial_manifest:
|
||||
self.initial_manifest = initial_manifest
|
||||
else:
|
||||
self.initial_manifest = os.path.join(self.manifest_path, "init")
|
||||
|
||||
# Output directories
|
||||
# Local output directories
|
||||
if out_path:
|
||||
self.out_path = out_path:
|
||||
else:
|
||||
self.out_path = os.path.join(tempfile.mkdtemp(), "out")
|
||||
|
||||
self.bin_path = os.path.join(self.out_path, "bin")
|
||||
self.global_explorer_out_path = os.path.join(self.out_path, "explorer")
|
||||
self.object_base_path = os.path.join(self.out_path, "object")
|
||||
self.bin_path = os.path.join(self.out_path, "bin")
|
||||
self.object_base_path = os.path.join(self.out_path, "object")
|
||||
|
||||
# Remote directories
|
||||
if "__cdist_remote_base_path" in os.environ:
|
||||
self.remote_base_path = os.environ['__cdist_remote_base_path']
|
||||
if remote_base_path:
|
||||
self.remote_base_path = remote_base_path
|
||||
else:
|
||||
self.remote_base_path = "/var/lib/cdist"
|
||||
|
||||
self.remote_conf_path = os.path.join(self.remote_base_path, "conf")
|
||||
self.remote_object_dir = os.path.join(self.remote_base_path, "object")
|
||||
self.remote_type_dir = os.path.join(self.remote_conf_path, "type")
|
||||
self.remote_global_explorer_dir = os.path.join(self.remote_conf_path, "explorer")
|
||||
self.remote_object_path = os.path.join(self.remote_base_path, "object")
|
||||
self.remote_type_path = os.path.join(self.remote_conf_path, "type")
|
||||
self.remote_global_explorer_path = os.path.join(self.remote_conf_path, "explorer")
|
||||
|
||||
# Create directories
|
||||
self.__init_out_dirs()
|
||||
self.__init_out_paths()
|
||||
|
||||
self.__init_env()
|
||||
|
||||
|
@ -108,24 +108,24 @@ class Context:
|
|||
|
||||
def __init_env(self):
|
||||
"""Setup environment"""
|
||||
os.environ['__cdist_out_dir'] = self.out_dir
|
||||
os.environ['__cdist_out_path'] = self.out_path
|
||||
os.environ['__cdist_base_path'] = self.base_path
|
||||
|
||||
def __init_out_dirs(self):
|
||||
def __init_out_paths(self):
|
||||
"""Initialise output directory structure"""
|
||||
|
||||
# Create base dir, if user supplied and not existing
|
||||
if not os.path.isdir(self.base_path):
|
||||
os.mkdir(self.base_path)
|
||||
|
||||
os.mkdir(self.out_dir)
|
||||
os.mkdir(self.global_explorer_out_dir)
|
||||
os.mkdir(self.bin_dir)
|
||||
os.mkdir(self.out_path)
|
||||
os.mkdir(self.global_explorer_out_path)
|
||||
os.mkdir(self.bin_path)
|
||||
|
||||
def remote_mkdir(self, directory):
|
||||
"""Create directory on remote side"""
|
||||
cdist.exec.run_or_fail(["mkdir", "-p", directory], remote_prefix=True)
|
||||
|
||||
def remove_remote_dir(self, destination):
|
||||
def remove_remote_path(self, destination):
|
||||
cdist.exec.run_or_fail(["rm", "-rf", destination], remote_prefix=True)
|
||||
|
||||
|
|
Loading…
Reference in a new issue