Merge branch 'feature__cdist_autodep_try2' of git://github.com/dheule/cdist

This commit is contained in:
Nico Schottelius 2014-02-06 15:48:45 +01:00
commit 41266a1946
2 changed files with 51 additions and 2 deletions

View file

@ -72,6 +72,7 @@ class Emulator(object):
raise MissingRequiredEnvironmentVariableError(e.args[0]) raise MissingRequiredEnvironmentVariableError(e.args[0])
self.object_base_path = os.path.join(self.global_path, "object") self.object_base_path = os.path.join(self.global_path, "object")
self.typeorder_path = os.path.join(self.global_path, "typeorder")
self.type_name = os.path.basename(argv[0]) self.type_name = os.path.basename(argv[0])
self.cdist_type = core.CdistType(self.type_base_path, self.type_name) self.cdist_type = core.CdistType(self.type_base_path, self.type_name)
@ -157,6 +158,9 @@ class Emulator(object):
else: else:
self.cdist_object.create() self.cdist_object.create()
self.cdist_object.parameters = self.parameters self.cdist_object.parameters = self.parameters
# record the created object in typeorder file
with open(self.typeorder_path, 'a') as typeorderfile:
print(self.cdist_object.name, file=typeorderfile)
# Record / Append source # Record / Append source
self.cdist_object.source.append(self.object_source) self.cdist_object.source.append(self.object_source)
@ -186,6 +190,23 @@ class Emulator(object):
def record_requirements(self): def record_requirements(self):
"""record requirements""" """record requirements"""
if "CDIST_ORDER_DEPENDENCY" in self.env:
# load object name created bevor this one from typeorder file ...
with open(self.typeorder_path, 'r') as typecreationfile:
typecreationorder = typecreationfile.readlines()
# get the type created bevore this one ...
try:
lastcreatedtype = typecreationorder[-2].strip()
if 'require' in self.env:
self.env['require'] += " " + lastcreatedtype
else:
self.env['require'] = lastcreatedtype
self.log.debug("Injecting require for CDIST_ORDER_DEPENDENCY: %s for %s", lastcreatedtype, self.cdist_object.name)
except IndexError:
# if no second last line, we are on the first type, so do not set a requirement
pass
if "require" in self.env: if "require" in self.env:
requirements = self.env['require'] requirements = self.env['require']
self.log.debug("reqs = " + requirements) self.log.debug("reqs = " + requirements)
@ -203,7 +224,7 @@ class Emulator(object):
self.log.error("%s requires object %s without object id. Defined at %s" % (self.cdist_object.name, requirement, self.object_source)) self.log.error("%s requires object %s without object id. Defined at %s" % (self.cdist_object.name, requirement, self.object_source))
raise raise
self.log.debug("Recording requirement: " + requirement) self.log.debug("Recording requirement: %s", requirement)
# Save the sanitised version, not the user supplied one # Save the sanitised version, not the user supplied one
# (__file//bar => __file/bar) # (__file//bar => __file/bar)

View file

@ -128,7 +128,6 @@ All objects that are created in a type manifest are automatically required
from the type that is calling them. This is called "autorequirement" in from the type that is calling them. This is called "autorequirement" in
cdist jargon. cdist jargon.
OVERRIDES OVERRIDES
--------- ---------
In some special cases, you would like to create an already defined object In some special cases, you would like to create an already defined object
@ -142,6 +141,35 @@ into an undefined situation.
THIS IS A BETA FEATURE AND MAY BE REMOVED AT ANY TIME. THIS IS A BETA FEATURE AND MAY BE REMOVED AT ANY TIME.
CDIST_ORDER_DEPENDENCY is a EXPERIMENTAL FEATURE !
You can tell cdist to execute all types in the order in which they are created
in the manifest by exporting CDIST_ORDER_DEPENDENCY.
--------------------------------------------------------------------------------
# Tells cdist to execute all types in the order in which they are created ...
export CDIST_ORDER_DEPENDENCY=on
__sample_type 1
require="__some_type_somewhere/id" __sample_type 2
__example_type 23
# Now this types are executed in the creation order until the variable is unset
unset CDIST_ORDER_DEPENDENCY
# all now following types cdist makes the order ..
__not_in_order_type 42
# how it works :
# this lines above are translated to:
__sample_type 1
require="__some_type_somewhere/id __sample_type/1" __sample_type 2
require="__sample_type/2" __example_type 23
__not_in_order_type 42
--------------------------------------------------------------------------------
EXAMPLES EXAMPLES
-------- --------
The initial manifest may for instance contain the following code: The initial manifest may for instance contain the following code: