Node classification/declassification - reactors and orchestration pipelines
Change-Id: Ic670e74767b2ee4a966b8f85859f6b427c32cbd2
diff --git a/README.rst b/README.rst
index 9090e65..73cdb83 100644
--- a/README.rst
+++ b/README.rst
@@ -51,6 +51,37 @@
.. literalinclude:: tests/pillar/node_classify.sls
:language: yaml
+Classify node after creation and unclassify on node deletion
+
+.. code-block:: yaml
+
+ salt:
+ master:
+ reactor:
+ reclass/minion/classify:
+ - salt://reclass/reactor/node_register.sls
+ reclass/minion/declassify:
+ - salt://reclass/reactor/node_unregister.sls
+
+Event to trigger the node classification
+
+.. code-block:: bash
+
+ salt-call event.send 'reclass/minion/classify' "{'node_master_ip': '$config_host', 'node_ip': '${node_ip}', 'node_domain': '$node_domain', 'node_cluster': '$node_cluster', 'node_hostname': '$node_hostname', 'node_os': '$node_os'}"
+
+.. note::
+
+ You can send any parameters in the event payload, all will be checked
+ against dynamic node classification conditions.
+
+ Both actions will use the minion ID as the node_name to be updated.
+
+Event to trigger the node declassification
+
+.. code-block:: bash
+
+ salt-call event.send 'reclass/minion/declassify'
+
More Information
================
diff --git a/reclass/orchestrate/reactor/node_register.sls b/reclass/orchestrate/reactor/node_register.sls
index ec00392..1bd211a 100644
--- a/reclass/orchestrate/reactor/node_register.sls
+++ b/reclass/orchestrate/reactor/node_register.sls
@@ -3,20 +3,19 @@
classify_node_{{ node_name }}:
salt.state:
- - tgt: 'salt:master'
- - tgt_type: pillar
- - sls: reclass.reactor_sls.node_register
- - queue: True
- - pillar:
- node_name: {{ node_name }}
- node_data: {{ node_data }}
+ - tgt: 'salt:master'
+ - tgt_type: pillar
+ - sls: reclass.reactor_sls.node_register
+ - queue: True
+ - pillar:
+ node_name: {{ node_name }}
+ node_data: {{ node_data }}
regenerate_all_nodes:
salt.state:
- - tgt: 'salt:master'
- - tgt_type: pillar
- - sls: reclass.storage.node
- - queue: True
- - requires:
- - salt: classify_node_{{ node_name }}
-
+ - tgt: 'salt:master'
+ - tgt_type: pillar
+ - sls: reclass.storage.node
+ - queue: True
+ - requires:
+ - salt: classify_node_{{ node_name }}
diff --git a/reclass/orchestrate/reactor/node_unregister.sls b/reclass/orchestrate/reactor/node_unregister.sls
new file mode 100644
index 0000000..ec6fd91
--- /dev/null
+++ b/reclass/orchestrate/reactor/node_unregister.sls
@@ -0,0 +1,10 @@
+{%- set node_name = salt['pillar.get']('event_originator') %}
+
+unregister_node_{{ node_name }}:
+ salt.state:
+ - tgt: 'salt:master'
+ - tgt_type: pillar
+ - sls: reclass.reactor_sls.node_unregister
+ - queue: True
+ - pillar:
+ node_name: {{ node_name }}
diff --git a/reclass/reactor/node_register.sls b/reclass/reactor/node_register.sls
index e2c972d..057b345 100644
--- a/reclass/reactor/node_register.sls
+++ b/reclass/reactor/node_register.sls
@@ -1,8 +1,8 @@
orchestrate_node_register:
runner.state.orchestrate:
- - mods: reclass.orchestrate.reactor.node_register
- - queue: True
- - pillar:
- event_originator: {{ data.id }}
- event_data: {{ data.data }}
+ - mods: reclass.orchestrate.reactor.node_register
+ - queue: True
+ - pillar:
+ event_originator: {{ data.id }}
+ event_data: {{ data.data }}
diff --git a/reclass/reactor/node_unregister.sls b/reclass/reactor/node_unregister.sls
new file mode 100644
index 0000000..29ee421
--- /dev/null
+++ b/reclass/reactor/node_unregister.sls
@@ -0,0 +1,7 @@
+
+orchestrate_node_unregister:
+ runner.state.orchestrate:
+ - mods: reclass.orchestrate.reactor.node_unregister
+ - queue: True
+ - pillar:
+ event_originator: {{ data.id }}
diff --git a/reclass/reactor_sls/node_register.sls b/reclass/reactor_sls/node_register.sls
index af2031f..de21be1 100644
--- a/reclass/reactor_sls/node_register.sls
+++ b/reclass/reactor_sls/node_register.sls
@@ -7,4 +7,3 @@
- name: {{ node_name }}
- node_data: {{ node_data }}
- class_mapping: {{ class_mapping }}
-
diff --git a/reclass/reactor_sls/node_unregister.sls b/reclass/reactor_sls/node_unregister.sls
new file mode 100644
index 0000000..d0f3dc8
--- /dev/null
+++ b/reclass/reactor_sls/node_unregister.sls
@@ -0,0 +1,5 @@
+{%- set node_name = salt['pillar.get']('node_name') %}
+
+unclassify_node_{{ node_name }}:
+ reclass.dynamic_node_absent:
+ - name: {{ node_name }}
diff --git a/tests/pillar/reactor_classify.sls b/tests/pillar/reactor_classify.sls
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/pillar/reactor_classify.sls