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