Merge pull request #2 from bbinet/optionnal-classes
Optionnal classes
diff --git a/reclass/adapters/salt.py b/reclass/adapters/salt.py
index 1b45823..f4f331b 100755
--- a/reclass/adapters/salt.py
+++ b/reclass/adapters/salt.py
@@ -24,7 +24,8 @@
nodes_uri=OPT_NODES_URI,
classes_uri=OPT_CLASSES_URI,
class_mappings=None,
- propagate_pillar_data_to_reclass=False):
+ propagate_pillar_data_to_reclass=False,
+ ignore_class_notfound=False):
nodes_uri, classes_uri = path_mangler(inventory_base_uri,
nodes_uri, classes_uri)
@@ -33,7 +34,8 @@
input_data = None
if propagate_pillar_data_to_reclass:
input_data = pillar
- reclass = Core(storage, class_mappings, input_data=input_data)
+ reclass = Core(storage, class_mappings, input_data=input_data,
+ ignore_class_notfound=ignore_class_notfound)
data = reclass.nodeinfo(minion_id)
params = data.get('parameters', {})
@@ -48,13 +50,14 @@
def top(minion_id, storage_type=OPT_STORAGE_TYPE,
inventory_base_uri=OPT_INVENTORY_BASE_URI, nodes_uri=OPT_NODES_URI,
classes_uri=OPT_CLASSES_URI,
- class_mappings=None):
+ class_mappings=None, ignore_class_notfound=False):
nodes_uri, classes_uri = path_mangler(inventory_base_uri,
nodes_uri, classes_uri)
storage = get_storage(storage_type, nodes_uri, classes_uri,
default_environment='base')
- reclass = Core(storage, class_mappings, input_data=None)
+ reclass = Core(storage, class_mappings, input_data=None,
+ ignore_class_notfound=ignore_class_notfound)
# if the minion_id is not None, then return just the applications for the
# specific minion, otherwise return the entire top data (which we need for
diff --git a/reclass/core.py b/reclass/core.py
index 76bd0a8..0c8543d 100644
--- a/reclass/core.py
+++ b/reclass/core.py
@@ -18,9 +18,11 @@
class Core(object):
- def __init__(self, storage, class_mappings, input_data=None):
+ def __init__(self, storage, class_mappings, input_data=None,
+ ignore_class_notfound=False):
self._storage = storage
self._class_mappings = class_mappings
+ self._ignore_class_notfound = ignore_class_notfound
self._input_data = input_data
@staticmethod
@@ -93,6 +95,8 @@
try:
class_entity = self._storage.get_class(klass)
except ClassNotFound, e:
+ if self._ignore_class_notfound:
+ continue
e.set_nodename(nodename)
raise e