Merge pull request #26 from salt-formulas/ref-in-classes
Interpolate references in class names
diff --git a/README-extentions.rst b/README-extentions.rst
index 97d78af..9085b57 100644
--- a/README-extentions.rst
+++ b/README-extentions.rst
@@ -208,6 +208,55 @@
group_errors: True
+Use references in class names
+-----------------------------
+
+Allows to use references in the class names.
+
+Assuming following setup:
+
+.. code-block:: yaml
+ #/etc/reclass/classes/first.yml
+ parameters:
+ _class:
+ env:
+ override: 'env.dev'
+ lab:
+ name: default
+
+ #/etc/reclass/classes/lab/env/dev.yml
+ parameters:
+ lab:
+ name: dev
+
+ #/etc/reclass/classes/second.yml
+ classes:
+ - first
+ - lab.${_class:env:override}
+
+
+Reclass --nodeinfo then returns:
+
+.. code-block:: yaml
+
+ ...
+ ...
+ applications: []
+ environment: base
+ exports: {}
+ classes:
+ - first
+ - lab.${_class:env:override}
+ - second
+ parameters:
+ _class:
+ env:
+ override: env.dev
+ lab:
+ name: dev
+ ...
+ ...
+
Inventory Queries
-----------------
diff --git a/reclass/core.py b/reclass/core.py
index 9da0ddb..23851a5 100644
--- a/reclass/core.py
+++ b/reclass/core.py
@@ -19,6 +19,7 @@
from reclass.output.yaml_outputter import ExplicitDumper
from reclass.datatypes import Entity, Classes, Parameters, Exports
from reclass.errors import MappingFormatError, ClassNotFound, InvQueryClassNotFound, InvQueryError, InterpolationError
+from reclass.values.parser import Parser
class Core(object):
@@ -89,6 +90,10 @@
return Entity(self._settings, parameters=p, name='input data')
def _recurse_entity(self, entity, merge_base=None, seen=None, nodename=None, environment=None):
+
+ # values/parser in order to interpolate references in classes
+ _parser = Parser()
+
if seen is None:
seen = {}
@@ -99,6 +104,8 @@
merge_base = Entity(self._settings, name='empty (@{0})'.format(nodename))
for klass in entity.classes.as_list():
+ if merge_base is not None:
+ klass=str(_parser.parse(klass, self._settings).render(merge_base.parameters.as_dict(), {}))
if klass not in seen:
try:
class_entity = self._storage.get_class(klass, environment, self._settings)