cleanup object_run() finally

Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
Nico Schottelius 2011-10-07 13:34:22 +02:00
parent 484b947eca
commit f121934769

View file

@ -104,16 +104,17 @@ class ConfigInstall:
################################################################################ ################################################################################
def object_run(self, cdist_object, mode): def object_run(self, cdist_object):
"""Run gencode or code for an object""" """Run gencode or code for an object"""
log.debug("Running %s from %s", mode, cdist_object) log.debug("Running %s from %s", mode, cdist_object)
requirements = cdist_object.requirements # Catch requirements, which re-call us
if cdist_object.ran:
return
type = cdist_object.type type = cdist_object.type
# FIXME: ensure objects are not run multiple times! for requirement in cdist_object.requirements:
# FIXME: probably mark objects!
for requirement in requirements:
log.debug("Object %s requires %s", cdist_object, requirement) log.debug("Object %s requires %s", cdist_object, requirement)
self.object_run(requirement, mode=mode) self.object_run(requirement, mode=mode)
@ -128,12 +129,7 @@ class ConfigInstall:
env["__object_fq"] = cdist_object.name env["__object_fq"] = cdist_object.name
env["__type"] = type.name env["__type"] = type.name
if mode == "gencode": # gencode
paths = [
type.gencode
type.gencode_remote
]
for cmd in ["local", "remote"]: for cmd in ["local", "remote"]:
bin = getattr(type, "gencode_" + cmd) bin = getattr(type, "gencode_" + cmd)
@ -157,27 +153,22 @@ class ConfigInstall:
else: else:
# Add header and make executable - identically to 0o700 # Add header and make executable - identically to 0o700
os.chmod(outfile, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR) os.chmod(outfile, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR)
cdist_object.changed=True
# FIXME: use new interface # code local
# Mark object as changed code_local = cdist_object.code_local
open(os.path.join(self.path.object_dir(cdist_object), "changed"), "w").close() if os.path.isfile(code_local):
cdist.exec.run_or_fail([code_local])
# code remote
if mode == "code": local_remote_code = cdist_object.code_remote
local_dir = self.path.object_dir(cdist_object) remote_remote_code = cdist_object.code_remote_remote
remote_dir = self.path.remote_object_dir(cdist_object)
bin = os.path.join(local_dir, "code-local")
if os.path.isfile(bin):
cdist.exec.run_or_fail([bin])
local_remote_code = os.path.join(local_dir, "code-remote")
remote_remote_code = os.path.join(remote_dir, "code-remote")
if os.path.isfile(local_remote_code): if os.path.isfile(local_remote_code):
self.path.transfer_file(local_remote_code, remote_remote_code) self.context.transfer_file(local_remote_code, remote_remote_code)
cdist.exec.run_or_fail([remote_remote_code], remote_prefix=True) cdist.exec.run_or_fail([remote_remote_code], remote_prefix=True)
cdist_object.ran = True
### Cleaned / check functions: Round 1 :-) ################################# ### Cleaned / check functions: Round 1 :-) #################################
def run_type_explorer(self, cdist_object): def run_type_explorer(self, cdist_object):
"""Run type specific explorers for objects""" """Run type specific explorers for objects"""
@ -239,11 +230,9 @@ class ConfigInstall:
def stage_run(self): def stage_run(self):
"""The final (and real) step of deployment""" """The final (and real) step of deployment"""
log.info("Generating and executing code") log.info("Generating and executing code")
# Now do the final steps over the existing objects
for cdist_object in cdist.core.Object.list_objects(): for cdist_object in cdist.core.Object.list_objects():
log.debug("Run object: %s", cdist_object) log.debug("Run object: %s", cdist_object)
self.object_run(cdist_object, mode="gencode") self.object_run(cdist_object)
self.object_run(cdist_object, mode="code")
def deploy_to(self): def deploy_to(self):
"""Mimic the old deploy to: Deploy to one host""" """Mimic the old deploy to: Deploy to one host"""